No Description

SplFileInfoPatchSpec.php 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace spec\Prophecy\Doubler\ClassPatch;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. class SplFileInfoPatchSpec extends ObjectBehavior
  6. {
  7. function it_is_a_patch()
  8. {
  9. $this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
  10. }
  11. function its_priority_is_50()
  12. {
  13. $this->getPriority()->shouldReturn(50);
  14. }
  15. /**
  16. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  17. */
  18. function it_does_not_support_nodes_without_parent_class($node)
  19. {
  20. $node->getParentClass()->willReturn('stdClass');
  21. $this->supports($node)->shouldReturn(false);
  22. }
  23. /**
  24. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  25. */
  26. function it_supports_nodes_with_SplFileInfo_as_parent_class($node)
  27. {
  28. $node->getParentClass()->willReturn('SplFileInfo');
  29. $this->supports($node)->shouldReturn(true);
  30. }
  31. /**
  32. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  33. */
  34. function it_supports_nodes_with_derivative_of_SplFileInfo_as_parent_class($node)
  35. {
  36. $node->getParentClass()->willReturn('SplFileInfo');
  37. $this->supports($node)->shouldReturn(true);
  38. }
  39. /**
  40. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  41. */
  42. function it_adds_a_method_to_node_if_not_exists($node)
  43. {
  44. $node->hasMethod('__construct')->willReturn(false);
  45. $node->addMethod(Argument::any())->shouldBeCalled();
  46. $node->getParentClass()->shouldBeCalled();
  47. $this->apply($node);
  48. }
  49. /**
  50. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  51. * @param \Prophecy\Doubler\Generator\Node\MethodNode $method
  52. */
  53. function it_updates_existing_method_if_found($node, $method)
  54. {
  55. $node->hasMethod('__construct')->willReturn(true);
  56. $node->getMethod('__construct')->willReturn($method);
  57. $node->getParentClass()->shouldBeCalled();
  58. $method->useParentCode()->shouldBeCalled();
  59. $this->apply($node);
  60. }
  61. /**
  62. * @param \Prophecy\Doubler\Generator\Node\ClassNode $node
  63. * @param \Prophecy\Doubler\Generator\Node\MethodNode $method
  64. */
  65. function it_should_not_supply_a_file_for_a_directory_iterator($node, $method)
  66. {
  67. $node->hasMethod('__construct')->willReturn(true);
  68. $node->getMethod('__construct')->willReturn($method);
  69. $node->getParentClass()->willReturn('DirectoryIterator');
  70. $method->setCode(Argument::that(function($value) {
  71. return strpos($value, '.php') === false;
  72. }))->shouldBeCalled();
  73. $this->apply($node);
  74. }
  75. }