关系不起作用-Laravel/phpunit/Sqlite
我正在编写一个测试,但是我在基本关系中得到了一些意想不到的结果。我使用内存中的sqlite db 这些测试在MySQL数据库中运行良好。我想这与这次迁移有关关系不起作用-Laravel/phpunit/Sqlite,php,laravel,sqlite,phpunit,Php,Laravel,Sqlite,Phpunit,我正在编写一个测试,但是我在基本关系中得到了一些意想不到的结果。我使用内存中的sqlite db 这些测试在MySQL数据库中运行良好。我想这与这次迁移有关 $tournament0 = factory(Tournament::class) ->create(['user_id' => $this->simpleUser->id]); $this->simpleUser是在setUp()方法上创建的 现在,当$this->simpleUser->tourname
$tournament0 = factory(Tournament::class)
->create(['user_id' => $this->simpleUser->id]);
$this->simpleUser
是在setUp()
方法上创建的
现在,当$this->simpleUser->tournaments
应该返回$tournament0
,但它是空的
我的关系很正常,没有破裂。此外,在浏览器中手动测试时,它也可以工作
它只是在使用phpunit时失败
下面是setUp()方法:
失败的完整方法:
/** @test */
public function dashboard_check_initial_state()
{
Artisan::call('db:seed', ['--class' => 'CountriesSeeder', '--database' => 'sqlite']);
Artisan::call('db:seed', ['--class' => 'TournamentLevelSeeder', '--database' => 'sqlite']);
Artisan::call('db:seed', ['--class' => 'CategorySeeder', '--database' => 'sqlite']);
// Given
$this->logWithUser($this->simpleUser);
// Nothing has been created, default dash
$this->visit('/')
->see(trans('core.create_new_tournament'))
->dontSee(trans('core.congigure_categories'));
// Create 1 tournament
$tournament0 = factory(Tournament::class)->create(['user_id' => $this->simpleUser->id]);
$this->visit('/')
->seeInElement("p.text-muted", trans('core.no_tournament_created_yet'));
// Now configure 2/2 categories
$championship1 = factory(Championship::class)->create(['tournament_id' => $tournament0->id,'category_id'=>1]);
$championship2 = factory(Championship::class)->create(['tournament_id' => $tournament0->id,'category_id'=>2]);
factory(ChampionshipSettings::class)->create(['championship_id' => $championship1->id]);
factory(ChampionshipSettings::class)->create(['championship_id' => $championship2->id]);
$this->visit('/')
->seeInElement("span.text-muted", trans('core.congigure_categories'));
}
你知道会是什么吗?你能展示一下
设置方法和失败的整个测试方法吗?是的,但请稍候,因为问题似乎不是关系,因为锦标赛::all()返回空集合我添加了设置方法…仍然不知道会是什么:(…以及失败的整个测试方法确定,方法已添加能否显示设置
方法和失败的整个测试方法?是的,但请稍候,因为问题似乎不是关系,因为锦标赛::all()返回空集合我添加了设置方法…仍然不知道可能是什么:(…并且增加了失败的整个测试方法
/** @test */
public function dashboard_check_initial_state()
{
Artisan::call('db:seed', ['--class' => 'CountriesSeeder', '--database' => 'sqlite']);
Artisan::call('db:seed', ['--class' => 'TournamentLevelSeeder', '--database' => 'sqlite']);
Artisan::call('db:seed', ['--class' => 'CategorySeeder', '--database' => 'sqlite']);
// Given
$this->logWithUser($this->simpleUser);
// Nothing has been created, default dash
$this->visit('/')
->see(trans('core.create_new_tournament'))
->dontSee(trans('core.congigure_categories'));
// Create 1 tournament
$tournament0 = factory(Tournament::class)->create(['user_id' => $this->simpleUser->id]);
$this->visit('/')
->seeInElement("p.text-muted", trans('core.no_tournament_created_yet'));
// Now configure 2/2 categories
$championship1 = factory(Championship::class)->create(['tournament_id' => $tournament0->id,'category_id'=>1]);
$championship2 = factory(Championship::class)->create(['tournament_id' => $tournament0->id,'category_id'=>2]);
factory(ChampionshipSettings::class)->create(['championship_id' => $championship1->id]);
factory(ChampionshipSettings::class)->create(['championship_id' => $championship2->id]);
$this->visit('/')
->seeInElement("span.text-muted", trans('core.congigure_categories'));
}