@@ -104,4 +104,155 @@ public function it_returns_controllers()
104
104
$ this ->assertCount (1 , $ methods ['index ' ]);
105
105
$ this ->assertEquals ('index-statement-1 ' , $ methods ['index ' ][0 ]);
106
106
}
107
+
108
+ /**
109
+ * @test
110
+ */
111
+ public function it_returns_a_resource_controller ()
112
+ {
113
+ $ tokens = [
114
+ 'controllers ' => [
115
+ 'Comment ' => [
116
+ 'resource ' => 'all '
117
+ ]
118
+ ]
119
+ ];
120
+
121
+ $ this ->statementLexer ->shouldReceive ('analyze ' )
122
+ ->with ([
123
+ 'query ' => 'all:comments ' ,
124
+ 'render ' => 'comment.index with comments '
125
+ ])
126
+ ->andReturn (['index-statements ' ]);
127
+
128
+ $ this ->statementLexer ->shouldReceive ('analyze ' )
129
+ ->with ([
130
+ 'render ' => 'comment.create '
131
+ ])
132
+ ->andReturn (['create-statements ' ]);
133
+
134
+ $ this ->statementLexer ->shouldReceive ('analyze ' )
135
+ ->with ([
136
+ 'validate ' => 'comment ' ,
137
+ 'save ' => 'comment ' ,
138
+ 'flash ' => 'comment.id ' ,
139
+ 'redirect ' => 'comment.index '
140
+ ])
141
+ ->andReturn (['store-statements ' ]);
142
+
143
+ $ this ->statementLexer ->shouldReceive ('analyze ' )
144
+ ->with ([
145
+ 'render ' => 'comment.show with:comment '
146
+ ])
147
+ ->andReturn (['show-statements ' ]);
148
+
149
+ $ this ->statementLexer ->shouldReceive ('analyze ' )
150
+ ->with ([
151
+ 'render ' => 'comment.edit with:comment '
152
+ ])
153
+ ->andReturn (['edit-statements ' ]);
154
+
155
+ $ this ->statementLexer ->shouldReceive ('analyze ' )
156
+ ->with ([
157
+ 'validate ' => 'comment ' ,
158
+ 'update ' => 'comment ' ,
159
+ 'flash ' => 'comment.id ' ,
160
+ 'redirect ' => 'comment.index '
161
+ ])
162
+ ->andReturn (['update-statements ' ]);
163
+
164
+ $ this ->statementLexer ->shouldReceive ('analyze ' )
165
+ ->with ([
166
+ 'delete ' => 'comment ' ,
167
+ 'redirect ' => 'comment.index '
168
+ ])
169
+ ->andReturn (['destroy-statements ' ]);
170
+
171
+ $ actual = $ this ->subject ->analyze ($ tokens );
172
+
173
+ $ this ->assertCount (1 , $ actual ['controllers ' ]);
174
+
175
+ $ controller = $ actual ['controllers ' ]['Comment ' ];
176
+ $ this ->assertEquals ('CommentController ' , $ controller ->className ());
177
+
178
+ $ methods = $ controller ->methods ();
179
+ $ this ->assertCount (7 , $ methods );
180
+
181
+ $ this ->assertCount (1 , $ methods ['index ' ]);
182
+ $ this ->assertEquals ('index-statements ' , $ methods ['index ' ][0 ]);
183
+ $ this ->assertCount (1 , $ methods ['create ' ]);
184
+ $ this ->assertEquals ('create-statements ' , $ methods ['create ' ][0 ]);
185
+ $ this ->assertCount (1 , $ methods ['store ' ]);
186
+ $ this ->assertEquals ('store-statements ' , $ methods ['store ' ][0 ]);
187
+ $ this ->assertCount (1 , $ methods ['show ' ]);
188
+ $ this ->assertEquals ('show-statements ' , $ methods ['show ' ][0 ]);
189
+ $ this ->assertCount (1 , $ methods ['edit ' ]);
190
+ $ this ->assertEquals ('edit-statements ' , $ methods ['edit ' ][0 ]);
191
+ $ this ->assertCount (1 , $ methods ['update ' ]);
192
+ $ this ->assertEquals ('update-statements ' , $ methods ['update ' ][0 ]);
193
+ $ this ->assertCount (1 , $ methods ['destroy ' ]);
194
+ $ this ->assertEquals ('destroy-statements ' , $ methods ['destroy ' ][0 ]);
195
+ }
196
+
197
+ /**
198
+ * @test
199
+ */
200
+ public function it_returns_a_limited_resource_controller ()
201
+ {
202
+ $ tokens = [
203
+ 'controllers ' => [
204
+ 'User ' => [
205
+ 'resource ' => 'index, edit, update, destroy '
206
+ ]
207
+ ]
208
+ ];
209
+
210
+ $ this ->statementLexer ->shouldReceive ('analyze ' )
211
+ ->with ([
212
+ 'query ' => 'all:users ' ,
213
+ 'render ' => 'user.index with users '
214
+ ])
215
+ ->andReturn (['index-statements ' ]);
216
+
217
+ $ this ->statementLexer ->shouldReceive ('analyze ' )
218
+ ->with ([
219
+ 'render ' => 'user.edit with:user '
220
+ ])
221
+ ->andReturn (['edit-statements ' ]);
222
+
223
+ $ this ->statementLexer ->shouldReceive ('analyze ' )
224
+ ->with ([
225
+ 'validate ' => 'user ' ,
226
+ 'update ' => 'user ' ,
227
+ 'flash ' => 'user.id ' ,
228
+ 'redirect ' => 'user.index '
229
+ ])
230
+ ->andReturn (['update-statements ' ]);
231
+
232
+ $ this ->statementLexer ->shouldReceive ('analyze ' )
233
+ ->with ([
234
+ 'delete ' => 'user ' ,
235
+ 'redirect ' => 'user.index '
236
+ ])
237
+ ->andReturn (['destroy-statements ' ]);
238
+
239
+ $ actual = $ this ->subject ->analyze ($ tokens );
240
+
241
+ $ this ->assertCount (1 , $ actual ['controllers ' ]);
242
+
243
+ $ controller = $ actual ['controllers ' ]['User ' ];
244
+ $ this ->assertEquals ('UserController ' , $ controller ->className ());
245
+
246
+ $ methods = $ controller ->methods ();
247
+ $ this ->assertCount (4 , $ methods );
248
+
249
+ $ this ->assertCount (1 , $ methods ['index ' ]);
250
+ $ this ->assertEquals ('index-statements ' , $ methods ['index ' ][0 ]);
251
+ $ this ->assertCount (1 , $ methods ['edit ' ]);
252
+ $ this ->assertEquals ('edit-statements ' , $ methods ['edit ' ][0 ]);
253
+ $ this ->assertCount (1 , $ methods ['update ' ]);
254
+ $ this ->assertEquals ('update-statements ' , $ methods ['update ' ][0 ]);
255
+ $ this ->assertCount (1 , $ methods ['destroy ' ]);
256
+ $ this ->assertEquals ('destroy-statements ' , $ methods ['destroy ' ][0 ]);
257
+ }
107
258
}
0 commit comments