Open cmoore4 opened 11 years ago
Codeception seems to be a really nice test suite for API, with the ApiGuy class:
<?php
$I = new ApiGuy($scenario);
$I->wantTo('create a new user by API');
$I->amHttpAuthenticated('davert','123456');
$I->haveHttpHeader('Content-Type','application/x-www-form-urlencoded');
$I->sendPOST('/users', array('name' => 'davert' ));
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(array('result' => 'ok'));
?>
Its nice, but the syntax isn't very nice to look at or read.
Potentially use something like spectrum ?
I tried Codeception for testing some REST API in my application and it was nice. As it is based on PHP classes in intentions, it has nice working autocomplete in IDE. For me spectrum smells a little JavaScript, at first glance it looks like Jasmine.
I've also found that Behat could be used for testing API, here is article: http://keithloy.me/blog/2012/05/02/testing-rest-api-with-behat/ but I didn't used it myself so far.
Yeah, I'm not a huge fan of the syntax, but it is exceptionally clear what is happening, and is purpose-specific to testing a Rest API; it supports all of the tests I want to do out of the box.
Spectrum is nice for unit testing and functional testing of modules, which is not what I want to implement at first. As this is a more of a seed/boilerplate project, not a library, unit testing will be left to the implementer.
I'll write up the first few tests over the weekend and see how nice it is to work with.
This needs tests.