Beispiel #1
0
 public function testNotAllowed(FunctionalTester $I)
 {
     $I->sendPATCH('/foo');
     $I->seeResponseCodeIs(405);
 }
Beispiel #2
0
<?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 = [];
Beispiel #3
0
 public function testDelete(FunctionalTester $I)
 {
     $I->sendDELETE('/foo/2/var/3');
     $I->seeResponseCodeIs(204);
 }
Beispiel #4
0
$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');
///////////////////////////////
$I->amGoingTo('request user $foo at ' . $foo['uri']);
$I->sendGet($foo['uri']);
$I->seeResponseCodeIs(200);
$I->seeResponseEquals(json_encode(['username' => $foo['username'], 'uri' => "/users/{$foo['username']}", 'articles' => "/users/{$foo['username']}/articles"]));
///////////////////////////////
$I->amGoingTo('request all users');
$I->sendGet('/users');
$I->seeResponseCodeIs(200);
$I->seeResponseEquals(json_encode([['username' => $foo['username'], 'uri' => "/users/{$foo['username']}", 'articles' => "/users/{$foo['username']}/articles"], ['username' => $bar['username'], 'uri' => "/users/{$bar['username']}", 'articles' => "/users/{$bar['username']}/articles"]]));
Beispiel #5
0
 public function testInternalServerError(FunctionalTester $I)
 {
     $I->sendDELETE('/foo/0');
     $I->seeResponseCodeIs(500);
     $I->seeResponseEquals(json_encode(['message' => 'Internal server error', 'code' => 500]));
 }