22
33namespace spec \EcomDev \PHPSpec \MagentoDiAdapter \Runner ;
44
5- use PhpSpec \Loader \Node \ExampleNode ;
5+ use EcomDev \PHPSpec \MagentoDiAdapter \ParameterValidator ;
6+ use PhpSpec \Loader \Node \SpecificationNode ;
67use PhpSpec \ObjectBehavior ;
8+ use PhpSpec \Loader \Node \ExampleNode ;
79use PhpSpec \Runner \Maintainer \MaintainerInterface ;
10+ use PhpSpec \Runner \CollaboratorManager ;
11+ use PhpSpec \Runner \MatcherManager ;
12+ use PhpSpec \SpecificationInterface ;
813use Prophecy \Argument ;
914
1015class CollaboratorMaintainerSpec extends ObjectBehavior
1116{
17+ /**
18+ * Parameter validator
19+ *
20+ * @var ParameterValidator
21+ */
22+ private $ parameterValidator ;
23+
24+ function let (ParameterValidator $ parameterValidator )
25+ {
26+ $ this ->parameterValidator = $ parameterValidator ;
27+ $ this ->beConstructedWith ($ this ->parameterValidator );
28+ }
29+
1230 function it_should_implement_maintainer_interface ()
1331 {
1432 $ this ->shouldImplement (MaintainerInterface::class);
@@ -23,4 +41,62 @@ function it_has_higher_priority_than_current_collaborator_maintainer()
2341 {
2442 $ this ->getPriority ()->shouldReturn (49 );
2543 }
44+
45+
46+ function it_does_pass_regular_example_into_parameter_validator (
47+ ExampleNode $ example ,
48+ SpecificationInterface $ context ,
49+ MatcherManager $ matchers ,
50+ CollaboratorManager $ collaborators ,
51+ SpecificationNode $ specificationNode ,
52+ \ReflectionClass $ reflectionClass
53+ )
54+ {
55+
56+ $ example ->getSpecification ()->willReturn ($ specificationNode );
57+ $ specificationNode ->getClassReflection ()->willReturn ($ reflectionClass );
58+ $ reflectionClass ->hasMethod ('let ' )->willReturn (false );
59+
60+ $ exampleClosureReflection = new \ReflectionFunction (function () {});
61+ $ example ->getFunctionReflection ()->willReturn ($ exampleClosureReflection )->shouldBeCalled ();
62+ $ this ->parameterValidator ->validate ($ exampleClosureReflection )->shouldBeCalled ();
63+
64+ $ this ->prepare ($ example , $ context , $ matchers , $ collaborators )->shouldReturn ($ this );
65+ }
66+
67+ function it_does_pass_regular_example_into_parameter_validator_and_let_method_if_they_are_defined (
68+ ExampleNode $ example ,
69+ SpecificationInterface $ context ,
70+ MatcherManager $ matchers ,
71+ CollaboratorManager $ collaborators ,
72+ SpecificationNode $ specificationNode ,
73+ \ReflectionClass $ reflectionClass
74+ )
75+ {
76+ $ example ->getSpecification ()->willReturn ($ specificationNode );
77+ $ specificationNode ->getClassReflection ()->willReturn ($ reflectionClass );
78+ $ reflectionClass ->hasMethod ('let ' )->willReturn (true );
79+
80+ $ exampleClosureReflection = new \ReflectionFunction (function () {});
81+ $ letClosureReflection = new \ReflectionFunction (function () {});
82+ $ reflectionClass ->getMethod ('let ' )->willReturn ($ letClosureReflection )->shouldBeCalled ();
83+ $ example ->getFunctionReflection ()->willReturn ($ exampleClosureReflection )->shouldBeCalled ();
84+
85+ $ this ->parameterValidator ->validate ($ letClosureReflection )->shouldBeCalled ();
86+ $ this ->parameterValidator ->validate ($ exampleClosureReflection )->shouldBeCalled ();
87+
88+ $ this ->prepare ($ example , $ context , $ matchers , $ collaborators )->shouldReturn ($ this );
89+ }
90+
91+
92+
93+ function it_does_not_have_anything_to_cleanup_on_teardown (
94+ ExampleNode $ example ,
95+ SpecificationInterface $ context ,
96+ MatcherManager $ matchers ,
97+ CollaboratorManager $ collaborators
98+ )
99+ {
100+ $ this ->teardown ($ example , $ context , $ matchers , $ collaborators )->shouldReturn ($ this );
101+ }
26102}
0 commit comments