本文整理汇总了PHP中UnitTester::getListenedQueries方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitTester::getListenedQueries方法的具体用法?PHP UnitTester::getListenedQueries怎么用?PHP UnitTester::getListenedQueries使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnitTester
的用法示例。
在下文中一共展示了UnitTester::getListenedQueries方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testUserGroup
public function testUserGroup()
{
$this->tester->importDatabase(realpath(__DIR__ . '/../_data/') . '/pckg_database_001.sql');
$this->tester->listenToQueries();
$userGroup = UserGroup::getOrCreate(['slug' => 'test1']);
$userGroup->title = 'test2title';
$userGroup->slug = 'test2';
$userGroup->save();
$this->assertEquals([['sql' => 'SELECT `user_groups`.* FROM `user_groups` WHERE (`user_groups`.`slug` = ?) LIMIT 1', 'binds' => ['test1']], ['sql' => 'INSERT INTO `user_groups` (`slug`) VALUES (?)', 'binds' => ['test1']], ['sql' => 'INSERT INTO `user_groups_i18n` (`id`, `language_id`) VALUES (?, ?)', 'binds' => [5, 'en']], ['sql' => 'UPDATE `user_groups` SET `id` = ?, `slug` = ? WHERE (`id` = ?)', 'binds' => [5, 5, 'test2']], ['sql' => 'SELECT `user_groups_i18n`.* FROM `user_groups_i18n` WHERE (`user_groups_i18n`.`id` = ?) AND (`user_groups_i18n`.`language_id` = ?) LIMIT 1', 'binds' => [5, 'en']], ['sql' => 'UPDATE `user_groups_i18n` SET `id` = ?, `language_id` = ?, `title` = ? WHERE (`id` = ?) AND (`language_id` = ?)', 'binds' => [5, 5, 'en', 'en', 'test2title']]], $this->tester->getListenedQueries());
$this->tester->listenToQueries();
$userGroup = UserGroup::getOrCreate(['slug' => 'untranslated']);
$userGroup->title = 'translated';
$userGroup->save();
$this->assertEquals([['sql' => 'SELECT `user_groups`.* FROM `user_groups` WHERE (`user_groups`.`slug` = ?) LIMIT 1', 'binds' => ['untranslated']], ['sql' => 'UPDATE `user_groups` SET `id` = ?, `slug` = ? WHERE (`id` = ?)', 'binds' => [4, 4, 'untranslated']], ['sql' => 'SELECT `user_groups_i18n`.* FROM `user_groups_i18n` WHERE (`user_groups_i18n`.`id` = ?) AND (`user_groups_i18n`.`language_id` = ?) LIMIT 1', 'binds' => [4, 'en']], ['sql' => 'INSERT INTO `user_groups_i18n` (`id`, `language_id`, `title`) VALUES (?, ?, ?)', 'binds' => [4, 'en', 'translated']]], $this->tester->getListenedQueries());
}
示例2: testAllTheWayLazyRelations
public function testAllTheWayLazyRelations()
{
$languages = new Languages();
$this->tester->listenToQueries();
$language = $languages->where('id', 2)->one();
$language->users(function (HasMany $users) {
$users->withUserGroup()->withCategories(function (HasAndBelongsTo $categories) {
$categories->withUsers(function (HasMany $users) {
$users->withLanguage();
});
})->withSettings();
});
$this->assertNotEmpty($language->users->first());
$this->assertNotEmpty($language->users->first()->userGroup);
$this->assertNotEmpty($language->users->first()->categories->first());
$this->assertNotEmpty($language->users->first()->categories->first()->users->first());
$this->assertNotEmpty($language->users->first()->categories->first()->users->first()->language);
$this->assertNotEmpty($language->users->first()->settings->first());
$this->assertCount(10, $this->tester->getListenedQueries());
}