i keep fixtures in: app/test/fixture/ directory
and for e.x.
app/test/fixture/UserRoleHistoryFixture.php looks this way
<?php
class UserRoleHistoryFixture extends CakeTestFixture {
public $import = array('model' => 'UserRoleHistory', 'records' => false, 'connection' => 'test');
}
app/Test/Fixture/UserFixture.php looks this way
class UserFixture extends CakeTestFixture {
public $import = array('model' => 'User', 'records' => true, 'connection' => 'test');
}
All fixtures looks this (only difference is somtimes records are set true)
Then in my UserTest.php(model) im using its this way:
class UserTest extends CakeTestCase {
public $fixtures = array('app.user', 'app.user_role','app.session', 'app.users_activity', 'app.user_role_history'
);
public $autoFixtures = false;
public function setUp() {
parent::setUp();
$this->loadFixtures('User','UserRoleHistory','Session','UserRole','UsersActivity');
));
And what i get while trying to do some test i PDO error and stack trace , mayby i called sth wrong way ? Guess that it’s problem with how i make my fixture but dont know ..
Thanks for ideas !
Edit:
my problem changed a little, there is error and stack trace:
PDOException: SQLSTATE[23503]: Foreign key violation: 7 BŁĄD: modyfikacja lub usunięcie na tabeli "users" narusza klucz obcy "user_role_history_user_id" tabeli "user_role_history" DETAIL: Klucz (id)=(26381) ma wciąż odwołanie w tabeli "user_role_history".
Test case: UserTest(testUserNameExists)
Stack trace:
C:\Program Files (x86)\PostgreSQL\EnterpriseDB- ApachePHP\apache\www\soig\www\konkursy2.0\lib\Cake\Model\Datasource\DboSource.php : 436
C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\apache\www\soig\www\konkursy2.0\lib\Cake\Model\Datasource\DboSource.php : 403
C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\apache\www\soig\www\konkursy2.0\lib\Cake\Model\Datasource\Database\Postgres.php : 309
C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\apache\www\soig\www\konkursy2.0\lib\Cake\TestSuite\Fixture\CakeTestFixture.php : 232
C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\apache\www\soig\www\konkursy2.0\lib\Cake\TestSuite\Fixture\CakeFixtureManager.php : 236
C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\apache\www\soig\www\konkursy2.0\lib\Cake\TestSuite\CakeTestCase.php : 191
C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\apache\www\soig\www\konkursy2.0\app\Test\Case\Model\UserTest.php : 16
C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\apache\www\soig\www\konkursy2.0\vendors\PHPUnit\Framework\TestCase.php : 801
C:\Program Files (x86)\PostgreSQL\EnterpriseDB-ApachePHP\apache\www\soig\www\konkursy2.0\app\webroot\test.php : 92
Also what i got is
Fatal Error (256): [PDOException] You cannot serialize or unserialize PDOStatement instances
#0 [internal function]: PDOStatement->__sleep()
etc ;/
i see the first problem is about foregin key, and that when test is used to delete table users there is foregin key violation but is it problem about how the database is created ?
You importing from ‘test’ datasource, remove that in your fixtures. it pull from default, or specify another to pull from if you like. It will create in ‘test’ instead of importing from it