KeywordPatchSpec.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace spec\Prophecy\Doubler\ClassPatch;
  3. use PhpSpec\Exception\Example\SkippingException;
  4. use PhpSpec\ObjectBehavior;
  5. use Prophecy\Argument;
  6. use Prophecy\Doubler\Generator\Node\ClassNode;
  7. use Prophecy\Doubler\Generator\Node\MethodNode;
  8. class KeywordPatchSpec extends ObjectBehavior
  9. {
  10. function it_is_a_patch()
  11. {
  12. $this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
  13. }
  14. function its_priority_is_49()
  15. {
  16. $this->getPriority()->shouldReturn(49);
  17. }
  18. function it_will_remove_echo_and_eval_methods(
  19. ClassNode $node,
  20. MethodNode $method1,
  21. MethodNode $method2,
  22. MethodNode $method3
  23. ) {
  24. if (\PHP_VERSION_ID >= 70000) {
  25. throw new SkippingException('Reserved keywords list in PHP 7 does not include most of PHP 5.6 keywords');
  26. }
  27. $node->removeMethod('eval')->shouldBeCalled();
  28. $node->removeMethod('echo')->shouldBeCalled();
  29. $method1->getName()->willReturn('echo');
  30. $method2->getName()->willReturn('eval');
  31. $method3->getName()->willReturn('notKeyword');
  32. $node->getMethods()->willReturn(array(
  33. 'echo' => $method1,
  34. 'eval' => $method2,
  35. 'notKeyword' => $method3,
  36. ));
  37. $this->apply($node);
  38. }
  39. function it_will_remove_halt_compiler_method(
  40. ClassNode $node,
  41. MethodNode $method1,
  42. MethodNode $method2,
  43. MethodNode $method3
  44. ) {
  45. if (\PHP_VERSION_ID < 70000) {
  46. throw new SkippingException('Reserved keywords list in PHP 7 does not include most of PHP 5.6 keywords');
  47. }
  48. $node->removeMethod('__halt_compiler')->shouldBeCalled();
  49. $method1->getName()->willReturn('__halt_compiler');
  50. $method2->getName()->willReturn('echo');
  51. $method3->getName()->willReturn('notKeyword');
  52. $node->getMethods()->willReturn(array(
  53. '__halt_compiler' => $method1,
  54. 'echo' => $method2,
  55. 'notKeyword' => $method3,
  56. ));
  57. $this->apply($node);
  58. }
  59. }