Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Functional tests using PHPUnit

I see WebTestCase and Symfony come up a lot...I have some unit tests in PHPUnit already but really need higher level tests...I do not need anything fancy like Selenium (the UI is done in ExtJS but this could change entirely to Polymer in the future) I just need to post data and check the JSON results.

Can this be done via PHPUnit or do I need to bring in Symfony and it's WebTestCase?

Testing RESTful web services using PHPUnit

Note: I am actually looking to test the services -- no mocked objects desired -- I need to login when the test suite is first run -- store the SESSION ID and go through each test...

like image 282
Alex.Barylski Avatar asked Jul 09 '26 14:07

Alex.Barylski


1 Answers

I have achieved success in writing PHP functional tests using Guzzle.

It allows you to perform HTTP requests like this:

$client = new GuzzleHttp\Client();
$response = $client->get('http://guzzlephp.org');

And the $client will maintain the PHPSESSIONID across requests, allowing you to perform authenticated requests by logging in and then performing requests with the same client.

like image 88
Raibaz Avatar answered Jul 13 '26 19:07

Raibaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!