[Flow] Creating simple UnitTests (RestController)
Peter R
peter at webschuppen.com
Wed Apr 2 13:30:37 CEST 2014
Hello Christian,
I created a functional test:
/**
* @test
*/
public function listActionHasErrorCode401() {
$response = $this->browser->request('http://localhost/api/v1/standard');
$this->assertEquals(401, $response->getStatusCode());
}
and this works for me. But now I have to log in to the api to get status code 200.
So I've created the database flow_functional_testing as pdo_mysql with user, password and host in Configuration/Testing/Settings.yaml.
The property phpBinaryPathAndFilename is also seted.
Is it ok that database flow_functional_testing is empty?
Because I can not log in. The process failed. For example user with password doesn't exits.
$user = new User();
$user ->setUsername('foo');
$user ->setPassword('bar');
$this->persistenceManager->add($user );
$this->persistenceManager->persistAll();
$request = Request::create(new Uri('http://localhost/api/v1/auth'), 'POST');
$request->setHeader('Content-Type', 'application/json');
$request->setHeader('Accept', 'application/json');
$jsonArray = array(
'username' => $user ->getUsername(),
'password' => $user ->getPassword()
);
$request->setContent(json_encode($jsonArray));
$response = $this->browser->sendRequest($request);
$this->assertEquals(200, $response->getStatusCode());
Peter
More information about the Flow
mailing list