@@ -14,6 +14,60 @@ require: {
14
14
}
15
15
```
16
16
17
+ ### Ways of testing
18
+ Common way of testing api responses with Symfony2 WebTestCase
19
+
20
+ ``` php
21
+ public function testGetToys()
22
+ {
23
+ $this->setUpFixtures();
24
+ $this->setUpOath();
25
+ $this->client->request('GET', '/api/toys');
26
+ $response = $this->client->getResponse();
27
+ $this->assertJsonResponse($response, 200);
28
+ $content = $response->getContent();
29
+ $decoded = json_decode($content, true);
30
+ $this->assertTrue(isset($decoded[0]['id']));
31
+ $this->assertTrue(isset($decoded[1]['id']));
32
+ $this->assertTrue(isset($decoded[2]['id']));
33
+ $this->assertEquals($decoded[0]['name'], 'Barbie'));
34
+ $this->assertEquals($decoded[1]['name'], 'GI Joe'));
35
+ $this->assertEquals($decoded[2]['name'], 'Optimus Prime'));
36
+ }
37
+ ```
38
+ With php-matcher, you can make it more readable to the person reading the test:
39
+ ``` php
40
+ public function testGetToys()
41
+ {
42
+ $this->setUpFixtures();
43
+ $this->setUpOath();
44
+ $this->client->request('GET', '/api/toys');
45
+ $response = $this->client->getResponse();
46
+ $this->assertJsonResponse($response, 200);
47
+ $content = $response->getContent();
48
+ $pattern = '[
49
+ {
50
+ "id": "@string@",
51
+ "name": "Barbie",
52
+ "_links: "@*@"
53
+ },
54
+ {
55
+ "id": "@string@",
56
+ "name": "GI Joe",
57
+ "_links": "@*@"
58
+ },
59
+ {
60
+ "id": "@string@",
61
+ "name": "Optimus Prime",
62
+ "_links": "@*@"
63
+ }
64
+ ]
65
+ ';
66
+ $this->assertEquals(match($content, $pattern));
67
+ }
68
+ ```
69
+
70
+
17
71
From now you should be able to use global function `` match($value, $pattern) ``
18
72
19
73
##Example usage
0 commit comments