コード例 #1
0
ファイル: MultipleIdsCest.php プロジェクト: ovide/phest
 public function testPost(FunctionalTester $I)
 {
     $post = ['id' => 3, 'name' => 'Post', 'description' => 'Post desc'];
     $I->sendPOST('/foo/2/var', $post);
     $I->seeResponseCodeIs(201);
     $I->seeResponseEquals(json_encode($post));
 }
コード例 #2
0
ファイル: BasicCest.php プロジェクト: ovide/phest
 public function testPost(FunctionalTester $I)
 {
     $post = ['name' => 'Post', 'description' => 'PostDesc'];
     $prepend = ['id' => 3];
     $I->sendPOST('/foo/', $post);
     $prepend += $post;
     $I->seeResponseCodeIs(201);
     //TODO
     //$I->seeHttpHeader('Location', '/basic/3');
     $I->seeResponseEquals(json_encode($prepend));
 }
コード例 #3
0
ファイル: ContentTypeCept.php プロジェクト: ovide/phest
<?php

use Ovide\Libs\Mvc\FunctionalTester;
use Ovide\Libs\Mvc\Rest\ContentType\XmlEncoder;
Ovide\Libs\Mvc\Rest\App::instance()->reset();
$I = new FunctionalTester($scenario);
$handlers = Ovide\Libs\Mvc\Rest\App::instance()->getHandlers();
$accept = $handlers[\Ovide\Libs\Mvc\Rest\HeaderHandler\Accept::HEADER];
$accept->setAcceptable(XmlEncoder::CONTENT_TYPE, XmlEncoder::class);
$I->wantTo('test Content-type and Accept headers');
$I->amGoingTo('post a new foo as xml and expect the response as json: error 415');
$I->haveHttpHeader('Content-Type', 'application/xml');
$I->haveHttpHeader('Accept', 'application/json');
$I->sendPOST('/users', '<?xml version="1.0"?><user><name>foo</name><password>bar</password></user>');
$I->seeResponseCodeIs(415);
$I->seeHttpHeader('Accept', 'application/json');
///////////////////////////////
$I->amGoingTo('post a new foo as json and get the response as xml');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->haveHttpHeader('Accept', 'application/xml');
$I->sendPOST('/users', json_encode(['username' => 'fooo', 'password' => 'barbarbar']));
$I->seeResponseCodeIs(201);
$I->seeResponseContains('<?xml version="1.0"?>' . PHP_EOL . '<root><username>fooo</username><uri>/users/fooo</uri><articles>/users/fooo/articles</articles></root>');
//Clean
Mocks\Examples\User::$data = [];
コード例 #4
0
ファイル: UsersCept.php プロジェクト: ovide/phest
<?php

use Ovide\Libs\Mvc\FunctionalTester;
$I = new FunctionalTester($scenario);
$I->wantTo('Do some CRUD operations with users');
$foo = ['username' => 'foo', 'password' => 'barbarbar'];
$bar = ['username' => 'bar', 'password' => 'foofoofoo'];
$newUser = ['username' => $foo['username'], 'password' => 'bar'];
///////////////////////////////
$I->amGoingTo('post $newUser ' . $foo['username'] . ' with a short password');
$I->sendPOST('/users', $newUser);
$I->seeHttpHeader('Status', '400 Password is too short');
///////////////////////////////
$I->amGoingTo('post $newUser ' . $foo['username'] . ' with a valid password');
$newUser = ['username' => $foo['username'], 'password' => $foo['password']];
$I->sendPOST('/users', $newUser);
$I->seeHttpHeader('Status', "201 Created with username {$newUser['username']}");
$I->seeHttpHeader('Location');
$foo['uri'] = $I->grabHttpHeader('Location');
///////////////////////////////
$I->amGoingTo('post $newUser with a existent username');
$newUser = ['username' => 'foo', 'password' => $bar['password']];
$I->sendPOST('/users', $newUser);
$I->seeHttpHeader('Status', "409 User {$newUser['username']} already exists");
///////////////////////////////
$I->amGoingTo('post $newUser ' . $foo['username']);
$newUser = ['username' => $bar['username'], 'password' => $bar['password']];
$I->sendPost('/users', $newUser);
$I->seeHttpHeader('Status', "201 Created with username {$newUser['username']}");
$I->seeHttpHeader('Location');
$bar['uri'] = $I->grabHttpHeader('Location');