Reputation: 51
I am trying to run some unit tests in CakePHP 3.0 but keep getting the following errors, which seem to be more Cake problems than one I constructed myself? Anyone have a similar issue? Test code is following samle in this article: http://book.cakephp.org/3.0/en/development/testing.html
namespace App\Test\TestCase\Controller;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestCase;
/**
* App\Controller\UsersController Test Case
*/
class UsersControllerTest extends IntegrationTestCase
{
/**
* Test add method
*
* @return void
*/
public function testAdd()
{
$data = [
'username' => 'testusername',
'password' => 'testpassword',
'email' => '[email protected]',
'location_id' => 5,
'gender' => 'Male',
'info' => 'test info'
];
$this->post('/users', $data);
$this->assertResponseSuccess();
$users = TableRegistry::get('Users');
$query = $users->find()->where(['username' => $data['username']]);
$this->assertEquals(1, $query->count());
}
Response:
1) App\Test\TestCase\Controller\UsersControllerTest::testIndex
Use of undefined constant TMP - assumed 'TMP'
C:\wamp\www\mysite\vendor\cakephp\cakephp\src\Network\Session.php:141
C:\wamp\www\mysite\vendor\cakephp\cakephp\src\Network\Session.php:95
C:\wamp\www\mysite\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCas
e.php:340
C:\wamp\www\mysite\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCas
e.php:267
C:\wamp\www\mysite\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCas
e.php:188
Upvotes: 2
Views: 1357
Reputation: 48
I had the same problem. Here is What worked for me
ex : c:/xampp/htdocs/someproject/
then type command
c:/xampp/htdocs/someproject>phpunit
it will run all the tests. Hope this Works For You
Upvotes: 1
Reputation: 1779
If it can help, I had the same error because the phpunit.xml.dist configuration file was missing in my project.
You can find it here: https://github.com/cakephp/app/blob/master/phpunit.xml.dist.
Upvotes: 2
Reputation: 9614
You need to define the constants that are required for CakePHP to work. This is done for you in the tests/bootstrap.php file in the application skeleton:
https://github.com/cakephp/app/blob/master/tests/bootstrap.php#L8
By including the application bootstrap, it also creates defines the constants here:
https://github.com/cakephp/app/blob/master/config/paths.php#L61
Upvotes: 2