annotate vendor/phpspec/prophecy/spec/Prophecy/Doubler/ClassPatch/SplFileInfoPatchSpec.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace spec\Prophecy\Doubler\ClassPatch;
Chris@0 4
Chris@0 5 use PhpSpec\ObjectBehavior;
Chris@0 6 use Prophecy\Argument;
Chris@0 7 use Prophecy\Doubler\Generator\Node\ClassNode;
Chris@0 8 use Prophecy\Doubler\Generator\Node\MethodNode;
Chris@0 9
Chris@0 10 class SplFileInfoPatchSpec extends ObjectBehavior
Chris@0 11 {
Chris@0 12 function it_is_a_patch()
Chris@0 13 {
Chris@0 14 $this->shouldBeAnInstanceOf('Prophecy\Doubler\ClassPatch\ClassPatchInterface');
Chris@0 15 }
Chris@0 16
Chris@0 17 function its_priority_is_50()
Chris@0 18 {
Chris@0 19 $this->getPriority()->shouldReturn(50);
Chris@0 20 }
Chris@0 21
Chris@0 22 function it_does_not_support_nodes_without_parent_class(ClassNode $node)
Chris@0 23 {
Chris@0 24 $node->getParentClass()->willReturn('stdClass');
Chris@0 25 $this->supports($node)->shouldReturn(false);
Chris@0 26 }
Chris@0 27
Chris@0 28 function it_supports_nodes_with_SplFileInfo_as_parent_class(ClassNode $node)
Chris@0 29 {
Chris@0 30 $node->getParentClass()->willReturn('SplFileInfo');
Chris@0 31 $this->supports($node)->shouldReturn(true);
Chris@0 32 }
Chris@0 33
Chris@0 34 function it_supports_nodes_with_derivative_of_SplFileInfo_as_parent_class(ClassNode $node)
Chris@0 35 {
Chris@0 36 $node->getParentClass()->willReturn('SplFileInfo');
Chris@0 37 $this->supports($node)->shouldReturn(true);
Chris@0 38 }
Chris@0 39
Chris@0 40 function it_adds_a_method_to_node_if_not_exists(ClassNode $node)
Chris@0 41 {
Chris@0 42 $node->hasMethod('__construct')->willReturn(false);
Chris@0 43 $node->addMethod(Argument::any())->shouldBeCalled();
Chris@0 44 $node->getParentClass()->shouldBeCalled();
Chris@0 45
Chris@0 46 $this->apply($node);
Chris@0 47 }
Chris@0 48
Chris@0 49 function it_updates_existing_method_if_found(ClassNode $node, MethodNode $method)
Chris@0 50 {
Chris@0 51 $node->hasMethod('__construct')->willReturn(true);
Chris@0 52 $node->getMethod('__construct')->willReturn($method);
Chris@0 53 $node->getParentClass()->shouldBeCalled();
Chris@0 54
Chris@0 55 $method->useParentCode()->shouldBeCalled();
Chris@0 56
Chris@0 57 $this->apply($node);
Chris@0 58 }
Chris@0 59
Chris@0 60 function it_should_not_supply_a_file_for_a_directory_iterator(ClassNode $node, MethodNode $method)
Chris@0 61 {
Chris@0 62 $node->hasMethod('__construct')->willReturn(true);
Chris@0 63 $node->getMethod('__construct')->willReturn($method);
Chris@0 64 $node->getParentClass()->willReturn('DirectoryIterator');
Chris@0 65
Chris@0 66 $method->setCode(Argument::that(function($value) {
Chris@0 67 return strpos($value, '.php') === false;
Chris@0 68 }))->shouldBeCalled();
Chris@0 69
Chris@0 70 $this->apply($node);
Chris@0 71 }
Chris@0 72
Chris@0 73 function it_should_supply_a_file_for_a_spl_file_object(ClassNode $node, MethodNode $method)
Chris@0 74 {
Chris@0 75 $node->hasMethod('__construct')->willReturn(true);
Chris@0 76 $node->getMethod('__construct')->willReturn($method);
Chris@0 77 $node->getParentClass()->willReturn('SplFileObject');
Chris@0 78
Chris@0 79 $method->setCode(Argument::that(function($value) {
Chris@0 80 return strpos($value, '.php') !== false;
Chris@0 81 }))->shouldBeCalled();
Chris@0 82
Chris@0 83 $this->apply($node);
Chris@0 84 }
Chris@0 85 }