DisableConstructorPatchSpec.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 DisableConstructorPatchSpec extends ObjectBehavior
  9. {
  10. function it_is_a_patch()
  11. {
  12. $this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
  13. }
  14. function its_priority_is_100()
  15. {
  16. $this->getPriority()->shouldReturn(100);
  17. }
  18. function it_supports_anything(ClassNode $node)
  19. {
  20. $this->supports($node)->shouldReturn(true);
  21. }
  22. function it_makes_all_constructor_arguments_optional(
  23. ClassNode $class,
  24. MethodNode $method,
  25. ArgumentNode $arg1,
  26. ArgumentNode $arg2
  27. ) {
  28. $class->hasMethod('__construct')->willReturn(true);
  29. $class->getMethod('__construct')->willReturn($method);
  30. $method->getArguments()->willReturn(array($arg1, $arg2));
  31. $arg1->setDefault(null)->shouldBeCalled();
  32. $arg2->setDefault(null)->shouldBeCalled();
  33. $method->setCode(Argument::type('string'))->shouldBeCalled();
  34. $this->apply($class);
  35. }
  36. function it_creates_new_constructor_if_object_has_none(ClassNode $class)
  37. {
  38. $class->hasMethod('__construct')->willReturn(false);
  39. $class->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))
  40. ->shouldBeCalled();
  41. $this->apply($class);
  42. }
  43. }