ReflectionClassNewInstancePatchSpec.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace spec\Prophecy\Doubler\ClassPatch;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. use Prophecy\Doubler\Generator\Node\ArgumentNode;
  6. use Prophecy\Doubler\Generator\Node\ClassNode;
  7. use Prophecy\Doubler\Generator\Node\MethodNode;
  8. class ReflectionClassNewInstancePatchSpec extends ObjectBehavior
  9. {
  10. function it_is_a_patch()
  11. {
  12. $this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
  13. }
  14. function its_priority_is_50()
  15. {
  16. $this->getPriority()->shouldReturn(50);
  17. }
  18. function it_supports_ReflectionClass_only(ClassNode $reflectionClassNode, ClassNode $anotherClassNode)
  19. {
  20. $reflectionClassNode->getParentClass()->willReturn('ReflectionClass');
  21. $anotherClassNode->getParentClass()->willReturn('stdClass');
  22. $this->supports($reflectionClassNode)->shouldReturn(true);
  23. $this->supports($anotherClassNode)->shouldReturn(false);
  24. }
  25. function it_makes_all_newInstance_arguments_optional(
  26. ClassNode $class,
  27. MethodNode $method,
  28. ArgumentNode $arg1
  29. ) {
  30. $class->getMethod('newInstance')->willReturn($method);
  31. $method->getArguments()->willReturn(array($arg1));
  32. $arg1->setDefault(null)->shouldBeCalled();
  33. $this->apply($class);
  34. }
  35. }