I am trying to write some tests for Silex using phpunit.
I have a class Symfony\Component\BrowserKit\Client that generates a Crawler object.
This object expects the results of the client to be xhtml however my api that I am trying to test returns JSON and the crawler does not allow this.
Is there a built in class in either Silex or phpunit that will work with JSON or will I have to roll my own?
Cheers
Definition of silex : silica or a siliceous material (such as powdered tripoli) especially for use as a filler in paints or wood.
Silex is indicated in the treatment of uncomplicated skin and skin structure infections caused by Staphylococcus aureus (methicillin-susceptible isolates only) or Streptococcus pyogenes.
Chert or silex is a cryptocrystalline or microcrystalline sedimentary rock composed of quartz.
Silex is a type of sedimentary soil that is rich with flint. In fact, silex is the English word for flint. Silex is closely associated with limestone soils -- they can exist in close proximity. But flint is generally a harder stone and can have an almost metallic look.
There is nothing special for dealing with json, but you can use the client without using the crawler. Simply call getResponse()
on the client to get the response, like this:
$client = $this->createClient();
$client->request('GET', '/');
$response = $client->getResponse();
$data = json_decode($response->getContent(), true);
$this->assertSame(array('id' => 1, 'name' => 'igorw'), $data['users'][0]);
I suggest you move this logic into a helper method on the test case and use that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With