I'm using phpunit with cakephp for testing but when I try to run some test class is throw a Fatal Error but this class is inserted correctly and is not even accused missing file Error by PHPStorm.
The command to execute a testcase:
c:\xampp\htdocs\PROJETOS\Shopping\vendor\phpunit>phpunit "C:/xampp/htdocs/PROJETOS/Shopping/tests/TestCase/Model/Table/UsersTableTest.php"
The Fatal Error:
Fatal error: Class 'Cake\TestSuite\TestCase' not found in C:\xampp\htdocs\PROJET OS\Shopping\tests\TestCase\Model\Table\UsersTableTest.php on line 12
The test case:
<?php
namespace App\Test\TestCase\Model\Table;
use App\Model\Table\UsersTable;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
/**
* App\Model\Table\UsersTable Test Case
*/
class UsersTableTest extends TestCase
{
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.users',
'app.user_types',
'app.bookings',
'app.stores'
];
/**
* setUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
$config = TableRegistry::exists('Users') ? [] : ['className' => 'App\Model\Table\UsersTable'];
$this->Users = TableRegistry::get('Users', $config);
}
/**
* tearDown method
*
* @return void
*/
public function tearDown()
{
unset($this->Users);
parent::tearDown();
}
/**
* Test initialize method
*
* @return void
*/
public function testInitialize()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test validationDefault method
*
* @return void
*/
// Método que deverá testar o método "validationDefault()" de "UsersTable",
// mas como e quando este método será chamado?
// A ferramenta seleciona o método a ser executado
public function testValidationDefault()
{
$this->markTestIncomplete('Not implemented yet.');
}
/**
* Test buildRules method
*
* @return void
*/
public function testBuildRules()
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testFindUserById(){
$query = $this->Users->find('userById', [
'conditions' => ['Users.id' => 900000],
'fields' => ['Users.id', 'Users.email', 'Users.password',
'Users.username', 'Users.user_type_id', 'Users.created',
'Users.modified']
]);
$this->assertInstanceOf('Cake\ORM\Query', $query);
$result = $query->hydrate(false)->toArray();
$expected = [
[
'id' => 900000,
'email' => '[email protected]',
'password' => 'usuariocomum1senha',
'username' => 'usuariocomum1username',
'user_type_id' => 900000,
'created' => '2015-07-17 18:46:47',
'modified' => '2015-07-17 18:46:47'
]
];
$this->assertEquals($expected, $result);
}
}
In folder: [ProjectName]/tests/ has 2 folders Fixture and TestCase and 1 file bootstrap.php
My folder Structure:
config and tests folders:
phpunit folder (inside vendor folder (installed with composer))
bin folder in vendor folder
When I remove phpunit with composer follow that answer: How to remove unused dependencies from composer? still got a folder phpunit with a strange file (It is OK?)
NOTE: I'm using CakePHP 3.0.11 and PHPHUnit 4.8
phpunit
that tells it how to bootstrap. I don't know how it works. Here is the doc: phpunit.de/manual/current/en/appendixes.configuration.html – Halcyonphpunit
usingcomposer
, you can remove thevendor/phpunit
folder. – Holt