ProphecySubjectPatchSpec.php 2.9 KB

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