3v4l.org

run code in 300+ PHP versions simultaneously
<?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();
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.3.32 - 7.3.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.33
Deprecated: assert(): Calling assert() with a string argument is deprecated in /in/q81Qg on line 162
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.3.11, 4.4.0 - 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.

preferences:
271.35 ms | 401 KiB | 326 Q