These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php declare(strict_types=1); |
||
2 | |||
3 | namespace Portiny\Doctrine\Tests\Adapter\Nette\Tracy; |
||
4 | |||
5 | use Doctrine\ORM\EntityManager; |
||
6 | use Portiny\Doctrine\Adapter\Nette\Tracy\DoctrineSQLPanel; |
||
7 | use Portiny\Doctrine\Tests\AbstractContainerTestCase; |
||
8 | |||
9 | class DoctrineSQLPanelTest extends AbstractContainerTestCase |
||
10 | { |
||
11 | /** |
||
12 | * @var DoctrineSQLPanel |
||
13 | */ |
||
14 | private $doctrineSQLPanel; |
||
15 | |||
16 | protected function setUp(): void |
||
17 | { |
||
18 | parent::setUp(); |
||
19 | |||
20 | /** @var EntityManager $entityManager */ |
||
21 | $entityManager = $this->container->getByType(EntityManager::class); |
||
22 | $this->doctrineSQLPanel = new DoctrineSQLPanel($entityManager); |
||
23 | } |
||
24 | |||
25 | public function testStartQuery(): void |
||
26 | { |
||
27 | $this->doctrineSQLPanel->startQuery('SELECT 1 FROM dual', NULL, NULL); |
||
28 | $this->doctrineSQLPanel->stopQuery(); |
||
29 | |||
30 | $queries = $this->doctrineSQLPanel->getQueries(); |
||
31 | self::assertCount(1, $queries); |
||
32 | self::assertSame('SELECT 1 FROM dual', reset($queries)[0]); |
||
33 | } |
||
34 | |||
35 | public function testStopQuery(): void |
||
36 | { |
||
37 | $this->doctrineSQLPanel->startQuery('SELECT 1 FROM dual', NULL, NULL); |
||
38 | sleep(1); |
||
39 | $this->doctrineSQLPanel->stopQuery(); |
||
40 | |||
41 | $queries = $this->doctrineSQLPanel->getQueries(); |
||
42 | $firstQuery = reset($queries); |
||
43 | |||
44 | self::assertCount(1, $queries); |
||
45 | self::assertSame('SELECT 1 FROM dual', $firstQuery[0]); |
||
46 | self::assertTrue($firstQuery[3] > 0); |
||
47 | } |
||
48 | |||
49 | View Code Duplication | public function testGetTab(): void |
|
0 ignored issues
–
show
|
|||
50 | { |
||
51 | self::assertContains('<span title="Doctrine 2">', $this->doctrineSQLPanel->getTab()); |
||
52 | self::assertContains('0 queries', $this->doctrineSQLPanel->getTab()); |
||
53 | |||
54 | $this->doctrineSQLPanel->startQuery('SELECT 1 FROM dual', NULL, NULL); |
||
55 | $this->doctrineSQLPanel->stopQuery(); |
||
56 | |||
57 | self::assertContains('1 queries', $this->doctrineSQLPanel->getTab()); |
||
58 | } |
||
59 | |||
60 | View Code Duplication | public function testGetPanel(): void |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
61 | { |
||
62 | self::assertContains('<h2>Queries</h2>', $this->doctrineSQLPanel->getPanel()); |
||
63 | |||
64 | $this->doctrineSQLPanel->startQuery('SELECT 1 FROM dual', NULL, NULL); |
||
65 | $this->doctrineSQLPanel->stopQuery(); |
||
66 | |||
67 | self::assertContains('<h1>Queries: 1, time:', $this->doctrineSQLPanel->getPanel()); |
||
68 | } |
||
69 | } |
||
70 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.