@@ -21,7 +21,7 @@ function it_registers_a_class()
2121 {
2222 $ this ->reset ();
2323
24- $ this ->register ('class1 ' , ' spec\Http\Discovery\AnotherClassToFind ' );
24+ $ this ->register ('spec\Http\Discovery\AnotherClassToFind ' );
2525
2626 $ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
2727 }
@@ -30,8 +30,8 @@ function it_registers_a_class_with_a_condition()
3030 {
3131 $ this ->reset ();
3232
33- $ this ->register ('class1 ' , 'spec\Http\Discovery\ClassToFind ' , false );
34- $ this ->register ('class2 ' , ' spec\Http\Discovery\AnotherClassToFind ' , ' spec\Http\Discovery\TestClass ' );
33+ $ this ->register ('spec\Http\Discovery\AnotherClassToFind ' , 'spec\Http\Discovery\TestClass ' );
34+ $ this ->register ('spec\Http\Discovery\ClassToFind ' , false );
3535
3636 $ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
3737 }
@@ -40,8 +40,8 @@ function it_registers_a_class_with_a_callable_condition()
4040 {
4141 $ this ->reset ();
4242
43- $ this ->register ('class1 ' , ' spec\Http\Discovery\ClassToFind ' , false );
44- $ this ->register ('class2 ' , ' spec\Http\Discovery\AnotherClassToFind ' , function () { return true ; } );
43+ $ this ->register ('spec\Http\Discovery\AnotherClassToFind ' , function () { return true ; } );
44+ $ this ->register ('spec\Http\Discovery\ClassToFind ' , false );
4545
4646 $ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
4747 }
@@ -50,8 +50,8 @@ function it_registers_a_class_with_a_boolean_condition()
5050 {
5151 $ this ->reset ();
5252
53- $ this ->register ('class1 ' , ' spec\Http\Discovery\ClassToFind ' , false );
54- $ this ->register ('class2 ' , ' spec\Http\Discovery\AnotherClassToFind ' , true );
53+ $ this ->register ('spec\Http\Discovery\AnotherClassToFind ' , true );
54+ $ this ->register ('spec\Http\Discovery\ClassToFind ' , false );
5555
5656 $ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
5757 }
@@ -60,8 +60,8 @@ function it_registers_a_class_with_an_invalid_condition()
6060 {
6161 $ this ->reset ();
6262
63- $ this ->register ('class1 ' , ' spec\Http\Discovery\ClassToFind ' , new \ stdClass );
64- $ this ->register ('class2 ' , ' spec\Http\Discovery\AnotherClassToFind ' , true );
63+ $ this ->register ('spec\Http\Discovery\AnotherClassToFind ' , true );
64+ $ this ->register ('spec\Http\Discovery\ClassToFind ' , new \ stdClass );
6565
6666 $ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
6767 }
@@ -72,7 +72,7 @@ function it_resets_cache_when_a_class_is_registered()
7272
7373 $ this ->find ()->shouldHaveType ('spec\Http\Discovery\ClassToFind ' );
7474
75- $ this ->register ('class1 ' , ' spec\Http\Discovery\AnotherClassToFind ' );
75+ $ this ->register ('spec\Http\Discovery\AnotherClassToFind ' );
7676
7777 $ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
7878 }
@@ -83,16 +83,14 @@ function it_caches_a_found_class()
8383
8484 $ this ->find ()->shouldHaveType ('spec\Http\Discovery\ClassToFind ' );
8585
86- $ this ->registerWithoutCacheReset ('class1 ' , ' spec\Http\Discovery\AnotherClassToFind ' );
86+ $ this ->registerWithoutCacheReset ('spec\Http\Discovery\AnotherClassToFind ' );
8787
8888 $ this ->find ()->shouldhaveType ('spec\Http\Discovery\ClassToFind ' );
8989 }
9090
9191 function it_throws_an_exception_when_no_class_is_found ()
9292 {
93- $ this ->reset ();
94-
95- $ this ->register ('class1 ' , 'invalid ' );
93+ $ this ->resetEmpty ();
9694
9795 $ this ->shouldThrow ('Http\Discovery\NotFoundException ' )->duringFind ();
9896 }
@@ -115,19 +113,28 @@ public function reset()
115113 static ::$ cache = null ;
116114
117115 static ::$ classes = [
118- ' class1 ' => [
116+ [
119117 'class ' => 'spec\Http\Discovery\ClassToFind ' ,
120118 'condition ' => 'spec\Http\Discovery\ClassToFind '
121119 ],
122120 ];
123121 }
124122
125- public function registerWithoutCacheReset ($ name , $ class , $ condition = null )
123+ public function registerWithoutCacheReset ($ class , $ condition = null )
126124 {
127- static :: $ classes [ $ name ] = [
125+ $ definition = [
128126 'class ' => $ class ,
129- 'condition ' => $ condition ? : $ class ,
127+ 'condition ' => isset ( $ condition) ? $ condition : $ class ,
130128 ];
129+
130+ array_unshift (static ::$ classes , $ definition );
131+ }
132+
133+ public function resetEmpty ()
134+ {
135+ static ::$ cache = null ;
136+
137+ static ::$ classes = [];
131138 }
132139}
133140
0 commit comments