Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Use https://github.com/Ocramius/Instantiator to instantiate objects w…
Browse files Browse the repository at this point in the history
…ithout invoking their class' constructor
  • Loading branch information
sebastianbergmann committed Jun 22, 2014
1 parent 0166705 commit 84b2756
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -22,7 +22,8 @@
"minimum-stability": "dev",
"require": {
"php": ">=5.3.3",
"phpunit/php-text-template": "~1.2"
"phpunit/php-text-template": "~1.2",
"ocramius/instantiator": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "4.2.*@dev"
Expand Down
21 changes: 4 additions & 17 deletions src/Framework/MockObject/Generator.php
Expand Up @@ -42,6 +42,8 @@
* @since File available since Release 1.0.0
*/

use Instantiator\Instantiator;

if (!function_exists('trait_exists')) {
function trait_exists($traitname, $autoload = true)
{
Expand Down Expand Up @@ -268,23 +270,8 @@ protected function getObject($code, $className, $type = '', $callOriginalConstru
$object = $class->newInstanceArgs($arguments);
}
} else {
$class = new ReflectionClass('ReflectionClass');
$hasNewInstanceWithoutConstructor = $class->hasMethod('newInstanceWithoutConstructor');;

$class = new ReflectionClass($className);
$isInternal = $this->isInternalClass($class);

if ($isInternal || !$hasNewInstanceWithoutConstructor) {
$object = unserialize(
sprintf('%s:%d:"%s":0:{}',
(version_compare(PHP_VERSION, '5.4', '>') && $class->implementsInterface("Serializable") ? "C" : "O"),
strlen($className),
$className
)
);
} else {
$object = $class->newInstanceWithoutConstructor();
}
$instantiator = new Instantiator;
$object = $instantiator->instantiate($className);
}

if ($callOriginalMethods) {
Expand Down

0 comments on commit 84b2756

Please sign in to comment.