Pressroom template verwijderd, website naar root van repo
This commit is contained in:
54
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/DisableConstructorPatchSpec.php
vendored
Normal file
54
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/DisableConstructorPatchSpec.php
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\ClassPatch;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Doubler\Generator\Node\ArgumentNode;
|
||||
use Prophecy\Doubler\Generator\Node\ClassNode;
|
||||
use Prophecy\Doubler\Generator\Node\MethodNode;
|
||||
|
||||
class DisableConstructorPatchSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_a_patch()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
|
||||
}
|
||||
|
||||
function its_priority_is_100()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(100);
|
||||
}
|
||||
|
||||
function it_supports_anything(ClassNode $node)
|
||||
{
|
||||
$this->supports($node)->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_makes_all_constructor_arguments_optional(
|
||||
ClassNode $class,
|
||||
MethodNode $method,
|
||||
ArgumentNode $arg1,
|
||||
ArgumentNode $arg2
|
||||
) {
|
||||
$class->hasMethod('__construct')->willReturn(true);
|
||||
$class->getMethod('__construct')->willReturn($method);
|
||||
$method->getArguments()->willReturn(array($arg1, $arg2));
|
||||
|
||||
$arg1->setDefault(null)->shouldBeCalled();
|
||||
$arg2->setDefault(null)->shouldBeCalled();
|
||||
|
||||
$method->setCode(Argument::type('string'))->shouldBeCalled();
|
||||
|
||||
$this->apply($class);
|
||||
}
|
||||
|
||||
function it_creates_new_constructor_if_object_has_none(ClassNode $class)
|
||||
{
|
||||
$class->hasMethod('__construct')->willReturn(false);
|
||||
$class->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))
|
||||
->shouldBeCalled();
|
||||
|
||||
$this->apply($class);
|
||||
}
|
||||
}
|
||||
34
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/HhvmExceptionPatchSpec.php
vendored
Normal file
34
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/HhvmExceptionPatchSpec.php
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\ClassPatch;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Doubler\Generator\Node\ClassNode;
|
||||
use Prophecy\Doubler\Generator\Node\MethodNode;
|
||||
|
||||
class HhvmExceptionPatchSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_a_patch()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
|
||||
}
|
||||
|
||||
function its_priority_is_minus_50()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(-50);
|
||||
}
|
||||
|
||||
function it_uses_parent_code_for_setTraceOptions(ClassNode $node, MethodNode $method, MethodNode $getterMethod)
|
||||
{
|
||||
$node->hasMethod('setTraceOptions')->willReturn(true);
|
||||
$node->getMethod('setTraceOptions')->willReturn($method);
|
||||
$node->hasMethod('getTraceOptions')->willReturn(true);
|
||||
$node->getMethod('getTraceOptions')->willReturn($getterMethod);
|
||||
|
||||
$method->useParentCode()->shouldBeCalled();
|
||||
$getterMethod->useParentCode()->shouldBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
}
|
||||
43
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/KeywordPatchSpec.php
vendored
Normal file
43
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/KeywordPatchSpec.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\ClassPatch;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Doubler\Generator\Node\ClassNode;
|
||||
use Prophecy\Doubler\Generator\Node\MethodNode;
|
||||
|
||||
class KeywordPatchSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_a_patch()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
|
||||
}
|
||||
|
||||
function its_priority_is_49()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(49);
|
||||
}
|
||||
|
||||
function it_will_remove_echo_and_eval_methods(
|
||||
ClassNode $node,
|
||||
MethodNode $method1,
|
||||
MethodNode $method2,
|
||||
MethodNode $method3
|
||||
) {
|
||||
$node->removeMethod('eval')->shouldBeCalled();
|
||||
$node->removeMethod('echo')->shouldBeCalled();
|
||||
|
||||
$method1->getName()->willReturn('echo');
|
||||
$method2->getName()->willReturn('eval');
|
||||
$method3->getName()->willReturn('notKeyword');
|
||||
|
||||
$node->getMethods()->willReturn(array(
|
||||
'echo' => $method1,
|
||||
'eval' => $method2,
|
||||
'notKeyword' => $method3,
|
||||
));
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
}
|
||||
140
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/MagicCallPatchSpec.php
vendored
Normal file
140
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/MagicCallPatchSpec.php
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\ClassPatch;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Doubler\Generator\Node\ClassNode;
|
||||
use Prophecy\Doubler\Generator\Node\MethodNode;
|
||||
|
||||
class MagicCallPatchSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_a_patch()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
|
||||
}
|
||||
|
||||
function it_supports_anything(ClassNode $node)
|
||||
{
|
||||
$this->supports($node)->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_discovers_api_using_phpdoc(ClassNode $node)
|
||||
{
|
||||
$node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApi');
|
||||
$node->getInterfaces()->willReturn(array());
|
||||
|
||||
$node->addMethod(new MethodNode('undefinedMethod'))->shouldBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
|
||||
function it_ignores_existing_methods(ClassNode $node)
|
||||
{
|
||||
$node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiExtended');
|
||||
$node->getInterfaces()->willReturn(array());
|
||||
|
||||
$node->addMethod(new MethodNode('undefinedMethod'))->shouldBeCalled();
|
||||
$node->addMethod(new MethodNode('definedMethod'))->shouldNotBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
|
||||
function it_ignores_empty_methods_from_phpdoc(ClassNode $node)
|
||||
{
|
||||
$node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiInvalidMethodDefinition');
|
||||
$node->getInterfaces()->willReturn(array());
|
||||
|
||||
$node->addMethod(new MethodNode(''))->shouldNotBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
|
||||
function it_discovers_api_using_phpdoc_from_implemented_interfaces(ClassNode $node)
|
||||
{
|
||||
$node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiImplemented');
|
||||
$node->getInterfaces()->willReturn(array());
|
||||
|
||||
$node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
|
||||
function it_discovers_api_using_phpdoc_from_own_interfaces(ClassNode $node)
|
||||
{
|
||||
$node->getParentClass()->willReturn('stdClass');
|
||||
$node->getInterfaces()->willReturn(array('spec\Prophecy\Doubler\ClassPatch\MagicalApiImplemented'));
|
||||
|
||||
$node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
|
||||
function it_discovers_api_using_phpdoc_from_extended_parent_interfaces(ClassNode $node)
|
||||
{
|
||||
$node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiImplementedExtended');
|
||||
$node->getInterfaces()->willReturn(array());
|
||||
|
||||
$node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
|
||||
function it_has_50_priority()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(50);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @method void undefinedMethod()
|
||||
*/
|
||||
class MagicalApi
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function definedMethod()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @method void invalidMethodDefinition
|
||||
* @method void
|
||||
* @method
|
||||
*/
|
||||
class MagicalApiInvalidMethodDefinition
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @method void undefinedMethod()
|
||||
* @method void definedMethod()
|
||||
*/
|
||||
class MagicalApiExtended extends MagicalApi
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class MagicalApiImplemented implements MagicalApiInterface
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
class MagicalApiImplementedExtended extends MagicalApiImplemented
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @method void implementedMethod()
|
||||
*/
|
||||
interface MagicalApiInterface
|
||||
{
|
||||
|
||||
}
|
||||
79
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/ProphecySubjectPatchSpec.php
vendored
Normal file
79
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/ProphecySubjectPatchSpec.php
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\ClassPatch;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Doubler\Generator\Node\ClassNode;
|
||||
use Prophecy\Doubler\Generator\Node\MethodNode;
|
||||
|
||||
class ProphecySubjectPatchSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_a_patch()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
|
||||
}
|
||||
|
||||
function it_has_priority_of_0()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(0);
|
||||
}
|
||||
|
||||
function it_supports_any_class(ClassNode $node)
|
||||
{
|
||||
$this->supports($node)->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_forces_class_to_implement_ProphecySubjectInterface(ClassNode $node)
|
||||
{
|
||||
$node->addInterface('Prophecy\Prophecy\ProphecySubjectInterface')->shouldBeCalled();
|
||||
|
||||
$node->addProperty('objectProphecy', 'private')->willReturn(null);
|
||||
$node->getMethods()->willReturn(array());
|
||||
$node->hasMethod(Argument::any())->willReturn(false);
|
||||
$node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
|
||||
$node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
|
||||
function it_forces_all_class_methods_except_constructor_to_proxy_calls_into_prophecy_makeCall(
|
||||
ClassNode $node,
|
||||
MethodNode $constructor,
|
||||
MethodNode $method1,
|
||||
MethodNode $method2,
|
||||
MethodNode $method3
|
||||
) {
|
||||
$node->addInterface('Prophecy\Prophecy\ProphecySubjectInterface')->willReturn(null);
|
||||
$node->addProperty('objectProphecy', 'private')->willReturn(null);
|
||||
$node->hasMethod(Argument::any())->willReturn(false);
|
||||
$node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
|
||||
$node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
|
||||
|
||||
$constructor->getName()->willReturn('__construct');
|
||||
$method1->getName()->willReturn('method1');
|
||||
$method2->getName()->willReturn('method2');
|
||||
$method3->getName()->willReturn('method3');
|
||||
|
||||
$method1->getReturnType()->willReturn('int');
|
||||
$method2->getReturnType()->willReturn('int');
|
||||
$method3->getReturnType()->willReturn('void');
|
||||
|
||||
$node->getMethods()->willReturn(array(
|
||||
'method1' => $method1,
|
||||
'method2' => $method2,
|
||||
'method3' => $method3,
|
||||
));
|
||||
|
||||
$constructor->setCode(Argument::any())->shouldNotBeCalled();
|
||||
|
||||
$method1->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
|
||||
->shouldBeCalled();
|
||||
$method2->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
|
||||
->shouldBeCalled();
|
||||
$method3->setCode('$this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
|
||||
->shouldBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
}
|
||||
43
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/ReflectionClassNewInstancePatchSpec.php
vendored
Normal file
43
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/ReflectionClassNewInstancePatchSpec.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\ClassPatch;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Doubler\Generator\Node\ArgumentNode;
|
||||
use Prophecy\Doubler\Generator\Node\ClassNode;
|
||||
use Prophecy\Doubler\Generator\Node\MethodNode;
|
||||
|
||||
class ReflectionClassNewInstancePatchSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_a_patch()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
|
||||
}
|
||||
|
||||
function its_priority_is_50()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(50);
|
||||
}
|
||||
|
||||
function it_supports_ReflectionClass_only(ClassNode $reflectionClassNode, ClassNode $anotherClassNode)
|
||||
{
|
||||
$reflectionClassNode->getParentClass()->willReturn('ReflectionClass');
|
||||
$anotherClassNode->getParentClass()->willReturn('stdClass');
|
||||
|
||||
$this->supports($reflectionClassNode)->shouldReturn(true);
|
||||
$this->supports($anotherClassNode)->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_makes_all_newInstance_arguments_optional(
|
||||
ClassNode $class,
|
||||
MethodNode $method,
|
||||
ArgumentNode $arg1
|
||||
) {
|
||||
$class->getMethod('newInstance')->willReturn($method);
|
||||
$method->getArguments()->willReturn(array($arg1));
|
||||
$arg1->setDefault(null)->shouldBeCalled();
|
||||
|
||||
$this->apply($class);
|
||||
}
|
||||
}
|
||||
85
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/SplFileInfoPatchSpec.php
vendored
Normal file
85
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/SplFileInfoPatchSpec.php
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\ClassPatch;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Doubler\Generator\Node\ClassNode;
|
||||
use Prophecy\Doubler\Generator\Node\MethodNode;
|
||||
|
||||
class SplFileInfoPatchSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_a_patch()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
|
||||
}
|
||||
|
||||
function its_priority_is_50()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(50);
|
||||
}
|
||||
|
||||
function it_does_not_support_nodes_without_parent_class(ClassNode $node)
|
||||
{
|
||||
$node->getParentClass()->willReturn('stdClass');
|
||||
$this->supports($node)->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_supports_nodes_with_SplFileInfo_as_parent_class(ClassNode $node)
|
||||
{
|
||||
$node->getParentClass()->willReturn('SplFileInfo');
|
||||
$this->supports($node)->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_supports_nodes_with_derivative_of_SplFileInfo_as_parent_class(ClassNode $node)
|
||||
{
|
||||
$node->getParentClass()->willReturn('SplFileInfo');
|
||||
$this->supports($node)->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_adds_a_method_to_node_if_not_exists(ClassNode $node)
|
||||
{
|
||||
$node->hasMethod('__construct')->willReturn(false);
|
||||
$node->addMethod(Argument::any())->shouldBeCalled();
|
||||
$node->getParentClass()->shouldBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
|
||||
function it_updates_existing_method_if_found(ClassNode $node, MethodNode $method)
|
||||
{
|
||||
$node->hasMethod('__construct')->willReturn(true);
|
||||
$node->getMethod('__construct')->willReturn($method);
|
||||
$node->getParentClass()->shouldBeCalled();
|
||||
|
||||
$method->useParentCode()->shouldBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
|
||||
function it_should_not_supply_a_file_for_a_directory_iterator(ClassNode $node, MethodNode $method)
|
||||
{
|
||||
$node->hasMethod('__construct')->willReturn(true);
|
||||
$node->getMethod('__construct')->willReturn($method);
|
||||
$node->getParentClass()->willReturn('DirectoryIterator');
|
||||
|
||||
$method->setCode(Argument::that(function($value) {
|
||||
return strpos($value, '.php') === false;
|
||||
}))->shouldBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
|
||||
function it_should_supply_a_file_for_a_spl_file_object(ClassNode $node, MethodNode $method)
|
||||
{
|
||||
$node->hasMethod('__construct')->willReturn(true);
|
||||
$node->getMethod('__construct')->willReturn($method);
|
||||
$node->getParentClass()->willReturn('SplFileObject');
|
||||
|
||||
$method->setCode(Argument::that(function($value) {
|
||||
return strpos($value, '.php') !== false;
|
||||
}))->shouldBeCalled();
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
}
|
||||
50
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/TraversablePatchSpec.php
vendored
Normal file
50
vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/TraversablePatchSpec.php
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\ClassPatch;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Doubler\Generator\Node\ClassNode;
|
||||
|
||||
class TraversablePatchSpec extends ObjectBehavior
|
||||
{
|
||||
function it_is_a_patch()
|
||||
{
|
||||
$this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
|
||||
}
|
||||
|
||||
function it_supports_class_that_implements_only_Traversable(ClassNode $node)
|
||||
{
|
||||
$node->getInterfaces()->willReturn(array('Traversable'));
|
||||
|
||||
$this->supports($node)->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_does_not_support_class_that_implements_Iterator(ClassNode $node)
|
||||
{
|
||||
$node->getInterfaces()->willReturn(array('Traversable', 'Iterator'));
|
||||
|
||||
$this->supports($node)->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_does_not_support_class_that_implements_IteratorAggregate(ClassNode $node)
|
||||
{
|
||||
$node->getInterfaces()->willReturn(array('Traversable', 'IteratorAggregate'));
|
||||
|
||||
$this->supports($node)->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_has_100_priority()
|
||||
{
|
||||
$this->getPriority()->shouldReturn(100);
|
||||
}
|
||||
|
||||
function it_forces_node_to_implement_IteratorAggregate(ClassNode $node)
|
||||
{
|
||||
$node->addInterface('Iterator')->shouldBeCalled();
|
||||
|
||||
$node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
|
||||
|
||||
$this->apply($node);
|
||||
}
|
||||
}
|
||||
115
vendor/phpspec/prophecy/spec/Prophecy/Doubler/DoublerSpec.php
vendored
Normal file
115
vendor/phpspec/prophecy/spec/Prophecy/Doubler/DoublerSpec.php
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Doubler\ClassPatch\ClassPatchInterface;
|
||||
use Prophecy\Doubler\Generator\ClassCreator;
|
||||
use Prophecy\Doubler\Generator\ClassMirror;
|
||||
use Prophecy\Doubler\Generator\Node\ClassNode;
|
||||
use Prophecy\Doubler\NameGenerator;
|
||||
|
||||
class DoublerSpec extends ObjectBehavior
|
||||
{
|
||||
function let(ClassMirror $mirror, ClassCreator $creator, NameGenerator $namer)
|
||||
{
|
||||
$this->beConstructedWith($mirror, $creator, $namer);
|
||||
}
|
||||
|
||||
function it_does_not_have_patches_by_default()
|
||||
{
|
||||
$this->getClassPatches()->shouldHaveCount(0);
|
||||
}
|
||||
|
||||
function its_registerClassPatch_adds_a_patch_to_the_doubler(ClassPatchInterface $patch)
|
||||
{
|
||||
$this->registerClassPatch($patch);
|
||||
$this->getClassPatches()->shouldReturn(array($patch));
|
||||
}
|
||||
|
||||
function its_getClassPatches_sorts_patches_by_priority(
|
||||
ClassPatchInterface $alt1,
|
||||
ClassPatchInterface $alt2,
|
||||
ClassPatchInterface $alt3,
|
||||
ClassPatchInterface $alt4
|
||||
) {
|
||||
$alt1->getPriority()->willReturn(2);
|
||||
$alt2->getPriority()->willReturn(50);
|
||||
$alt3->getPriority()->willReturn(10);
|
||||
$alt4->getPriority()->willReturn(0);
|
||||
|
||||
$this->registerClassPatch($alt1);
|
||||
$this->registerClassPatch($alt2);
|
||||
$this->registerClassPatch($alt3);
|
||||
$this->registerClassPatch($alt4);
|
||||
|
||||
$this->getClassPatches()->shouldReturn(array($alt2, $alt3, $alt1, $alt4));
|
||||
}
|
||||
|
||||
function its_double_mirrors_alterates_and_instantiates_provided_class(
|
||||
$mirror,
|
||||
$creator,
|
||||
$namer,
|
||||
ClassPatchInterface $alt1,
|
||||
ClassPatchInterface $alt2,
|
||||
\ReflectionClass $class,
|
||||
\ReflectionClass $interface1,
|
||||
\ReflectionClass $interface2,
|
||||
ClassNode $node
|
||||
) {
|
||||
$mirror->reflect($class, array($interface1, $interface2))->willReturn($node);
|
||||
$alt1->supports($node)->willReturn(true);
|
||||
$alt2->supports($node)->willReturn(false);
|
||||
$alt1->getPriority()->willReturn(1);
|
||||
$alt2->getPriority()->willReturn(2);
|
||||
$namer->name($class, array($interface1, $interface2))->willReturn('SplStack');
|
||||
$class->getName()->willReturn('stdClass');
|
||||
$interface1->getName()->willReturn('ArrayAccess');
|
||||
$interface2->getName()->willReturn('Iterator');
|
||||
|
||||
$alt1->apply($node)->shouldBeCalled();
|
||||
$alt2->apply($node)->shouldNotBeCalled();
|
||||
$creator->create('SplStack', $node)->shouldBeCalled();
|
||||
|
||||
$this->registerClassPatch($alt1);
|
||||
$this->registerClassPatch($alt2);
|
||||
|
||||
$this->double($class, array($interface1, $interface2))
|
||||
->shouldReturnAnInstanceOf('SplStack');
|
||||
}
|
||||
|
||||
function it_double_instantiates_a_class_with_constructor_argument(
|
||||
$mirror,
|
||||
\ReflectionClass $class,
|
||||
ClassNode $node,
|
||||
$namer
|
||||
) {
|
||||
$class->getName()->willReturn('ReflectionClass');
|
||||
$mirror->reflect($class, array())->willReturn($node);
|
||||
$namer->name($class, array())->willReturn('ReflectionClass');
|
||||
|
||||
$double = $this->double($class, array(), array('stdClass'));
|
||||
$double->shouldBeAnInstanceOf('ReflectionClass');
|
||||
$double->getName()->shouldReturn('stdClass');
|
||||
}
|
||||
|
||||
function it_can_instantiate_class_with_final_constructor(
|
||||
$mirror,
|
||||
\ReflectionClass $class,
|
||||
ClassNode $node,
|
||||
$namer
|
||||
) {
|
||||
$class->getName()->willReturn('spec\Prophecy\Doubler\WithFinalConstructor');
|
||||
$mirror->reflect($class, array())->willReturn($node);
|
||||
$namer->name($class, array())->willReturn('spec\Prophecy\Doubler\WithFinalConstructor');
|
||||
|
||||
$double = $this->double($class, array());
|
||||
|
||||
$double->shouldBeAnInstanceOf('spec\Prophecy\Doubler\WithFinalConstructor');
|
||||
}
|
||||
}
|
||||
|
||||
class WithFinalConstructor
|
||||
{
|
||||
final public function __construct() {}
|
||||
}
|
||||
362
vendor/phpspec/prophecy/spec/Prophecy/Doubler/Generator/ClassCodeGeneratorSpec.php
vendored
Normal file
362
vendor/phpspec/prophecy/spec/Prophecy/Doubler/Generator/ClassCodeGeneratorSpec.php
vendored
Normal file
@@ -0,0 +1,362 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\Generator;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\Tags\Method;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\Doubler\Generator\Node\ArgumentNode;
|
||||
use Prophecy\Doubler\Generator\Node\ClassNode;
|
||||
use Prophecy\Doubler\Generator\Node\MethodNode;
|
||||
|
||||
class ClassCodeGeneratorSpec extends ObjectBehavior
|
||||
{
|
||||
function it_generates_proper_php_code_for_specific_ClassNode(
|
||||
ClassNode $class,
|
||||
MethodNode $method1,
|
||||
MethodNode $method2,
|
||||
MethodNode $method3,
|
||||
MethodNode $method4,
|
||||
ArgumentNode $argument11,
|
||||
ArgumentNode $argument12,
|
||||
ArgumentNode $argument21,
|
||||
ArgumentNode $argument31
|
||||
) {
|
||||
$class->getParentClass()->willReturn('RuntimeException');
|
||||
$class->getInterfaces()->willReturn(array(
|
||||
'Prophecy\Doubler\Generator\MirroredInterface', 'ArrayAccess', 'ArrayIterator'
|
||||
));
|
||||
$class->getProperties()->willReturn(array('name' => 'public', 'email' => 'private'));
|
||||
$class->getMethods()->willReturn(array($method1, $method2, $method3, $method4));
|
||||
|
||||
$method1->getName()->willReturn('getName');
|
||||
$method1->getVisibility()->willReturn('public');
|
||||
$method1->returnsReference()->willReturn(false);
|
||||
$method1->isStatic()->willReturn(true);
|
||||
$method1->getArguments()->willReturn(array($argument11, $argument12));
|
||||
$method1->hasReturnType()->willReturn(true);
|
||||
$method1->getReturnType()->willReturn('string');
|
||||
$method1->hasNullableReturnType()->willReturn(true);
|
||||
$method1->getCode()->willReturn('return $this->name;');
|
||||
|
||||
$method2->getName()->willReturn('getEmail');
|
||||
$method2->getVisibility()->willReturn('protected');
|
||||
$method2->returnsReference()->willReturn(false);
|
||||
$method2->isStatic()->willReturn(false);
|
||||
$method2->getArguments()->willReturn(array($argument21));
|
||||
$method2->hasReturnType()->willReturn(false);
|
||||
$method2->hasNullableReturnType()->willReturn(true);
|
||||
$method2->getCode()->willReturn('return $this->email;');
|
||||
|
||||
$method3->getName()->willReturn('getRefValue');
|
||||
$method3->getVisibility()->willReturn('public');
|
||||
$method3->returnsReference()->willReturn(true);
|
||||
$method3->isStatic()->willReturn(false);
|
||||
$method3->getArguments()->willReturn(array($argument31));
|
||||
$method3->hasReturnType()->willReturn(true);
|
||||
$method3->getReturnType()->willReturn('string');
|
||||
$method3->hasNullableReturnType()->willReturn(false);
|
||||
$method3->getCode()->willReturn('return $this->refValue;');
|
||||
|
||||
$method4->getName()->willReturn('doSomething');
|
||||
$method4->getVisibility()->willReturn('public');
|
||||
$method4->returnsReference()->willReturn(false);
|
||||
$method4->isStatic()->willReturn(false);
|
||||
$method4->getArguments()->willReturn(array());
|
||||
$method4->hasReturnType()->willReturn(true);
|
||||
$method4->getReturnType()->willReturn('void');
|
||||
$method4->hasNullableReturnType()->willReturn(false);
|
||||
$method4->getCode()->willReturn('return;');
|
||||
|
||||
$argument11->getName()->willReturn('fullname');
|
||||
$argument11->getTypeHint()->willReturn('array');
|
||||
$argument11->isOptional()->willReturn(true);
|
||||
$argument11->getDefault()->willReturn(null);
|
||||
$argument11->isPassedByReference()->willReturn(false);
|
||||
$argument11->isVariadic()->willReturn(false);
|
||||
$argument11->isNullable()->willReturn(false);
|
||||
|
||||
$argument12->getName()->willReturn('class');
|
||||
$argument12->getTypeHint()->willReturn('ReflectionClass');
|
||||
$argument12->isOptional()->willReturn(false);
|
||||
$argument12->isPassedByReference()->willReturn(false);
|
||||
$argument12->isVariadic()->willReturn(false);
|
||||
$argument12->isNullable()->willReturn(false);
|
||||
|
||||
$argument21->getName()->willReturn('default');
|
||||
$argument21->getTypeHint()->willReturn('string');
|
||||
$argument21->isOptional()->willReturn(true);
|
||||
$argument21->getDefault()->willReturn('ever.zet@gmail.com');
|
||||
$argument21->isPassedByReference()->willReturn(false);
|
||||
$argument21->isVariadic()->willReturn(false);
|
||||
$argument21->isNullable()->willReturn(true);
|
||||
|
||||
$argument31->getName()->willReturn('refValue');
|
||||
$argument31->getTypeHint()->willReturn(null);
|
||||
$argument31->isOptional()->willReturn(false);
|
||||
$argument31->getDefault()->willReturn();
|
||||
$argument31->isPassedByReference()->willReturn(false);
|
||||
$argument31->isVariadic()->willReturn(false);
|
||||
$argument31->isNullable()->willReturn(false);
|
||||
|
||||
$code = $this->generate('CustomClass', $class);
|
||||
|
||||
if (version_compare(PHP_VERSION, '7.1', '>=')) {
|
||||
$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): ?string {
|
||||
return $this->name;
|
||||
}
|
||||
protected function getEmail(?string $default = 'ever.zet@gmail.com') {
|
||||
return $this->email;
|
||||
}
|
||||
public function &getRefValue( $refValue): string {
|
||||
return $this->refValue;
|
||||
}
|
||||
public function doSomething(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
} elseif (version_compare(PHP_VERSION, '7.0', '>=')) {
|
||||
$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): string {
|
||||
return $this->name;
|
||||
}
|
||||
protected function getEmail(string $default = 'ever.zet@gmail.com') {
|
||||
return $this->email;
|
||||
}
|
||||
public function &getRefValue( $refValue): string {
|
||||
return $this->refValue;
|
||||
}
|
||||
public function doSomething() {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
public function doSomething() {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
}
|
||||
$expected = strtr($expected, array("\r\n" => "\n", "\r" => "\n"));
|
||||
$code->shouldBe($expected);
|
||||
}
|
||||
|
||||
function it_generates_proper_php_code_for_variadics(
|
||||
ClassNode $class,
|
||||
MethodNode $method1,
|
||||
MethodNode $method2,
|
||||
MethodNode $method3,
|
||||
MethodNode $method4,
|
||||
ArgumentNode $argument1,
|
||||
ArgumentNode $argument2,
|
||||
ArgumentNode $argument3,
|
||||
ArgumentNode $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);
|
||||
$argument1->isNullable()->willReturn(false);
|
||||
|
||||
$argument2->getName()->willReturn('args');
|
||||
$argument2->getTypeHint()->willReturn(null);
|
||||
$argument2->isOptional()->willReturn(false);
|
||||
$argument2->isPassedByReference()->willReturn(true);
|
||||
$argument2->isVariadic()->willReturn(true);
|
||||
$argument2->isNullable()->willReturn(false);
|
||||
|
||||
$argument3->getName()->willReturn('args');
|
||||
$argument3->getTypeHint()->willReturn('\ReflectionClass');
|
||||
$argument3->isOptional()->willReturn(false);
|
||||
$argument3->isPassedByReference()->willReturn(false);
|
||||
$argument3->isVariadic()->willReturn(true);
|
||||
$argument3->isNullable()->willReturn(false);
|
||||
|
||||
$argument4->getName()->willReturn('args');
|
||||
$argument4->getTypeHint()->willReturn('\ReflectionClass');
|
||||
$argument4->isOptional()->willReturn(false);
|
||||
$argument4->isPassedByReference()->willReturn(true);
|
||||
$argument4->isVariadic()->willReturn(true);
|
||||
$argument4->isNullable()->willReturn(false);
|
||||
|
||||
$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;
|
||||
$expected = strtr($expected, array("\r\n" => "\n", "\r" => "\n"));
|
||||
$code->shouldBe($expected);
|
||||
}
|
||||
|
||||
function it_overrides_properly_methods_with_args_passed_by_reference(
|
||||
ClassNode $class,
|
||||
MethodNode $method,
|
||||
ArgumentNode $argument
|
||||
) {
|
||||
$class->getParentClass()->willReturn('RuntimeException');
|
||||
$class->getInterfaces()->willReturn(array('Prophecy\Doubler\Generator\MirroredInterface'));
|
||||
$class->getProperties()->willReturn(array());
|
||||
$class->getMethods()->willReturn(array($method));
|
||||
|
||||
$method->getName()->willReturn('getName');
|
||||
$method->getVisibility()->willReturn('public');
|
||||
$method->isStatic()->willReturn(false);
|
||||
$method->getArguments()->willReturn(array($argument));
|
||||
$method->hasReturnType()->willReturn(false);
|
||||
$method->returnsReference()->willReturn(false);
|
||||
$method->getCode()->willReturn('return $this->name;');
|
||||
|
||||
$argument->getName()->willReturn('fullname');
|
||||
$argument->getTypeHint()->willReturn('array');
|
||||
$argument->isOptional()->willReturn(true);
|
||||
$argument->getDefault()->willReturn(null);
|
||||
$argument->isPassedByReference()->willReturn(true);
|
||||
$argument->isVariadic()->willReturn(false);
|
||||
$argument->isNullable()->willReturn(false);
|
||||
|
||||
$code = $this->generate('CustomClass', $class);
|
||||
$expected =<<<'PHP'
|
||||
namespace {
|
||||
class CustomClass extends \RuntimeException implements \Prophecy\Doubler\Generator\MirroredInterface {
|
||||
|
||||
public function getName(array &$fullname = NULL) {
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
$expected = strtr($expected, array("\r\n" => "\n", "\r" => "\n"));
|
||||
$code->shouldBe($expected);
|
||||
}
|
||||
|
||||
function it_generates_empty_class_for_empty_ClassNode(ClassNode $class)
|
||||
{
|
||||
$class->getParentClass()->willReturn('stdClass');
|
||||
$class->getInterfaces()->willReturn(array('Prophecy\Doubler\Generator\MirroredInterface'));
|
||||
$class->getProperties()->willReturn(array());
|
||||
$class->getMethods()->willReturn(array());
|
||||
|
||||
$code = $this->generate('CustomClass', $class);
|
||||
$expected =<<<'PHP'
|
||||
namespace {
|
||||
class CustomClass extends \stdClass implements \Prophecy\Doubler\Generator\MirroredInterface {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
$expected = strtr($expected, array("\r\n" => "\n", "\r" => "\n"));
|
||||
$code->shouldBe($expected);
|
||||
}
|
||||
|
||||
function it_wraps_class_in_namespace_if_it_is_namespaced(ClassNode $class)
|
||||
{
|
||||
$class->getParentClass()->willReturn('stdClass');
|
||||
$class->getInterfaces()->willReturn(array('Prophecy\Doubler\Generator\MirroredInterface'));
|
||||
$class->getProperties()->willReturn(array());
|
||||
$class->getMethods()->willReturn(array());
|
||||
|
||||
$code = $this->generate('My\Awesome\CustomClass', $class);
|
||||
$expected =<<<'PHP'
|
||||
namespace My\Awesome {
|
||||
class CustomClass extends \stdClass implements \Prophecy\Doubler\Generator\MirroredInterface {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
PHP;
|
||||
$expected = strtr($expected, array("\r\n" => "\n", "\r" => "\n"));
|
||||
$code->shouldBe($expected);
|
||||
}
|
||||
}
|
||||
37
vendor/phpspec/prophecy/spec/Prophecy/Doubler/Generator/ClassCreatorSpec.php
vendored
Normal file
37
vendor/phpspec/prophecy/spec/Prophecy/Doubler/Generator/ClassCreatorSpec.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\Generator;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Doubler\Generator\ClassCodeGenerator;
|
||||
use Prophecy\Doubler\Generator\Node\ClassNode;
|
||||
|
||||
class ClassCreatorSpec extends ObjectBehavior
|
||||
{
|
||||
function let(ClassCodeGenerator $generator)
|
||||
{
|
||||
$this->beConstructedWith($generator);
|
||||
}
|
||||
|
||||
function it_evaluates_code_generated_by_ClassCodeGenerator($generator, ClassNode $class)
|
||||
{
|
||||
$generator->generate('stdClass', $class)->shouldBeCalled()->willReturn(
|
||||
'return 42;'
|
||||
);
|
||||
|
||||
$this->create('stdClass', $class)->shouldReturn(42);
|
||||
}
|
||||
|
||||
function it_throws_an_exception_if_class_does_not_exist_after_evaluation($generator, ClassNode $class)
|
||||
{
|
||||
$generator->generate('CustomClass', $class)->shouldBeCalled()->willReturn(
|
||||
'return 42;'
|
||||
);
|
||||
|
||||
$class->getParentClass()->willReturn('stdClass');
|
||||
$class->getInterfaces()->willReturn(array('Interface1', 'Interface2'));
|
||||
|
||||
$this->shouldThrow('Prophecy\Exception\Doubler\ClassCreatorException')
|
||||
->duringCreate('CustomClass', $class);
|
||||
}
|
||||
}
|
||||
92
vendor/phpspec/prophecy/spec/Prophecy/Doubler/Generator/Node/ArgumentNodeSpec.php
vendored
Normal file
92
vendor/phpspec/prophecy/spec/Prophecy/Doubler/Generator/Node/ArgumentNodeSpec.php
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\Generator\Node;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
class ArgumentNodeSpec extends ObjectBehavior
|
||||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith('name');
|
||||
}
|
||||
|
||||
function it_is_not_be_passed_by_reference_by_default()
|
||||
{
|
||||
$this->shouldNotBePassedByReference();
|
||||
}
|
||||
|
||||
function it_is_passed_by_reference_if_marked()
|
||||
{
|
||||
$this->setAsPassedByReference();
|
||||
$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');
|
||||
}
|
||||
|
||||
function it_has_no_typehint_by_default()
|
||||
{
|
||||
$this->getTypeHint()->shouldReturn(null);
|
||||
}
|
||||
|
||||
function its_typeHint_is_mutable()
|
||||
{
|
||||
$this->setTypeHint('array');
|
||||
$this->getTypeHint()->shouldReturn('array');
|
||||
}
|
||||
|
||||
function it_does_not_have_default_value_by_default()
|
||||
{
|
||||
$this->getDefault()->shouldReturn(null);
|
||||
}
|
||||
|
||||
function it_is_not_optional_by_default()
|
||||
{
|
||||
$this->isOptional()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function its_default_is_mutable()
|
||||
{
|
||||
$this->setDefault(array());
|
||||
$this->getDefault()->shouldReturn(array());
|
||||
}
|
||||
|
||||
function it_is_marked_as_optional_when_default_is_set()
|
||||
{
|
||||
$this->setDefault(null);
|
||||
$this->isOptional()->shouldReturn(true);
|
||||
}
|
||||
}
|
||||
185
vendor/phpspec/prophecy/spec/Prophecy/Doubler/Generator/Node/ClassNodeSpec.php
vendored
Normal file
185
vendor/phpspec/prophecy/spec/Prophecy/Doubler/Generator/Node/ClassNodeSpec.php
vendored
Normal file
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\Generator\Node;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Doubler\Generator\Node\MethodNode;
|
||||
use Prophecy\Exception\Doubler\MethodNotExtendableException;
|
||||
|
||||
class ClassNodeSpec extends ObjectBehavior
|
||||
{
|
||||
function its_parentClass_is_a_stdClass_by_default()
|
||||
{
|
||||
$this->getParentClass()->shouldReturn('stdClass');
|
||||
}
|
||||
|
||||
function its_parentClass_is_mutable()
|
||||
{
|
||||
$this->setParentClass('Exception');
|
||||
$this->getParentClass()->shouldReturn('Exception');
|
||||
}
|
||||
|
||||
function its_parentClass_is_set_to_stdClass_if_user_set_null()
|
||||
{
|
||||
$this->setParentClass(null);
|
||||
$this->getParentClass()->shouldReturn('stdClass');
|
||||
}
|
||||
|
||||
function it_does_not_implement_any_interface_by_default()
|
||||
{
|
||||
$this->getInterfaces()->shouldHaveCount(0);
|
||||
}
|
||||
|
||||
function its_addInterface_adds_item_to_the_list_of_implemented_interfaces()
|
||||
{
|
||||
$this->addInterface('MyInterface');
|
||||
$this->getInterfaces()->shouldHaveCount(1);
|
||||
}
|
||||
|
||||
function its_hasInterface_returns_true_if_class_implements_interface()
|
||||
{
|
||||
$this->addInterface('MyInterface');
|
||||
$this->hasInterface('MyInterface')->shouldReturn(true);
|
||||
}
|
||||
|
||||
function its_hasInterface_returns_false_if_class_does_not_implements_interface()
|
||||
{
|
||||
$this->hasInterface('MyInterface')->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_supports_implementation_of_multiple_interfaces()
|
||||
{
|
||||
$this->addInterface('MyInterface');
|
||||
$this->addInterface('MySecondInterface');
|
||||
$this->getInterfaces()->shouldHaveCount(2);
|
||||
}
|
||||
|
||||
function it_ignores_same_interfaces_added_twice()
|
||||
{
|
||||
$this->addInterface('MyInterface');
|
||||
$this->addInterface('MyInterface');
|
||||
|
||||
$this->getInterfaces()->shouldHaveCount(1);
|
||||
$this->getInterfaces()->shouldReturn(array('MyInterface'));
|
||||
}
|
||||
|
||||
function it_does_not_have_methods_by_default()
|
||||
{
|
||||
$this->getMethods()->shouldHaveCount(0);
|
||||
}
|
||||
|
||||
function it_can_has_methods(MethodNode $method1, MethodNode $method2)
|
||||
{
|
||||
$method1->getName()->willReturn('__construct');
|
||||
$method2->getName()->willReturn('getName');
|
||||
|
||||
$this->addMethod($method1);
|
||||
$this->addMethod($method2);
|
||||
|
||||
$this->getMethods()->shouldReturn(array(
|
||||
'__construct' => $method1,
|
||||
'getName' => $method2
|
||||
));
|
||||
}
|
||||
|
||||
function its_hasMethod_returns_true_if_method_exists(MethodNode $method)
|
||||
{
|
||||
$method->getName()->willReturn('getName');
|
||||
|
||||
$this->addMethod($method);
|
||||
|
||||
$this->hasMethod('getName')->shouldReturn(true);
|
||||
}
|
||||
|
||||
function its_getMethod_returns_method_by_name(MethodNode $method)
|
||||
{
|
||||
$method->getName()->willReturn('getName');
|
||||
|
||||
$this->addMethod($method);
|
||||
|
||||
$this->getMethod('getName')->shouldReturn($method);
|
||||
}
|
||||
|
||||
function its_hasMethod_returns_false_if_method_does_not_exists()
|
||||
{
|
||||
$this->hasMethod('getName')->shouldReturn(false);
|
||||
}
|
||||
|
||||
function its_hasMethod_returns_false_if_method_has_been_removed(MethodNode $method)
|
||||
{
|
||||
$method->getName()->willReturn('getName');
|
||||
$this->addMethod($method);
|
||||
$this->removeMethod('getName');
|
||||
|
||||
$this->hasMethod('getName')->shouldReturn(false);
|
||||
}
|
||||
|
||||
|
||||
function it_does_not_have_properties_by_default()
|
||||
{
|
||||
$this->getProperties()->shouldHaveCount(0);
|
||||
}
|
||||
|
||||
function it_is_able_to_have_properties()
|
||||
{
|
||||
$this->addProperty('title');
|
||||
$this->addProperty('text', 'private');
|
||||
$this->getProperties()->shouldReturn(array(
|
||||
'title' => 'public',
|
||||
'text' => 'private'
|
||||
));
|
||||
}
|
||||
|
||||
function its_addProperty_does_not_accept_unsupported_visibility()
|
||||
{
|
||||
$this->shouldThrow('InvalidArgumentException')->duringAddProperty('title', 'town');
|
||||
}
|
||||
|
||||
function its_addProperty_lowercases_visibility_before_setting()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
function it_throws_an_exception_when_adding_a_method_that_isnt_extendable(MethodNode $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);
|
||||
}
|
||||
}
|
||||
134
vendor/phpspec/prophecy/spec/Prophecy/Doubler/Generator/Node/MethodNodeSpec.php
vendored
Normal file
134
vendor/phpspec/prophecy/spec/Prophecy/Doubler/Generator/Node/MethodNodeSpec.php
vendored
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler\Generator\Node;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Doubler\Generator\Node\ArgumentNode;
|
||||
|
||||
class MethodNodeSpec extends ObjectBehavior
|
||||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith('getTitle');
|
||||
}
|
||||
|
||||
function it_has_a_name()
|
||||
{
|
||||
$this->getName()->shouldReturn('getTitle');
|
||||
}
|
||||
|
||||
function it_has_public_visibility_by_default()
|
||||
{
|
||||
$this->getVisibility()->shouldReturn('public');
|
||||
}
|
||||
|
||||
function its_visibility_is_mutable()
|
||||
{
|
||||
$this->setVisibility('private');
|
||||
$this->getVisibility()->shouldReturn('private');
|
||||
}
|
||||
|
||||
function it_is_not_static_by_default()
|
||||
{
|
||||
$this->shouldNotBeStatic();
|
||||
}
|
||||
|
||||
function it_does_not_return_a_reference_by_default()
|
||||
{
|
||||
$this->returnsReference()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_should_be_settable_as_returning_a_reference_through_setter()
|
||||
{
|
||||
$this->setReturnsReference();
|
||||
$this->returnsReference()->shouldReturn(true);
|
||||
}
|
||||
|
||||
function it_should_be_settable_as_static_through_setter()
|
||||
{
|
||||
$this->setStatic();
|
||||
$this->shouldBeStatic();
|
||||
}
|
||||
|
||||
function it_accepts_only_supported_visibilities()
|
||||
{
|
||||
$this->shouldThrow('InvalidArgumentException')->duringSetVisibility('stealth');
|
||||
}
|
||||
|
||||
function it_lowercases_visibility_before_setting_it()
|
||||
{
|
||||
$this->setVisibility('Public');
|
||||
$this->getVisibility()->shouldReturn('public');
|
||||
}
|
||||
|
||||
function its_useParentCode_causes_method_to_call_parent(ArgumentNode $argument1, ArgumentNode $argument2)
|
||||
{
|
||||
$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);'
|
||||
);
|
||||
}
|
||||
|
||||
function its_code_is_mutable()
|
||||
{
|
||||
$this->setCode('echo "code";');
|
||||
$this->getCode()->shouldReturn('echo "code";');
|
||||
}
|
||||
|
||||
function its_reference_returning_methods_will_generate_exceptions()
|
||||
{
|
||||
$this->setCode('echo "code";');
|
||||
$this->setReturnsReference();
|
||||
$this->getCode()->shouldReturn("throw new \Prophecy\Exception\Doubler\ReturnByReferenceException('Returning by reference not supported', get_class(\$this), 'getTitle');");
|
||||
}
|
||||
|
||||
function its_setCode_provided_with_null_cleans_method_body()
|
||||
{
|
||||
$this->setCode(null);
|
||||
$this->getCode()->shouldReturn('');
|
||||
}
|
||||
|
||||
function it_is_constructable_with_code()
|
||||
{
|
||||
$this->beConstructedWith('getTitle', 'die();');
|
||||
$this->getCode()->shouldReturn('die();');
|
||||
}
|
||||
|
||||
function it_does_not_have_arguments_by_default()
|
||||
{
|
||||
$this->getArguments()->shouldHaveCount(0);
|
||||
}
|
||||
|
||||
function it_supports_adding_arguments(ArgumentNode $argument1, ArgumentNode $argument2)
|
||||
{
|
||||
$this->addArgument($argument1);
|
||||
$this->addArgument($argument2);
|
||||
|
||||
$this->getArguments()->shouldReturn(array($argument1, $argument2));
|
||||
}
|
||||
|
||||
function it_does_not_have_return_type_by_default()
|
||||
{
|
||||
$this->hasReturnType()->shouldReturn(false);
|
||||
}
|
||||
|
||||
function it_setReturnType_sets_return_type()
|
||||
{
|
||||
$returnType = 'string';
|
||||
|
||||
$this->setReturnType($returnType);
|
||||
|
||||
$this->hasReturnType()->shouldReturn(true);
|
||||
$this->getReturnType()->shouldReturn($returnType);
|
||||
}
|
||||
}
|
||||
79
vendor/phpspec/prophecy/spec/Prophecy/Doubler/LazyDoubleSpec.php
vendored
Normal file
79
vendor/phpspec/prophecy/spec/Prophecy/Doubler/LazyDoubleSpec.php
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Doubler\Doubler;
|
||||
use Prophecy\Prophecy\ProphecySubjectInterface;
|
||||
|
||||
class LazyDoubleSpec extends ObjectBehavior
|
||||
{
|
||||
function let(Doubler $doubler)
|
||||
{
|
||||
$this->beConstructedWith($doubler);
|
||||
}
|
||||
|
||||
function it_returns_anonymous_double_instance_by_default($doubler, ProphecySubjectInterface $double)
|
||||
{
|
||||
$doubler->double(null, array())->willReturn($double);
|
||||
|
||||
$this->getInstance()->shouldReturn($double);
|
||||
}
|
||||
|
||||
function it_returns_class_double_instance_if_set($doubler, ProphecySubjectInterface $double, \ReflectionClass $class)
|
||||
{
|
||||
$doubler->double($class, array())->willReturn($double);
|
||||
|
||||
$this->setParentClass($class);
|
||||
|
||||
$this->getInstance()->shouldReturn($double);
|
||||
}
|
||||
|
||||
function it_returns_same_double_instance_if_called_2_times(
|
||||
$doubler,
|
||||
ProphecySubjectInterface $double1,
|
||||
ProphecySubjectInterface $double2
|
||||
) {
|
||||
$doubler->double(null, array())->willReturn($double1);
|
||||
$doubler->double(null, array())->willReturn($double2);
|
||||
|
||||
$this->getInstance()->shouldReturn($double2);
|
||||
$this->getInstance()->shouldReturn($double2);
|
||||
}
|
||||
|
||||
function its_setParentClass_throws_ClassNotFoundException_if_class_not_found()
|
||||
{
|
||||
$this->shouldThrow('Prophecy\Exception\Doubler\ClassNotFoundException')
|
||||
->duringSetParentClass('SomeUnexistingClass');
|
||||
}
|
||||
|
||||
function its_setParentClass_throws_exception_if_prophecy_is_already_created(
|
||||
$doubler,
|
||||
ProphecySubjectInterface $double
|
||||
) {
|
||||
$doubler->double(null, array())->willReturn($double);
|
||||
|
||||
$this->getInstance();
|
||||
|
||||
$this->shouldThrow('Prophecy\Exception\Doubler\DoubleException')
|
||||
->duringSetParentClass('stdClass');
|
||||
}
|
||||
|
||||
function its_addInterface_throws_InterfaceNotFoundException_if_no_interface_found()
|
||||
{
|
||||
$this->shouldThrow('Prophecy\Exception\Doubler\InterfaceNotFoundException')
|
||||
->duringAddInterface('SomeUnexistingInterface');
|
||||
}
|
||||
|
||||
function its_addInterface_throws_exception_if_prophecy_is_already_created(
|
||||
$doubler,
|
||||
ProphecySubjectInterface $double
|
||||
) {
|
||||
$doubler->double(null, array())->willReturn($double);
|
||||
|
||||
$this->getInstance();
|
||||
|
||||
$this->shouldThrow('Prophecy\Exception\Doubler\DoubleException')
|
||||
->duringAddInterface('ArrayAccess');
|
||||
}
|
||||
}
|
||||
60
vendor/phpspec/prophecy/spec/Prophecy/Doubler/NameGeneratorSpec.php
vendored
Normal file
60
vendor/phpspec/prophecy/spec/Prophecy/Doubler/NameGeneratorSpec.php
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace spec\Prophecy\Doubler;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
|
||||
class NameGeneratorSpec extends ObjectBehavior
|
||||
{
|
||||
function its_name_generates_name_based_on_simple_class_reflection(\ReflectionClass $class)
|
||||
{
|
||||
$class->getName()->willReturn('stdClass');
|
||||
$this->name($class, array())->shouldStartWith('Double\stdClass\\');
|
||||
}
|
||||
|
||||
function its_name_generates_name_based_on_namespaced_class_reflection(\ReflectionClass $class)
|
||||
{
|
||||
$class->getName()->willReturn('Some\Custom\Class');
|
||||
$this->name($class, array())->shouldStartWith('Double\Some\Custom\Class\P');
|
||||
}
|
||||
|
||||
function its_name_generates_name_based_on_interface_shortnames(
|
||||
\ReflectionClass $interface1,
|
||||
\ReflectionClass $interface2
|
||||
) {
|
||||
$interface1->getShortName()->willReturn('HandlerInterface');
|
||||
$interface2->getShortName()->willReturn('LoaderInterface');
|
||||
|
||||
$this->name(null, array($interface1, $interface2))->shouldStartWith(
|
||||
'Double\HandlerInterface\LoaderInterface\P'
|
||||
);
|
||||
}
|
||||
|
||||
function it_generates_proper_name_for_no_class_and_interfaces_list()
|
||||
{
|
||||
$this->name(null, array())->shouldStartWith('Double\stdClass\P');
|
||||
}
|
||||
|
||||
function its_name_generates_name_based_only_on_class_if_its_available(
|
||||
\ReflectionClass $class,
|
||||
\ReflectionClass $interface1,
|
||||
\ReflectionClass $interface2
|
||||
) {
|
||||
$class->getName()->willReturn('Some\Custom\Class');
|
||||
$interface1->getShortName()->willReturn('HandlerInterface');
|
||||
$interface2->getShortName()->willReturn('LoaderInterface');
|
||||
|
||||
$this->name($class, array($interface1, $interface2))->shouldStartWith(
|
||||
'Double\Some\Custom\Class\P'
|
||||
);
|
||||
}
|
||||
|
||||
public function getMatchers()
|
||||
{
|
||||
return array(
|
||||
'startWith' => function ($subject, $string) {
|
||||
return 0 === strpos($subject, $string);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user