public function testAccept(FunctionalTester $I) { $this->app->mountResource(\Mocks\Controllers\FooVar::class); $handlers = App::instance()->getHandlers(); $accept = $handlers[HeaderHandler\Accept::HEADER]; $accept->setAcceptable('application/xml', ContentType\XmlEncoder::class); $I->haveHttpHeader('Accept', 'application/xml'); $I->sendGET('/foo/1/var'); $expected = <<<EOXML <?xml version="1.0"?> <root><id>1</id><name>foo1</name><description>foo1 desc</description><id>2</id><name>foo2</name><description>foo2 desc</description></root> EOXML; $I->seeResponseContains($expected); $I->haveHttpHeader('Accept', 'application/json'); $I->sendGET('/foo/1/var'); $I->seeResponseContainsJson(); $I->haveHttpHeader('Accept', 'foo/bar'); $I->sendGET('/foo/1/var'); }
public function testNotAllowed(FunctionalTester $I) { $I->sendPATCH('/foo'); $I->seeResponseCodeIs(405); }
<?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 = [];
<?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');
public function testDelete(FunctionalTester $I) { $I->sendDELETE('/foo/2/var/3'); $I->seeResponseCodeIs(204); }
public function testInternalServerError(FunctionalTester $I) { $I->sendDELETE('/foo/0'); $I->seeResponseCodeIs(500); $I->seeResponseEquals(json_encode(['message' => 'Internal server error', 'code' => 500])); }