You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-33Lines changed: 33 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,14 @@
1
1
# CrowdPHPSpecTraining
2
2
3
-
At Crowd Interactive we are interested in testing all our code, and Magento is not the exception. We are implementing the [MageTest/MageSpec](http://tinyurl.com/nednm2x) Module based on [PHPSpec](http://tinyurl.com/q6xqvgo) toolset.
3
+
At Crowd Interactive, we are interested in testing all our code and Magento is not the exception. We are implementing the [MageTest/MageSpec](http://tinyurl.com/nednm2x) Module based on [PHPSpec](http://tinyurl.com/q6xqvgo) toolset.
4
4
5
-
In this implementation we have 2 different tests taking of the [Magecasts](http://tinyurl.com/qxs5ux8) tutorials. The first is to understand how PHPSpec works.
5
+
In this implementation, we have two different tests taken from the [Magecasts](http://tinyurl.com/qxs5ux8) tutorials. The first one is to understand how PHPSpec works.
6
6
7
7
## First Test
8
8
9
-
"We will look at PHPspec and how we can use PHPspec to enhance our development workflow".
9
+
"We will look at PHPspec and how we can use it to enhance our development workflow".
10
10
11
-
### Prerequisites
11
+
### Prerequisites
12
12
13
13
PHP 5.3.x or greater
14
14
Install composer
@@ -17,7 +17,7 @@ In this implementation we have 2 different tests taking of the [Magecasts](http:
17
17
18
18
#### Create composer.json file
19
19
20
-
On root project create composer.json file with the below data
20
+
On root project, create composer.json file with the data below:
21
21
22
22
```json
23
23
{
@@ -39,7 +39,7 @@ On root project create composer.json file with the below data
39
39
40
40
$ composer install
41
41
42
-
You will get something like this:
42
+
You will get something like this:
43
43
44
44
```bash
45
45
Loading composer repositories with package information
@@ -123,7 +123,7 @@ In your folder project now you will see
123
123
![spec folder]
124
124
(http://i.imgur.com/p9uu1TX.png)
125
125
126
-
The content of ProductSpec.php file created looks like this
126
+
The content of the ProductSpec.php created file looks like this:
127
127
128
128
```php
129
129
<?php
@@ -144,12 +144,12 @@ class ProductSpec extends ObjectBehavior
144
144
145
145
$ bin/phpspec run
146
146
147
-
And now you will see this
147
+
And now you will see this:
148
148
149
149
![class does not exists]
150
150
(http://i.imgur.com/0iZ7OV5.png)
151
151
152
-
Obviously you write YES and you will get the next message
152
+
Obviously you type YES and you will get the next message:
153
153
154
154
![class was created]
155
155
(http://i.imgur.com/r4oTSWn.png)
@@ -159,7 +159,7 @@ And the next file structure in your project
159
159
![src file structure]
160
160
(http://i.imgur.com/4DAdc3t.png)
161
161
162
-
Inside Product.php you will see
162
+
Inside Product.php you will see
163
163
164
164
```php
165
165
<?php
@@ -171,7 +171,7 @@ class Product
171
171
}
172
172
```
173
173
174
-
Now inside [magentoroot]/spec/Crowd/Store/ProductSpec.php file write the next functions
174
+
Now inside [magentoroot]/spec/Crowd/Store/ProductSpec.php file, write the next functions
175
175
176
176
```php
177
177
functionit_should_have_a_name()
@@ -181,11 +181,11 @@ function it_should_have_a_name()
181
181
182
182
functionit_should_have_sku()
183
183
{
184
-
$this->getSku()->shouldReturn('12345');
184
+
$this->getSku()->shouldReturn('12345');
185
185
}
186
186
```
187
187
188
-
The complete files looks like
188
+
The complete files looks like:
189
189
190
190
```php
191
191
<?php
@@ -209,35 +209,35 @@ class ProductSpec extends ObjectBehavior
209
209
210
210
functionit_should_have_sku()
211
211
{
212
-
$this->getSku()->shouldReturn('12345');
212
+
$this->getSku()->shouldReturn('12345');
213
213
}
214
214
}
215
215
```
216
216
217
-
What are we doing here? Well, we are defining two test functions more, one to check if a functioncalledgetName() returns a string with value "Testing Spec" and other to check if a functioncalledgetSku() returns a string with value "12345"
217
+
What are we doing here? Well, we are defining two more test functions, one to check if a functioncalledgetName() returns a string with value "Testing Spec" and other to check if a functioncalledgetSku() returns a string with value "12345"
218
218
219
-
On terminal lets do
219
+
On terminal lets do:
220
220
221
221
$ bin/phpspec run
222
222
223
-
It will display
223
+
It will display:
224
224
225
225
![getName() functiondoes not exists]
226
226
(http://i.imgur.com/aT7yySp.png)
227
227
228
-
Press Y + return key and you should have this
228
+
Press Y + return key:
229
229
230
230
![getSku() functiondoes not exists]
231
231
(http://i.imgur.com/6KUmIbi.png)
232
232
233
-
Press Y + return key again and should have this
233
+
Press Y + return key again:
234
234
235
235
![functions exists but tests does not pass]
236
236
(http://i.imgur.com/eOieqj8.png)
237
237
238
-
What that means? First of all, PHPSpec checks ifgetName() and getSku() functions exists in the Product class, and it does not find them and ask us if we want to crete them. Once created PHPSpec tries to run the tests but they do not pass.
238
+
What does this mean? First of all, PHPSpec checks ifgetName() and getSku() functions exists in the Product class, and ifit does not find them, asks us if we want to crete them. Once created, PHPSpec will try to run the tests, but they do not pass.
239
239
240
-
The Product.php file under [magentoroot]/src/Crowd/Store/ change it content amd now looks like
240
+
The Product.php file under [magentoroot]/src/Crowd/Store/ changed its content and now looks like:
241
241
242
242
```php
243
243
<?php
@@ -259,7 +259,7 @@ class Product
259
259
}
260
260
```
261
261
262
-
That's the why about tests not pass. Becouse the functions exists but, they do nothing. Lets work with them typing the following in Product.php
262
+
That's the reason of out tests not passing: the functions exist, but they do nothing. Lets work with them and type the following in Product.php
263
263
264
264
```php
265
265
<?php
@@ -280,7 +280,7 @@ class Product
280
280
281
281
public function getName()
282
282
{
283
-
return $this->_name;
283
+
return $this->_name;
284
284
}
285
285
286
286
public function getSku()
@@ -290,16 +290,16 @@ class Product
290
290
}
291
291
```
292
292
293
-
Type again
293
+
Run the specs again:
294
294
295
-
$ bin/phpspec run
295
+
$ bin/phpspec run
296
296
297
-
And, oh them do not pass again. Why?
297
+
And... oh!, they don't pass again. Why?
298
298
299
299
![test not pass again]
300
300
(http://i.imgur.com/4ODyU1i.png)
301
301
302
-
That happend becouse phpspec its running without any init data. To do that lets type following inside ProductSpec class
302
+
This happened because phpspec is running without any init data. To do that, let's type the following inside ProductSpec class:
303
303
304
304
```php
305
305
function let()
@@ -310,13 +310,13 @@ function let()
310
310
}
311
311
```
312
312
313
-
The let() method is used to pass data into constructor each time the parser gets constructed using beConstructedWith() method
313
+
The let() method is used to pass data into the constructor each time the parser gets created using the beConstructedWith() method
0 commit comments