SplFileInfoPatchSpec.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 SplFileInfoPatchSpec extends ObjectBehavior
  8. {
  9. function it_is_a_patch()
  10. {
  11. $this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
  12. }
  13. function its_priority_is_50()
  14. {
  15. $this->getPriority()->shouldReturn(50);
  16. }
  17. function it_does_not_support_nodes_without_parent_class(ClassNode $node)
  18. {
  19. $node->getParentClass()->willReturn('stdClass');
  20. $this->supports($node)->shouldReturn(false);
  21. }
  22. function it_supports_nodes_with_SplFileInfo_as_parent_class(ClassNode $node)
  23. {
  24. $node->getParentClass()->willReturn('SplFileInfo');
  25. $this->supports($node)->shouldReturn(true);
  26. }
  27. function it_supports_nodes_with_derivative_of_SplFileInfo_as_parent_class(ClassNode $node)
  28. {
  29. $node->getParentClass()->willReturn('SplFileInfo');
  30. $this->supports($node)->shouldReturn(true);
  31. }
  32. function it_adds_a_method_to_node_if_not_exists(ClassNode $node)
  33. {
  34. $node->hasMethod('__construct')->willReturn(false);
  35. $node->addMethod(Argument::any())->shouldBeCalled();
  36. $node->getParentClass()->shouldBeCalled();
  37. $this->apply($node);
  38. }
  39. function it_updates_existing_method_if_found(ClassNode $node, MethodNode $method)
  40. {
  41. $node->hasMethod('__construct')->willReturn(true);
  42. $node->getMethod('__construct')->willReturn($method);
  43. $node->getParentClass()->shouldBeCalled();
  44. $method->useParentCode()->shouldBeCalled();
  45. $this->apply($node);
  46. }
  47. function it_should_not_supply_a_file_for_a_directory_iterator(ClassNode $node, MethodNode $method)
  48. {
  49. $node->hasMethod('__construct')->willReturn(true);
  50. $node->getMethod('__construct')->willReturn($method);
  51. $node->getParentClass()->willReturn('DirectoryIterator');
  52. $method->setCode(Argument::that(function($value) {
  53. return strpos($value, '.php') === false;
  54. }))->shouldBeCalled();
  55. $this->apply($node);
  56. }
  57. function it_should_supply_a_file_for_a_spl_file_object(ClassNode $node, MethodNode $method)
  58. {
  59. $node->hasMethod('__construct')->willReturn(true);
  60. $node->getMethod('__construct')->willReturn($method);
  61. $node->getParentClass()->willReturn('SplFileObject');
  62. $method->setCode(Argument::that(function($value) {
  63. return strpos($value, '.php') !== false;
  64. }))->shouldBeCalled();
  65. $this->apply($node);
  66. }
  67. }