MagicCallPatchSpec.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 MagicCallPatchSpec extends ObjectBehavior
  8. {
  9. function it_is_a_patch()
  10. {
  11. $this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
  12. }
  13. function it_supports_anything(ClassNode $node)
  14. {
  15. $this->supports($node)->shouldReturn(true);
  16. }
  17. function it_discovers_api_using_phpdoc(ClassNode $node)
  18. {
  19. $node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApi');
  20. $node->getInterfaces()->willReturn(array());
  21. $node->addMethod(new MethodNode('undefinedMethod'))->shouldBeCalled();
  22. $this->apply($node);
  23. }
  24. function it_ignores_existing_methods(ClassNode $node)
  25. {
  26. $node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiExtended');
  27. $node->getInterfaces()->willReturn(array());
  28. $node->addMethod(new MethodNode('undefinedMethod'))->shouldBeCalled();
  29. $node->addMethod(new MethodNode('definedMethod'))->shouldNotBeCalled();
  30. $this->apply($node);
  31. }
  32. function it_ignores_empty_methods_from_phpdoc(ClassNode $node)
  33. {
  34. $node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiInvalidMethodDefinition');
  35. $node->getInterfaces()->willReturn(array());
  36. $node->addMethod(new MethodNode(''))->shouldNotBeCalled();
  37. $this->apply($node);
  38. }
  39. function it_discovers_api_using_phpdoc_from_implemented_interfaces(ClassNode $node)
  40. {
  41. $node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiImplemented');
  42. $node->getInterfaces()->willReturn(array());
  43. $node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
  44. $this->apply($node);
  45. }
  46. function it_discovers_api_using_phpdoc_from_own_interfaces(ClassNode $node)
  47. {
  48. $node->getParentClass()->willReturn('stdClass');
  49. $node->getInterfaces()->willReturn(array('spec\Prophecy\Doubler\ClassPatch\MagicalApiImplemented'));
  50. $node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
  51. $this->apply($node);
  52. }
  53. function it_discovers_api_using_phpdoc_from_extended_parent_interfaces(ClassNode $node)
  54. {
  55. $node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiImplementedExtended');
  56. $node->getInterfaces()->willReturn(array());
  57. $node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
  58. $this->apply($node);
  59. }
  60. function it_has_50_priority()
  61. {
  62. $this->getPriority()->shouldReturn(50);
  63. }
  64. }
  65. /**
  66. * @method void undefinedMethod()
  67. */
  68. class MagicalApi
  69. {
  70. /**
  71. * @return void
  72. */
  73. public function definedMethod()
  74. {
  75. }
  76. }
  77. /**
  78. * @method void invalidMethodDefinition
  79. * @method void
  80. * @method
  81. */
  82. class MagicalApiInvalidMethodDefinition
  83. {
  84. }
  85. /**
  86. * @method void undefinedMethod()
  87. * @method void definedMethod()
  88. */
  89. class MagicalApiExtended extends MagicalApi
  90. {
  91. }
  92. /**
  93. */
  94. class MagicalApiImplemented implements MagicalApiInterface
  95. {
  96. }
  97. /**
  98. */
  99. class MagicalApiImplementedExtended extends MagicalApiImplemented
  100. {
  101. }
  102. /**
  103. * @method void implementedMethod()
  104. */
  105. interface MagicalApiInterface
  106. {
  107. }