No Description

MagicCallPatchSpec.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. /**
  47. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  48. */
  49. function it_discovers_api_using_phpdoc_from_own_interfaces($node)
  50. {
  51. $node->getParentClass()->willReturn('stdClass');
  52. $node->getInterfaces()->willReturn(array('spec\Prophecy\Doubler\ClassPatch\MagicalApiImplemented'));
  53. $node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
  54. $this->apply($node);
  55. }
  56. /**
  57. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  58. */
  59. function it_discovers_api_using_phpdoc_from_extended_parent_interfaces($node)
  60. {
  61. $node->getParentClass()->willReturn('spec\Prophecy\Doubler\ClassPatch\MagicalApiImplementedExtended');
  62. $node->getInterfaces()->willReturn(array());
  63. $node->addMethod(new MethodNode('implementedMethod'))->shouldBeCalled();
  64. $this->apply($node);
  65. }
  66. function it_has_50_priority()
  67. {
  68. $this->getPriority()->shouldReturn(50);
  69. }
  70. }
  71. /**
  72. * @method void undefinedMethod()
  73. */
  74. class MagicalApi
  75. {
  76. /**
  77. * @return void
  78. */
  79. public function definedMethod()
  80. {
  81. }
  82. }
  83. /**
  84. * @method void invalidMethodDefinition
  85. * @method void
  86. * @method
  87. */
  88. class MagicalApiInvalidMethodDefinition
  89. {
  90. }
  91. /**
  92. * @method void undefinedMethod()
  93. * @method void definedMethod()
  94. */
  95. class MagicalApiExtended extends MagicalApi
  96. {
  97. }
  98. /**
  99. */
  100. class MagicalApiImplemented implements MagicalApiInterface
  101. {
  102. }
  103. /**
  104. */
  105. class MagicalApiImplementedExtended extends MagicalApiImplemented
  106. {
  107. }
  108. /**
  109. * @method void implementedMethod()
  110. */
  111. interface MagicalApiInterface
  112. {
  113. }