No Description

ProphecySubjectPatchSpec.php 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace spec\Prophecy\Doubler\ClassPatch;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. class ProphecySubjectPatchSpec extends ObjectBehavior
  6. {
  7. function it_is_a_patch()
  8. {
  9. $this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
  10. }
  11. function it_has_priority_of_0()
  12. {
  13. $this->getPriority()->shouldReturn(0);
  14. }
  15. /**
  16. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  17. */
  18. function it_supports_any_class($node)
  19. {
  20. $this->supports($node)->shouldReturn(true);
  21. }
  22. /**
  23. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  24. */
  25. function it_forces_class_to_implement_ProphecySubjectInterface($node)
  26. {
  27. $node->addInterface('Prophecy\Prophecy\ProphecySubjectInterface')->shouldBeCalled();
  28. $node->addProperty('objectProphecy', 'private')->willReturn(null);
  29. $node->getMethods()->willReturn(array());
  30. $node->hasMethod(Argument::any())->willReturn(false);
  31. $node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
  32. $node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
  33. $this->apply($node);
  34. }
  35. /**
  36. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  37. * @param \Prophecy\Doubler\Generator\Node\MethodNode $constructor
  38. * @param \Prophecy\Doubler\Generator\Node\MethodNode $method1
  39. * @param \Prophecy\Doubler\Generator\Node\MethodNode $method2
  40. * @param \Prophecy\Doubler\Generator\Node\MethodNode $method3
  41. */
  42. function it_forces_all_class_methods_except_constructor_to_proxy_calls_into_prophecy_makeCall(
  43. $node, $constructor, $method1, $method2, $method3
  44. )
  45. {
  46. $node->addInterface('Prophecy\Prophecy\ProphecySubjectInterface')->willReturn(null);
  47. $node->addProperty('objectProphecy', 'private')->willReturn(null);
  48. $node->hasMethod(Argument::any())->willReturn(false);
  49. $node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
  50. $node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
  51. $constructor->getName()->willReturn('__construct');
  52. $method1->getName()->willReturn('method1');
  53. $method2->getName()->willReturn('method2');
  54. $method3->getName()->willReturn('method3');
  55. $node->getMethods()->willReturn(array(
  56. 'method1' => $method1,
  57. 'method2' => $method2,
  58. 'method3' => $method3,
  59. ));
  60. $constructor->setCode(Argument::any())->shouldNotBeCalled();
  61. $method1->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
  62. ->shouldBeCalled();
  63. $method2->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
  64. ->shouldBeCalled();
  65. $method3->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
  66. ->shouldBeCalled();
  67. $this->apply($node);
  68. }
  69. }