Update v1.0.6.5
This commit is contained in:
@@ -57,26 +57,32 @@ class ClassCodeGeneratorSpec extends ObjectBehavior
|
||||
$argument11->isOptional()->willReturn(true);
|
||||
$argument11->getDefault()->willReturn(null);
|
||||
$argument11->isPassedByReference()->willReturn(false);
|
||||
$argument11->isVariadic()->willReturn(false);
|
||||
|
||||
$argument12->getName()->willReturn('class');
|
||||
$argument12->getTypeHint()->willReturn('ReflectionClass');
|
||||
$argument12->isOptional()->willReturn(false);
|
||||
$argument12->isPassedByReference()->willReturn(false);
|
||||
$argument12->isVariadic()->willReturn(false);
|
||||
|
||||
$argument21->getName()->willReturn('default');
|
||||
$argument21->getTypeHint()->willReturn(null);
|
||||
$argument21->getTypeHint()->willReturn('string');
|
||||
$argument21->isOptional()->willReturn(true);
|
||||
$argument21->getDefault()->willReturn('ever.zet@gmail.com');
|
||||
$argument21->isPassedByReference()->willReturn(false);
|
||||
$argument21->isVariadic()->willReturn(false);
|
||||
|
||||
$argument31->getName()->willReturn('refValue');
|
||||
$argument31->getTypeHint()->willReturn(null);
|
||||
$argument31->isOptional()->willReturn(false);
|
||||
$argument31->getDefault()->willReturn();
|
||||
$argument31->isPassedByReference()->willReturn(false);
|
||||
$argument31->isVariadic()->willReturn(false);
|
||||
|
||||
$code = $this->generate('CustomClass', $class);
|
||||
$expected = <<<'PHP'
|
||||
|
||||
if (version_compare(PHP_VERSION, '7.0', '>=')) {
|
||||
$expected = <<<'PHP'
|
||||
namespace {
|
||||
class CustomClass extends \RuntimeException implements \Prophecy\Doubler\Generator\MirroredInterface, \ArrayAccess, \ArrayIterator {
|
||||
public $name;
|
||||
@@ -85,13 +91,138 @@ private $email;
|
||||
public static function getName(array $fullname = NULL, \ReflectionClass $class): string {
|
||||
return $this->name;
|
||||
}
|
||||
protected function getEmail( $default = 'ever.zet@gmail.com') {
|
||||
protected function getEmail(string $default = 'ever.zet@gmail.com') {
|
||||
return $this->email;
|
||||
}
|
||||
public function &getRefValue( $refValue) {
|
||||
return $this->refValue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
} else {
|
||||
$expected = <<<'PHP'
|
||||
namespace {
|
||||
class CustomClass extends \RuntimeException implements \Prophecy\Doubler\Generator\MirroredInterface, \ArrayAccess, \ArrayIterator {
|
||||
public $name;
|
||||
private $email;
|
||||
|
||||
public static function getName(array $fullname = NULL, \ReflectionClass $class) {
|
||||
return $this->name;
|
||||
}
|
||||
protected function getEmail(\string $default = 'ever.zet@gmail.com') {
|
||||
return $this->email;
|
||||
}
|
||||
public function &getRefValue( $refValue) {
|
||||
return $this->refValue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
}
|
||||
$expected = strtr($expected, array("\r\n" => "\n", "\r" => "\n"));
|
||||
$code->shouldBe($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Doubler\Generator\Node\ClassNode $class
|
||||
* @param \Prophecy\Doubler\Generator\Node\MethodNode $method1
|
||||
* @param \Prophecy\Doubler\Generator\Node\MethodNode $method2
|
||||
* @param \Prophecy\Doubler\Generator\Node\MethodNode $method3
|
||||
* @param \Prophecy\Doubler\Generator\Node\MethodNode $method4
|
||||
* @param \Prophecy\Doubler\Generator\Node\ArgumentNode $argument1
|
||||
* @param \Prophecy\Doubler\Generator\Node\ArgumentNode $argument2
|
||||
* @param \Prophecy\Doubler\Generator\Node\ArgumentNode $argument3
|
||||
* @param \Prophecy\Doubler\Generator\Node\ArgumentNode $argument4
|
||||
*/
|
||||
function it_generates_proper_php_code_for_variadics(
|
||||
$class, $method1, $method2, $method3, $method4, $argument1, $argument2,
|
||||
$argument3, $argument4
|
||||
)
|
||||
{
|
||||
$class->getParentClass()->willReturn('stdClass');
|
||||
$class->getInterfaces()->willReturn(array('Prophecy\Doubler\Generator\MirroredInterface'));
|
||||
$class->getProperties()->willReturn(array());
|
||||
$class->getMethods()->willReturn(array(
|
||||
$method1, $method2, $method3, $method4
|
||||
));
|
||||
|
||||
$method1->getName()->willReturn('variadic');
|
||||
$method1->getVisibility()->willReturn('public');
|
||||
$method1->returnsReference()->willReturn(false);
|
||||
$method1->isStatic()->willReturn(false);
|
||||
$method1->getArguments()->willReturn(array($argument1));
|
||||
$method1->hasReturnType()->willReturn(false);
|
||||
$method1->getCode()->willReturn('');
|
||||
|
||||
$method2->getName()->willReturn('variadicByRef');
|
||||
$method2->getVisibility()->willReturn('public');
|
||||
$method2->returnsReference()->willReturn(false);
|
||||
$method2->isStatic()->willReturn(false);
|
||||
$method2->getArguments()->willReturn(array($argument2));
|
||||
$method2->hasReturnType()->willReturn(false);
|
||||
$method2->getCode()->willReturn('');
|
||||
|
||||
$method3->getName()->willReturn('variadicWithType');
|
||||
$method3->getVisibility()->willReturn('public');
|
||||
$method3->returnsReference()->willReturn(false);
|
||||
$method3->isStatic()->willReturn(false);
|
||||
$method3->getArguments()->willReturn(array($argument3));
|
||||
$method3->hasReturnType()->willReturn(false);
|
||||
$method3->getCode()->willReturn('');
|
||||
|
||||
$method4->getName()->willReturn('variadicWithTypeByRef');
|
||||
$method4->getVisibility()->willReturn('public');
|
||||
$method4->returnsReference()->willReturn(false);
|
||||
$method4->isStatic()->willReturn(false);
|
||||
$method4->getArguments()->willReturn(array($argument4));
|
||||
$method4->hasReturnType()->willReturn(false);
|
||||
$method4->getCode()->willReturn('');
|
||||
|
||||
$argument1->getName()->willReturn('args');
|
||||
$argument1->getTypeHint()->willReturn(null);
|
||||
$argument1->isOptional()->willReturn(false);
|
||||
$argument1->isPassedByReference()->willReturn(false);
|
||||
$argument1->isVariadic()->willReturn(true);
|
||||
|
||||
$argument2->getName()->willReturn('args');
|
||||
$argument2->getTypeHint()->willReturn(null);
|
||||
$argument2->isOptional()->willReturn(false);
|
||||
$argument2->isPassedByReference()->willReturn(true);
|
||||
$argument2->isVariadic()->willReturn(true);
|
||||
|
||||
$argument3->getName()->willReturn('args');
|
||||
$argument3->getTypeHint()->willReturn('\ReflectionClass');
|
||||
$argument3->isOptional()->willReturn(false);
|
||||
$argument3->isPassedByReference()->willReturn(false);
|
||||
$argument3->isVariadic()->willReturn(true);
|
||||
|
||||
$argument4->getName()->willReturn('args');
|
||||
$argument4->getTypeHint()->willReturn('\ReflectionClass');
|
||||
$argument4->isOptional()->willReturn(false);
|
||||
$argument4->isPassedByReference()->willReturn(true);
|
||||
$argument4->isVariadic()->willReturn(true);
|
||||
|
||||
$code = $this->generate('CustomClass', $class);
|
||||
$expected = <<<'PHP'
|
||||
namespace {
|
||||
class CustomClass extends \stdClass implements \Prophecy\Doubler\Generator\MirroredInterface {
|
||||
|
||||
public function variadic( ...$args) {
|
||||
|
||||
}
|
||||
public function variadicByRef( &...$args) {
|
||||
|
||||
}
|
||||
public function variadicWithType(\\ReflectionClass ...$args) {
|
||||
|
||||
}
|
||||
public function variadicWithTypeByRef(\\ReflectionClass &...$args) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
@@ -126,6 +257,7 @@ PHP;
|
||||
$argument->isOptional()->willReturn(true);
|
||||
$argument->getDefault()->willReturn(null);
|
||||
$argument->isPassedByReference()->willReturn(true);
|
||||
$argument->isVariadic()->willReturn(false);
|
||||
|
||||
$code = $this->generate('CustomClass', $class);
|
||||
$expected =<<<'PHP'
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
namespace spec\Prophecy\Doubler\Generator;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use I\Simply;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use ReflectionParameter;
|
||||
@@ -13,15 +12,17 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
{
|
||||
/**
|
||||
* @param ReflectionClass $class
|
||||
* @param ReflectionClass $parent
|
||||
* @param ReflectionMethod $method1
|
||||
* @param ReflectionMethod $method2
|
||||
* @param ReflectionMethod $method3
|
||||
*/
|
||||
function it_reflects_a_class_by_mirroring_all_its_public_methods(
|
||||
$class, $method1, $method2, $method3
|
||||
$class, $parent, $method1, $method2, $method3
|
||||
)
|
||||
{
|
||||
$class->getName()->willReturn('Custom\ClassName');
|
||||
$class->getParentClass()->willReturn($parent);
|
||||
$class->isInterface()->willReturn(false);
|
||||
$class->isFinal()->willReturn(false);
|
||||
$class->getMethods(ReflectionMethod::IS_ABSTRACT)->willReturn(array());
|
||||
@@ -29,9 +30,15 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$method1, $method2, $method3
|
||||
));
|
||||
|
||||
$parent->getName()->willReturn('Custom\ParentClassName');
|
||||
|
||||
$method1->getDeclaringClass()->willReturn($class);
|
||||
$method2->getDeclaringClass()->willReturn($class);
|
||||
$method3->getDeclaringClass()->willReturn($class);
|
||||
|
||||
$method1->getName()->willReturn('getName');
|
||||
$method2->getName()->willReturn('isPublic');
|
||||
$method3->getName()->willReturn('isAbstract');
|
||||
$method2->getName()->willReturn('getSelf');
|
||||
$method3->getName()->willReturn('getParent');
|
||||
|
||||
$method1->isFinal()->willReturn(false);
|
||||
$method2->isFinal()->willReturn(false);
|
||||
@@ -54,9 +61,12 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$method3->getParameters()->willReturn(array());
|
||||
|
||||
if (version_compare(PHP_VERSION, '7.0', '>=')) {
|
||||
$method1->hasReturnType()->willReturn(false);
|
||||
$method2->hasReturnType()->willReturn(false);
|
||||
$method3->hasReturnType()->willReturn(false);
|
||||
$method1->hasReturnType()->willReturn(true);
|
||||
$method1->getReturnType()->willReturn('string');
|
||||
$method2->hasReturnType()->willReturn(true);
|
||||
$method2->getReturnType()->willReturn('self');
|
||||
$method3->hasReturnType()->willReturn(true);
|
||||
$method3->getReturnType()->willReturn('parent');
|
||||
}
|
||||
|
||||
$classNode = $this->reflect($class, array());
|
||||
@@ -67,8 +77,14 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$methodNodes->shouldHaveCount(3);
|
||||
|
||||
$classNode->hasMethod('getName')->shouldReturn(true);
|
||||
$classNode->hasMethod('isPublic')->shouldReturn(true);
|
||||
$classNode->hasMethod('isAbstract')->shouldReturn(true);
|
||||
$classNode->hasMethod('getSelf')->shouldReturn(true);
|
||||
$classNode->hasMethod('getParent')->shouldReturn(true);
|
||||
|
||||
if (version_compare(PHP_VERSION, '7.0', '>=')) {
|
||||
$classNode->getMethod('getName')->getReturnType()->shouldReturn('string');
|
||||
$classNode->getMethod('getSelf')->getReturnType()->shouldReturn('\Custom\ClassName');
|
||||
$classNode->getMethod('getParent')->getReturnType()->shouldReturn('\Custom\ParentClassName');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,6 +117,9 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$parameter->getDefaultValue()->willReturn(null);
|
||||
$parameter->isPassedByReference()->willReturn(false);
|
||||
$parameter->getClass()->willReturn($class);
|
||||
if (version_compare(PHP_VERSION, '5.6', '>=')) {
|
||||
$parameter->isVariadic()->willReturn(false);
|
||||
}
|
||||
|
||||
$classNode = $this->reflect($class, array());
|
||||
|
||||
@@ -177,6 +196,92 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$methodNodes['innerDetail']->isStatic()->shouldReturn(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $class
|
||||
* @param ReflectionMethod $constructMethod
|
||||
* @param ReflectionMethod $destructMethod
|
||||
* @param ReflectionMethod $sleepMethod
|
||||
* @param ReflectionMethod $wakeupMethod
|
||||
* @param ReflectionMethod $toStringMethod
|
||||
* @param ReflectionMethod $callMethod
|
||||
* @param ReflectionMethod $invokeMethod
|
||||
*/
|
||||
function it_reflects_allowed_magic_methods($class, $constructMethod, $destructMethod, $sleepMethod, $wakeupMethod, $toStringMethod, $callMethod, $invokeMethod)
|
||||
{
|
||||
$class->getName()->willReturn('Custom\ClassName');
|
||||
$class->isInterface()->willReturn(false);
|
||||
$class->isFinal()->willReturn(false);
|
||||
$class->getMethods(ReflectionMethod::IS_ABSTRACT)->willReturn(array());
|
||||
$class->getMethods(ReflectionMethod::IS_PUBLIC)->willReturn(array(
|
||||
$constructMethod, $destructMethod, $sleepMethod, $wakeupMethod, $toStringMethod, $callMethod, $invokeMethod
|
||||
));
|
||||
|
||||
$constructMethod->getName()->willReturn('__construct');
|
||||
$destructMethod->getName()->willReturn('__destruct');
|
||||
$sleepMethod->getName()->willReturn('__sleep');
|
||||
$wakeupMethod->getName()->willReturn('__wakeup');
|
||||
$toStringMethod->getName()->willReturn('__toString');
|
||||
$callMethod->getName()->willReturn('__call');
|
||||
$invokeMethod->getName()->willReturn('__invoke');
|
||||
|
||||
$constructMethod->isFinal()->willReturn(false);
|
||||
$destructMethod->isFinal()->willReturn(false);
|
||||
$sleepMethod->isFinal()->willReturn(false);
|
||||
$wakeupMethod->isFinal()->willReturn(false);
|
||||
$toStringMethod->isFinal()->willReturn(false);
|
||||
$callMethod->isFinal()->willReturn(false);
|
||||
$invokeMethod->isFinal()->willReturn(false);
|
||||
|
||||
$constructMethod->isProtected()->willReturn(false);
|
||||
$destructMethod->isProtected()->willReturn(false);
|
||||
$sleepMethod->isProtected()->willReturn(false);
|
||||
$wakeupMethod->isProtected()->willReturn(false);
|
||||
$toStringMethod->isProtected()->willReturn(false);
|
||||
$callMethod->isProtected()->willReturn(false);
|
||||
$invokeMethod->isProtected()->willReturn(false);
|
||||
|
||||
$constructMethod->isStatic()->willReturn(false);
|
||||
$destructMethod->isStatic()->willReturn(false);
|
||||
$sleepMethod->isStatic()->willReturn(false);
|
||||
$wakeupMethod->isStatic()->willReturn(false);
|
||||
$toStringMethod->isStatic()->willReturn(false);
|
||||
$callMethod->isStatic()->willReturn(false);
|
||||
$invokeMethod->isStatic()->willReturn(false);
|
||||
|
||||
$constructMethod->returnsReference()->willReturn(false);
|
||||
$destructMethod->returnsReference()->willReturn(false);
|
||||
$sleepMethod->returnsReference()->willReturn(false);
|
||||
$wakeupMethod->returnsReference()->willReturn(false);
|
||||
$toStringMethod->returnsReference()->willReturn(false);
|
||||
$callMethod->returnsReference()->willReturn(false);
|
||||
$invokeMethod->returnsReference()->willReturn(false);
|
||||
|
||||
$constructMethod->getParameters()->willReturn(array());
|
||||
$destructMethod->getParameters()->willReturn(array());
|
||||
$sleepMethod->getParameters()->willReturn(array());
|
||||
$wakeupMethod->getParameters()->willReturn(array());
|
||||
$toStringMethod->getParameters()->willReturn(array());
|
||||
$callMethod->getParameters()->willReturn(array());
|
||||
$invokeMethod->getParameters()->willReturn(array());
|
||||
|
||||
if (version_compare(PHP_VERSION, '7.0', '>=')) {
|
||||
$constructMethod->hasReturnType()->willReturn(false);
|
||||
$destructMethod->hasReturnType()->willReturn(false);
|
||||
$sleepMethod->hasReturnType()->willReturn(false);
|
||||
$wakeupMethod->hasReturnType()->willReturn(false);
|
||||
$toStringMethod->hasReturnType()->willReturn(false);
|
||||
$callMethod->hasReturnType()->willReturn(false);
|
||||
$invokeMethod->hasReturnType()->willReturn(false);
|
||||
}
|
||||
|
||||
$classNode = $this->reflect($class, array());
|
||||
$classNode->shouldBeAnInstanceOf('Prophecy\Doubler\Generator\Node\ClassNode');
|
||||
$classNode->getParentClass()->shouldReturn('Custom\ClassName');
|
||||
|
||||
$methodNodes = $classNode->getMethods();
|
||||
$methodNodes->shouldHaveCount(7);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $class
|
||||
* @param ReflectionMethod $method
|
||||
@@ -184,9 +289,10 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
* @param ReflectionParameter $param2
|
||||
* @param ReflectionClass $typeHint
|
||||
* @param ReflectionParameter $param3
|
||||
* @param ReflectionParameter $param4
|
||||
*/
|
||||
function it_properly_reads_methods_arguments_with_types(
|
||||
$class, $method, $param1, $param2, $typeHint, $param3
|
||||
$class, $method, $param1, $param2, $typeHint, $param3, $param4
|
||||
)
|
||||
{
|
||||
$class->getName()->willReturn('Custom\ClassName');
|
||||
@@ -200,7 +306,7 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$method->isProtected()->willReturn(true);
|
||||
$method->isStatic()->willReturn(false);
|
||||
$method->returnsReference()->willReturn(false);
|
||||
$method->getParameters()->willReturn(array($param1, $param2, $param3));
|
||||
$method->getParameters()->willReturn(array($param1, $param2, $param3, $param4));
|
||||
|
||||
if (version_compare(PHP_VERSION, '7.0', '>=')) {
|
||||
$method->hasReturnType()->willReturn(false);
|
||||
@@ -234,6 +340,22 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$param3->isPassedByReference()->willReturn(false);
|
||||
$param3->allowsNull()->willReturn(true);
|
||||
|
||||
$param4->getName()->willReturn('arg_4');
|
||||
$param4->isArray()->willReturn(false);
|
||||
$param4->getClass()->willReturn($typeHint);
|
||||
$param4->isPassedByReference()->willReturn(false);
|
||||
$param4->allowsNull()->willReturn(true);
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.6', '>=')) {
|
||||
$param1->isVariadic()->willReturn(false);
|
||||
$param2->isVariadic()->willReturn(false);
|
||||
$param3->isVariadic()->willReturn(false);
|
||||
$param4->isVariadic()->willReturn(true);
|
||||
} else {
|
||||
$param4->isOptional()->willReturn(true);
|
||||
$param4->isDefaultValueAvailable()->willReturn(false);
|
||||
}
|
||||
|
||||
$classNode = $this->reflect($class, array());
|
||||
$methodNodes = $classNode->getMethods();
|
||||
$argNodes = $methodNodes['methodWithArgs']->getArguments();
|
||||
@@ -255,6 +377,15 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
} else {
|
||||
$argNodes[2]->isOptional()->shouldReturn(false);
|
||||
}
|
||||
|
||||
$argNodes[3]->getName()->shouldReturn('arg_4');
|
||||
$argNodes[3]->getTypeHint()->shouldReturn('ArrayAccess');
|
||||
if (version_compare(PHP_VERSION, '5.6', '>=')) {
|
||||
$argNodes[3]->isVariadic()->shouldReturn(true);
|
||||
} else {
|
||||
$argNodes[3]->isOptional()->shouldReturn(true);
|
||||
$argNodes[3]->getDefault()->shouldReturn(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -294,6 +425,9 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$param1->hasType()->willReturn(false);
|
||||
}
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.6', '>=')) {
|
||||
$param1->isVariadic()->willReturn(false);
|
||||
}
|
||||
$param1->isDefaultValueAvailable()->willReturn(false);
|
||||
$param1->isOptional()->willReturn(false);
|
||||
$param1->isPassedByReference()->willReturn(false);
|
||||
@@ -314,10 +448,11 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
* @param ReflectionMethod $method
|
||||
* @param ReflectionParameter $param1
|
||||
* @param ReflectionParameter $param2
|
||||
* @param ReflectionParameter $param3
|
||||
* @param ReflectionClass $typeHint
|
||||
*/
|
||||
function it_marks_passed_by_reference_args_as_passed_by_reference(
|
||||
$class, $method, $param1, $param2, $typeHint
|
||||
$class, $method, $param1, $param2, $param3, $typeHint
|
||||
)
|
||||
{
|
||||
$class->getName()->willReturn('Custom\ClassName');
|
||||
@@ -331,7 +466,7 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$method->isProtected()->willReturn(false);
|
||||
$method->isStatic()->willReturn(false);
|
||||
$method->returnsReference()->willReturn(false);
|
||||
$method->getParameters()->willReturn(array($param1, $param2));
|
||||
$method->getParameters()->willReturn(array($param1, $param2, $param3));
|
||||
|
||||
if (version_compare(PHP_VERSION, '7.0', '>=')) {
|
||||
$method->hasReturnType()->willReturn(false);
|
||||
@@ -343,6 +478,9 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$param1->isCallable()->willReturn(false);
|
||||
}
|
||||
$param1->getClass()->willReturn(null);
|
||||
if (version_compare(PHP_VERSION, '5.6', '>=')) {
|
||||
$param1->isVariadic()->willReturn(false);
|
||||
}
|
||||
$param1->isDefaultValueAvailable()->willReturn(false);
|
||||
$param1->isOptional()->willReturn(true);
|
||||
$param1->isPassedByReference()->willReturn(true);
|
||||
@@ -359,6 +497,9 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$param2->getName()->willReturn('arg2');
|
||||
$param2->isArray()->willReturn(false);
|
||||
$param2->getClass()->willReturn($typeHint);
|
||||
if (version_compare(PHP_VERSION, '5.6', '>=')) {
|
||||
$param2->isVariadic()->willReturn(false);
|
||||
}
|
||||
$param2->isDefaultValueAvailable()->willReturn(false);
|
||||
$param2->isOptional()->willReturn(false);
|
||||
$param2->isPassedByReference()->willReturn(false);
|
||||
@@ -370,12 +511,25 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$param2->allowsNull()->willReturn(false);
|
||||
$typeHint->getName()->willReturn('ArrayAccess');
|
||||
|
||||
$param3->getName()->willReturn('arg2');
|
||||
$param3->isArray()->willReturn(false);
|
||||
$param3->getClass()->willReturn($typeHint);
|
||||
if (version_compare(PHP_VERSION, '5.6', '>=')) {
|
||||
$param3->isVariadic()->willReturn(true);
|
||||
} else {
|
||||
$param3->isOptional()->willReturn(true);
|
||||
$param3->isDefaultValueAvailable()->willReturn(false);
|
||||
}
|
||||
$param3->isPassedByReference()->willReturn(true);
|
||||
$param3->allowsNull()->willReturn(true);
|
||||
|
||||
$classNode = $this->reflect($class, array());
|
||||
$methodNodes = $classNode->getMethods();
|
||||
$argNodes = $methodNodes['methodWithArgs']->getArguments();
|
||||
|
||||
$argNodes[0]->isPassedByReference()->shouldReturn(true);
|
||||
$argNodes[1]->isPassedByReference()->shouldReturn(false);
|
||||
$argNodes[2]->isPassedByReference()->shouldReturn(true);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -410,6 +564,26 @@ class ClassMirrorSpec extends ObjectBehavior
|
||||
$classNode->getMethods()->shouldHaveCount(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $class
|
||||
* @param ReflectionMethod $method
|
||||
*/
|
||||
function it_marks_final_methods_as_unextendable($class, $method)
|
||||
{
|
||||
$class->getName()->willReturn('Custom\ClassName');
|
||||
$class->isInterface()->willReturn(false);
|
||||
$class->isFinal()->willReturn(false);
|
||||
$class->getMethods(ReflectionMethod::IS_ABSTRACT)->willReturn(array());
|
||||
$class->getMethods(ReflectionMethod::IS_PUBLIC)->willReturn(array($method));
|
||||
|
||||
$method->isFinal()->willReturn(true);
|
||||
$method->getName()->willReturn('finalImplementation');
|
||||
|
||||
$classNode = $this->reflect($class, array());
|
||||
$classNode->getUnextendableMethods()->shouldHaveCount(1);
|
||||
$classNode->isExtendable('finalImplementation')->shouldReturn(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ReflectionClass $interface
|
||||
*/
|
||||
|
||||
@@ -22,6 +22,36 @@ class ArgumentNodeSpec extends ObjectBehavior
|
||||
$this->shouldBePassedByReference();
|
||||
}
|
||||
|
||||
function it_is_not_variadic_by_default()
|
||||
{
|
||||
$this->shouldNotBeVariadic();
|
||||
}
|
||||
|
||||
function it_is_variadic_if_marked()
|
||||
{
|
||||
$this->setAsVariadic();
|
||||
$this->shouldBeVariadic();
|
||||
}
|
||||
|
||||
function it_does_not_have_default_by_default()
|
||||
{
|
||||
$this->shouldNotHaveDefault();
|
||||
}
|
||||
|
||||
function it_does_not_have_default_if_variadic()
|
||||
{
|
||||
$this->setDefault(null);
|
||||
$this->setAsVariadic();
|
||||
$this->shouldNotHaveDefault();
|
||||
}
|
||||
|
||||
function it_does_have_default_if_not_variadic()
|
||||
{
|
||||
$this->setDefault(null);
|
||||
$this->setAsVariadic(false);
|
||||
$this->hasDefault()->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_has_name_with_which_it_was_been_constructed()
|
||||
{
|
||||
$this->getName()->shouldReturn('name');
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace spec\Prophecy\Doubler\Generator\Node;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Exception\Doubler\MethodNotExtendableException;
|
||||
|
||||
class ClassNodeSpec extends ObjectBehavior
|
||||
{
|
||||
@@ -151,4 +152,49 @@ class ClassNodeSpec extends ObjectBehavior
|
||||
$this->addProperty('text', 'PRIVATE');
|
||||
$this->getProperties()->shouldReturn(array('text' => 'private'));
|
||||
}
|
||||
|
||||
function its_has_no_unextendable_methods_by_default()
|
||||
{
|
||||
$this->getUnextendableMethods()->shouldHaveCount(0);
|
||||
}
|
||||
|
||||
function its_addUnextendableMethods_adds_an_unextendable_method()
|
||||
{
|
||||
$this->addUnextendableMethod('testMethod');
|
||||
$this->getUnextendableMethods()->shouldHaveCount(1);
|
||||
}
|
||||
|
||||
function its_methods_are_extendable_by_default()
|
||||
{
|
||||
$this->isExtendable('testMethod')->shouldReturn(true);
|
||||
}
|
||||
|
||||
function its_unextendable_methods_are_not_extendable()
|
||||
{
|
||||
$this->addUnextendableMethod('testMethod');
|
||||
$this->isExtendable('testMethod')->shouldReturn(false);
|
||||
}
|
||||
|
||||
function its_addUnextendableMethods_doesnt_create_duplicates()
|
||||
{
|
||||
$this->addUnextendableMethod('testMethod');
|
||||
$this->addUnextendableMethod('testMethod');
|
||||
$this->getUnextendableMethods()->shouldHaveCount(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Prophecy\Doubler\Generator\Node\MethodNode $method
|
||||
*/
|
||||
function it_throws_an_exception_when_adding_a_method_that_isnt_extendable($method)
|
||||
{
|
||||
$this->addUnextendableMethod('testMethod');
|
||||
$method->getName()->willReturn('testMethod');
|
||||
|
||||
$expectedException = new MethodNotExtendableException(
|
||||
"Method `testMethod` is not extendable, so can not be added.",
|
||||
"stdClass",
|
||||
"testMethod"
|
||||
);
|
||||
$this->shouldThrow($expectedException)->duringAddMethod($method);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,13 +69,16 @@ class MethodNodeSpec extends ObjectBehavior
|
||||
$argument1->getName()->willReturn('objectName');
|
||||
$argument2->getName()->willReturn('default');
|
||||
|
||||
$argument1->isVariadic()->willReturn(false);
|
||||
$argument2->isVariadic()->willReturn(true);
|
||||
|
||||
$this->addArgument($argument1);
|
||||
$this->addArgument($argument2);
|
||||
|
||||
$this->useParentCode();
|
||||
|
||||
$this->getCode()->shouldReturn(
|
||||
'return parent::getTitle($objectName, $default);'
|
||||
'return parent::getTitle($objectName, ...$default);'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user