Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
defrag committed Apr 18, 2014
1 parent 4f2a6fa commit d200358
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,60 @@ require: {
}
```

### Ways of testing
Common way of testing api responses with Symfony2 WebTestCase

```php
public function testGetToys()
{
$this->setUpFixtures();
$this->setUpOath();
$this->client->request('GET', '/api/toys');
$response = $this->client->getResponse();
$this->assertJsonResponse($response, 200);
$content = $response->getContent();
$decoded = json_decode($content, true);
$this->assertTrue(isset($decoded[0]['id']));
$this->assertTrue(isset($decoded[1]['id']));
$this->assertTrue(isset($decoded[2]['id']));
$this->assertEquals($decoded[0]['name'], 'Barbie'));
$this->assertEquals($decoded[1]['name'], 'GI Joe'));
$this->assertEquals($decoded[2]['name'], 'Optimus Prime'));
}
```
With php-matcher, you can make it more readable to the person reading the test:
```php
public function testGetToys()
{
$this->setUpFixtures();
$this->setUpOath();
$this->client->request('GET', '/api/toys');
$response = $this->client->getResponse();
$this->assertJsonResponse($response, 200);
$content = $response->getContent();
$pattern = '[
{
"id": "@string@",
"name": "Barbie",
"_links: "@*@"
},
{
"id": "@string@",
"name": "GI Joe",
"_links": "@*@"
},
{
"id": "@string@",
"name": "Optimus Prime",
"_links": "@*@"
}
]
';
$this->assertEquals(match($content, $pattern));
}
```


From now you should be able to use global function ``match($value, $pattern)``

##Example usage
Expand Down

0 comments on commit d200358

Please sign in to comment.