TraversablePatchSpec.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace spec\Prophecy\Doubler\ClassPatch;
  3. use PhpSpec\ObjectBehavior;
  4. use Prophecy\Argument;
  5. use Prophecy\Doubler\Generator\Node\ClassNode;
  6. class TraversablePatchSpec extends ObjectBehavior
  7. {
  8. function it_is_a_patch()
  9. {
  10. $this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
  11. }
  12. function it_supports_class_that_implements_only_Traversable(ClassNode $node)
  13. {
  14. $node->getInterfaces()->willReturn(array('Traversable'));
  15. $this->supports($node)->shouldReturn(true);
  16. }
  17. function it_does_not_support_class_that_implements_Iterator(ClassNode $node)
  18. {
  19. $node->getInterfaces()->willReturn(array('Traversable', 'Iterator'));
  20. $this->supports($node)->shouldReturn(false);
  21. }
  22. function it_does_not_support_class_that_implements_IteratorAggregate(ClassNode $node)
  23. {
  24. $node->getInterfaces()->willReturn(array('Traversable', 'IteratorAggregate'));
  25. $this->supports($node)->shouldReturn(false);
  26. }
  27. function it_has_100_priority()
  28. {
  29. $this->getPriority()->shouldReturn(100);
  30. }
  31. function it_forces_node_to_implement_IteratorAggregate(ClassNode $node)
  32. {
  33. $node->addInterface('Iterator')->shouldBeCalled();
  34. $node->addMethod(Argument::type('Prophecy\Doubler\Generator\Node\MethodNode'))->willReturn(null);
  35. $this->apply($node);
  36. }
  37. }