當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UnitTester::listenToQueries方法代碼示例

本文整理匯總了PHP中UnitTester::listenToQueries方法的典型用法代碼示例。如果您正苦於以下問題:PHP UnitTester::listenToQueries方法的具體用法?PHP UnitTester::listenToQueries怎麽用?PHP UnitTester::listenToQueries使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UnitTester的用法示例。


在下文中一共展示了UnitTester::listenToQueries方法的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());
 }
開發者ID:pckg,項目名稱:database,代碼行數:15,代碼來源:CheckTranslatableExtensionTest.php

示例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());
 }
開發者ID:pckg,項目名稱:database,代碼行數:20,代碼來源:CheckSelectQueryTest.php


注:本文中的UnitTester::listenToQueries方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。