3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /** * @author @ct-jensschulze <jens.schulze@commercetools.de> */ class PHPUnit_Framework_MockObject_Invocation_Object extends PHPUnit_Framework_MockObject_Invocation_Static { /** * @var object */ public $object; /** * @param string $className * @param string $methodname * @param array $parameters * @param object $object * @param object $cloneObjects */ public function __construct($className, $methodName, array $parameters, $object, $cloneObjects = false) { parent::__construct($className, $methodName, $parameters, $cloneObjects); $this->object = $object; } } class PHPUnit_Framework_MockObject_Invocation_Static { /** * @var array */ protected static $uncloneableExtensions = array( 'mysqli' => true, 'SQLite' => true, 'sqlite3' => true, 'tidy' => true, 'xmlwriter' => true, 'xsl' => true ); /** * @var array */ protected static $uncloneableClasses = array( 'Closure', 'COMPersistHelper', 'IteratorIterator', 'RecursiveIteratorIterator', 'SplFileObject', 'PDORow', 'ZipArchive' ); /** * @var string */ public $className; /** * @var string */ public $methodName; /** * @var array */ public $parameters; /** * @param string $className * @param string $methodname * @param array $parameters * @param boolean $cloneObjects */ public function __construct($className, $methodName, array $parameters, $cloneObjects = false) { $this->className = $className; $this->methodName = $methodName; $this->parameters = $parameters; if (!$cloneObjects) { return; } foreach ($this->parameters as $key => $value) { if (is_object($value)) { $this->parameters[$key] = $this->cloneObject($value); } } } /** * @param object $original * @return object */ protected function cloneObject($original) { return clone $original; } } interface MyInterface { public function doSomethingDifferent(); } abstract class MyClass implements MyInterface { public function doSomething() { return "doneSomething"; } abstract public function doSomethingElse(); } class MyClassTest { public function getMockForAbstractClass($className) { $mockClassName = 'Mock_' . $className; $class = <<<EOF class $mockClassName extends $className { private \$__phpunit_invocationMocker; private \$__phpunit_originalObject; public function __clone() { \$this->__phpunit_invocationMocker = clone \$this->__phpunit_getInvocationMocker(); } public function doSomethingElse() {} public function doSomethingDifferent() { \$arguments = array(); \$count = func_num_args(); if (\$count > 0) { \$_arguments = func_get_args(); for (\$i = 0; \$i < \$count; \$i++) { \$arguments[] = \$_arguments[\$i]; } } \$result = \$this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'MyInterface', 'httpRequest', \$arguments, \$this, FALSE ) ); return \$result; } } EOF; eval($class); return new $mockClassName(); } public function testDoSomething() { $object = $this->getMockForAbstractClass('MyClass'); assert('"doneSomething" == "' . $object->doSomething() . '"'); } } $test = new MyClassTest(); $test->testDoSomething();
based on NZWDS
Output for 7.2.6 - 7.3.0rc3
Deprecated: assert(): Calling assert() with a string argument is deprecated in /in/q81Qg on line 162
Output for 5.1.0 - 7.1.20
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/q81Qg on line 20
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/q81Qg on line 11
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/q81Qg on line 11
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/q81Qg on line 11
Process exited with code 255.