No Description

ProphecySubjectPatchSpec.php 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. $node->getMethods()->willReturn(array(
  48. 'method1' => $method1,
  49. 'method2' => $method2,
  50. 'method3' => $method3,
  51. ));
  52. $constructor->setCode(Argument::any())->shouldNotBeCalled();
  53. $method1->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
  54. ->shouldBeCalled();
  55. $method2->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
  56. ->shouldBeCalled();
  57. $method3->setCode('return $this->getProphecy()->makeProphecyMethodCall(__FUNCTION__, func_get_args());')
  58. ->shouldBeCalled();
  59. $this->apply($node);
  60. }
  61. }