I am starting to write some integration tests for my CakePHP application and was wondering where to put a utility method used for multiple tests.
In my app, nearly every action needs to be authenticated.
In the cookbook, I have read that the
session() method of
Cake\TestSuite\IntegrationTestCase can be use to simulate a logged in user.
Currently, I have created a class
App\Test\TestCase\AppIntegrationTestCase that extends
Cake\TestSuite\IntegrationTestCase and putted my faked
login() function in there.
For example :
class AppIntegrationTestCase extends IntegrationTestCase
public function login()
'Auth' => [
'User' => [
'id' => 1,
'username' => 'testing'
For my integration tests, I then extend
App\Test\TestCase\AppIntegrationTestCase rather than
Cake\TestSuite\IntegrationTestCase and use defined function. For example
class PostsControllerTest extends AppIntegrationTestCase
public $fixtures = ['app.posts'];
public function testReadPosts()
$this->assertResponseContains('Latest blog posts');
It works but, it is the right way to go ?