我将固定装置保存在:app/test/fixture/ 目录中
而对于 ex app/test/fixture/UserRoleHistoryFixture.php 看起来是这样的
<?php
class UserRoleHistoryFixture extends CakeTestFixture {
public $import = array('model' => 'UserRoleHistory', 'records' => false, 'connection' => 'test');
}
app/Test/Fixture/UserFixture.php 看起来是这样的
class UserFixture extends CakeTestFixture {
public $import = array('model' => 'User', 'records' => true, 'connection' => 'test');
}
所有灯具看起来都是这样(唯一的区别是有时记录设置为真)然后在我的 UserTest.php(model) 中使用它的这种方式:
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');
));
而我在尝试做一些测试时得到了什么,我 PDO 错误和堆栈跟踪,也许我称之为错误的方式?猜猜这是我如何制作固定装置的问题,但不知道..谢谢你的想法!
编辑:我的问题改变了一点,有错误和堆栈跟踪:
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
我得到的是
Fatal Error (256): [PDOException] You cannot serialize or unserialize PDOStatement instances
#0 [internal function]: PDOStatement->__sleep()
etc ;/
我看到第一个问题是关于外键的,当测试用于删除表用户时,存在外键冲突,但它是关于如何创建数据库的问题吗?