<?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');