No Description

DisableConstructorPatchSpec.php 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace spec\Prophecy\Doubler\ClassPatch;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. class DisableConstructorPatchSpec extends ObjectBehavior
  6. {
  7. function it_is_a_patch()
  8. {
  9. $this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
  10. }
  11. function its_priority_is_100()
  12. {
  13. $this->getPriority()->shouldReturn(100);
  14. }
  15. /**
  16. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  17. */
  18. function it_supports_anything($node)
  19. {
  20. $this->supports($node)->shouldReturn(true);
  21. }
  22. /**
  23. * @param \Prophecy\Doubler\Generator\Node\ClassNode $class
  24. * @param \Prophecy\Doubler\Generator\Node\MethodNode $method
  25. * @param \Prophecy\Doubler\Generator\Node\ArgumentNode $arg1
  26. * @param \Prophecy\Doubler\Generator\Node\ArgumentNode $arg2
  27. */
  28. function it_makes_all_constructor_arguments_optional($class, $method, $arg1, $arg2)
  29. {
  30. $class->hasMethod('__construct')->willReturn(true);
  31. $class->getMethod('__construct')->willReturn($method);
  32. $method->getArguments()->willReturn(array($arg1, $arg2));
  33. $arg1->setDefault(null)->shouldBeCalled();
  34. $arg2->setDefault(null)->shouldBeCalled();
  35. $method->setCode(Argument::type('string'))->shouldBeCalled();
  36. $this->apply($class);
  37. }
  38. /**
  39. * @param \Prophecy\Doubler\Generator\Node\ClassNode $class
  40. */
  41. function it_creates_new_constructor_if_object_has_none($class)
  42. {
  43. $class->hasMethod('__construct')->willReturn(false);
  44. $class->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))
  45. ->shouldBeCalled();
  46. $this->apply($class);
  47. }
  48. }