Command line
./vendor/bin/phpunit tests/TestCase/Model/Table/UsersTableTestvendor/bin/phpunit tests/TestCase/Controller/SettingsControllerTest.php
vendor/bin/phpunit tests/TestCase/Controller/UsersControllerTest.php --coverage-html webroot/coverage --whitelist src/Controller/UsersController.php
Assert methods in Controller
// Check for a 2xx response code
$this->assertResponseOk();
// Check for a 2xx/3xx response code
$this->assertResponseSuccess();
// Check for a 4xx response code
$this->assertResponseError();
// Check for a 5xx response code
$this->assertResponseFailure();
// Check for a specific response code, e.g. 200
$this->assertResponseCode(200);
// Check the Location header
$this->assertRedirect(['controller' => 'Articles', 'action' => 'index']);
// Check that no Location header has been set
$this->assertNoRedirect();
// Check a part of the Location header
$this->assertRedirectContains('/articles/edit/');
// Assert not empty response content
$this->assertResponseNotEmpty();
// Assert empty response content
$this->assertResponseEmpty();
// Assert response content
$this->assertResponseEquals('Yeah!');
// Assert partial response content
$this->assertResponseContains('You won!');
$this->assertResponseNotContains('You lost!');
// Assert layout
$this->assertLayout('default');
// Assert which template was rendered (if any)
$this->assertTemplate('index');
// Assert data in the session
$this->assertSession(1, 'Auth.User.id');
// Assert response header.
$this->assertHeader('Content-Type', 'application/json');
// Assert view variables
$this->assertEquals('jose', $this->viewVariable('user.username'));
// Assert cookies in the response
$this->assertCookie('1', 'thingid');
// Check the content type
$this->assertContentType('application/json');
No comments:
Post a Comment