-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb0b371
commit 1fa5c86
Showing
3 changed files
with
73 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) CodeIgniter Foundation <admin@codeigniter.com> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CodeIgniter\Debug\Toolbar\Collectors; | ||
|
||
use CodeIgniter\Database\Query; | ||
use CodeIgniter\Test\CIUnitTestCase; | ||
use PHPUnit\Framework\MockObject\MockObject; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class DatabaseTest extends CIUnitTestCase | ||
{ | ||
public function testDisplay(): void | ||
{ | ||
/** @var MockObject&Query $query */ | ||
$query = $this->getMockBuilder(Query::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
|
||
// set mock returns | ||
$query->method('getQuery')->willReturn('SHOW TABLES;'); | ||
$query->method('debugToolbarDisplay')->willReturn('<strong>SHOW</strong> TABLES;'); | ||
$query->method('getDuration')->with(5)->willReturn('1.23456'); | ||
|
||
Database::collect($query); // <== $query will be called here | ||
$collector = new Database(); | ||
|
||
$queries = $collector->display()['queries']; | ||
|
||
$this->assertSame('1234.56 ms', $queries[0]['duration']); | ||
$this->assertSame('<strong>SHOW</strong> TABLES;', $queries[0]['sql']); | ||
$this->assertSame(clean_path(__FILE__) . ':35', $queries[0]['trace-file']); | ||
|
||
foreach ($queries[0]['trace'] as $trace) { | ||
// since we merged file & line together | ||
$this->assertArrayNotHasKey('line', $trace); | ||
$this->assertArrayHasKey('file', $trace); | ||
|
||
// since we dropped object & args in the backtrace for performance | ||
$this->assertArrayNotHasKey('object', $trace); | ||
$this->assertArrayNotHasKey('args', $trace); | ||
} | ||
} | ||
} |