@@ -21,7 +21,7 @@ function it_registers_a_class()
21
21
{
22
22
$ this ->reset ();
23
23
24
- $ this ->register ('class1 ' , ' spec\Http\Discovery\AnotherClassToFind ' );
24
+ $ this ->register ('spec\Http\Discovery\AnotherClassToFind ' );
25
25
26
26
$ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
27
27
}
@@ -30,8 +30,8 @@ function it_registers_a_class_with_a_condition()
30
30
{
31
31
$ this ->reset ();
32
32
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 );
35
35
36
36
$ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
37
37
}
@@ -40,8 +40,8 @@ function it_registers_a_class_with_a_callable_condition()
40
40
{
41
41
$ this ->reset ();
42
42
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 );
45
45
46
46
$ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
47
47
}
@@ -50,8 +50,8 @@ function it_registers_a_class_with_a_boolean_condition()
50
50
{
51
51
$ this ->reset ();
52
52
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 );
55
55
56
56
$ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
57
57
}
@@ -60,8 +60,8 @@ function it_registers_a_class_with_an_invalid_condition()
60
60
{
61
61
$ this ->reset ();
62
62
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 );
65
65
66
66
$ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
67
67
}
@@ -72,7 +72,7 @@ function it_resets_cache_when_a_class_is_registered()
72
72
73
73
$ this ->find ()->shouldHaveType ('spec\Http\Discovery\ClassToFind ' );
74
74
75
- $ this ->register ('class1 ' , ' spec\Http\Discovery\AnotherClassToFind ' );
75
+ $ this ->register ('spec\Http\Discovery\AnotherClassToFind ' );
76
76
77
77
$ this ->find ()->shouldHaveType ('spec\Http\Discovery\AnotherClassToFind ' );
78
78
}
@@ -83,16 +83,14 @@ function it_caches_a_found_class()
83
83
84
84
$ this ->find ()->shouldHaveType ('spec\Http\Discovery\ClassToFind ' );
85
85
86
- $ this ->registerWithoutCacheReset ('class1 ' , ' spec\Http\Discovery\AnotherClassToFind ' );
86
+ $ this ->registerWithoutCacheReset ('spec\Http\Discovery\AnotherClassToFind ' );
87
87
88
88
$ this ->find ()->shouldhaveType ('spec\Http\Discovery\ClassToFind ' );
89
89
}
90
90
91
91
function it_throws_an_exception_when_no_class_is_found ()
92
92
{
93
- $ this ->reset ();
94
-
95
- $ this ->register ('class1 ' , 'invalid ' );
93
+ $ this ->resetEmpty ();
96
94
97
95
$ this ->shouldThrow ('Http\Discovery\NotFoundException ' )->duringFind ();
98
96
}
@@ -115,19 +113,28 @@ public function reset()
115
113
static ::$ cache = null ;
116
114
117
115
static ::$ classes = [
118
- ' class1 ' => [
116
+ [
119
117
'class ' => 'spec\Http\Discovery\ClassToFind ' ,
120
118
'condition ' => 'spec\Http\Discovery\ClassToFind '
121
119
],
122
120
];
123
121
}
124
122
125
- public function registerWithoutCacheReset ($ name , $ class , $ condition = null )
123
+ public function registerWithoutCacheReset ($ class , $ condition = null )
126
124
{
127
- static :: $ classes [ $ name ] = [
125
+ $ definition = [
128
126
'class ' => $ class ,
129
- 'condition ' => $ condition ? : $ class ,
127
+ 'condition ' => isset ( $ condition) ? $ condition : $ class ,
130
128
];
129
+
130
+ array_unshift (static ::$ classes , $ definition );
131
+ }
132
+
133
+ public function resetEmpty ()
134
+ {
135
+ static ::$ cache = null ;
136
+
137
+ static ::$ classes = [];
131
138
}
132
139
}
133
140
0 commit comments