Merge pull request #19552 from kamil-tekiela/Fix-default-values
[phpmyadmin.git] / tests / unit / Dbal / DbiMysqliTest.php
blobf90e26bc52148aba8fe8e124567754812c149174
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests\Dbal;
7 use mysqli;
8 use mysqli_result;
9 use PhpMyAdmin\Dbal\Connection;
10 use PhpMyAdmin\Dbal\DbiMysqli;
11 use PhpMyAdmin\Dbal\MysqliResult;
12 use PhpMyAdmin\Tests\AbstractTestCase;
13 use PHPUnit\Framework\Attributes\CoversClass;
15 #[CoversClass(DbiMysqli::class)]
16 #[CoversClass(Connection::class)]
17 class DbiMysqliTest extends AbstractTestCase
19 protected DbiMysqli $object;
21 /**
22 * Sets up the fixture, for example, opens a network connection.
23 * This method is called before a test is executed.
25 protected function setUp(): void
27 parent::setUp();
29 $this->object = new DbiMysqli();
32 public function testGetClientInfo(): void
34 self::assertNotEmpty($this->object->getClientInfo());
37 /**
38 * Test for selectDb
40 public function testSelectDb(): void
42 $databaseName = 'test';
43 $mysqli = self::createMock(mysqli::class);
44 $mysqli->expects(self::once())
45 ->method('select_db')
46 ->with(self::equalTo($databaseName))
47 ->willReturn(true);
49 self::assertTrue($this->object->selectDb($databaseName, new Connection($mysqli)));
52 /**
53 * Test for realMultiQuery
55 public function testRealMultiQuery(): void
57 $query = 'test';
58 $mysqli = self::createMock(mysqli::class);
59 $mysqli->expects(self::once())
60 ->method('multi_query')
61 ->with(self::equalTo($query))
62 ->willReturn(true);
64 self::assertTrue($this->object->realMultiQuery(new Connection($mysqli), $query));
67 /**
68 * Test for realQuery
70 public function testrealQuery(): void
72 $query = 'test';
73 $mysqliResult = self::createMock(mysqli_result::class);
74 $mysqli = self::createMock(mysqli::class);
75 $mysqli->expects(self::once())
76 ->method('query')
77 ->with(self::equalTo($query))
78 ->willReturn($mysqliResult);
80 self::assertInstanceOf(MysqliResult::class, $this->object->realQuery($query, new Connection($mysqli)));
83 /**
84 * Test for nextResult
86 public function testNextResult(): void
88 $mysqli = self::createMock(mysqli::class);
89 $mysqli->expects(self::once())
90 ->method('next_result')
91 ->willReturn(true);
93 self::assertTrue($this->object->nextResult(new Connection($mysqli)));
96 /**
97 * Test for storeResult
99 public function testStoreResult(): void
101 $mysqli = self::createMock(mysqli::class);
102 $mysqliResult = self::createMock(mysqli_result::class);
103 $mysqli->expects(self::once())
104 ->method('store_result')
105 ->willReturn($mysqliResult);
107 self::assertInstanceOf(MysqliResult::class, $this->object->storeResult(new Connection($mysqli)));
111 * Test for escapeString
113 public function testEscapeString(): void
115 $string = 'test';
116 $mysqli = self::createMock(mysqli::class);
117 $mysqli->expects(self::once())
118 ->method('real_escape_string')
119 ->willReturn($string);
121 self::assertSame($string, $this->object->escapeString(new Connection($mysqli), $string));
124 public function testGetWarningCount(): void
126 $mysqli = (object) ['warning_count' => 30];
127 self::assertSame(30, $this->object->getWarningCount(new Connection($mysqli)));