Skip to content

Commit db02005

Browse files
committed
Fixed PHPUnit.
1 parent 9bf6b5e commit db02005

File tree

8 files changed

+62
-57
lines changed

8 files changed

+62
-57
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"psr/simple-cache": "^1.0"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "^7.0"
26+
"phpunit/phpunit": "^9.0"
2727
},
2828
"license": "MIT",
2929
"authors": [

src/MySQLReplication/Event/RowEvent/RowEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ protected function getDecimal(ColumnDTO $columnDTO): string
662662
$res .= sprintf('%0' . $compFractional . 'd', $value);
663663
}
664664

665-
return bcmul($res, '1', $columnDTO->getPrecision());
665+
return bcmul($res, '1', $columnDTO->getDecimals());
666666
}
667667

668668
protected function getDatetime(): ?string

tests/Integration/BaseTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ public function connect(): void
7171

7272
$this->connection = $this->mySQLReplicationFactory->getDbConnection();
7373

74-
$this->connection->exec('SET SESSION time_zone = "UTC"');
75-
$this->connection->exec('DROP DATABASE IF EXISTS ' . $this->database);
76-
$this->connection->exec('CREATE DATABASE ' . $this->database);
77-
$this->connection->exec('USE ' . $this->database);
78-
$this->connection->exec('SET SESSION sql_mode = \'\';');
74+
$this->connection->executeStatement('SET SESSION time_zone = "UTC"');
75+
$this->connection->executeStatement('DROP DATABASE IF EXISTS ' . $this->database);
76+
$this->connection->executeStatement('CREATE DATABASE ' . $this->database);
77+
$this->connection->executeStatement('USE ' . $this->database);
78+
$this->connection->executeStatement('SET SESSION sql_mode = \'\';');
7979
}
8080

8181
protected function getEvent(): EventDTO
@@ -101,7 +101,7 @@ protected function tearDown(): void
101101

102102
protected function checkForVersion(float $version): bool
103103
{
104-
return (float)$this->connection->fetchColumn('SELECT VERSION()') < $version;
104+
return (float)$this->connection->fetchOne('SELECT VERSION()') < $version;
105105
}
106106

107107
protected function disconnect(): void
@@ -113,13 +113,13 @@ protected function disconnect(): void
113113

114114
protected function createAndInsertValue(string $createQuery, string $insertQuery): EventDTO
115115
{
116-
$this->connection->exec($createQuery);
117-
$this->connection->exec($insertQuery);
116+
$this->connection->executeStatement($createQuery);
117+
$this->connection->executeStatement($insertQuery);
118118

119119
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
120120
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
121121
self::assertInstanceOf(TableMapDTO::class, $this->getEvent());
122122

123123
return $this->getEvent();
124124
}
125-
}
125+
}

tests/Integration/BasicTest.php

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function shouldGetDeleteEvent(): void
3030
'INSERT INTO test (data) VALUES(\'Hello World\')'
3131
);
3232

33-
$this->connection->exec('DELETE FROM test WHERE id = 1');
33+
$this->connection->executeStatement('DELETE FROM test WHERE id = 1');
3434

3535
self::assertInstanceOf(XidDTO::class, $this->getEvent());
3636
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
@@ -53,7 +53,7 @@ public function shouldGetUpdateEvent(): void
5353
'INSERT INTO test (data) VALUES(\'Hello\')'
5454
);
5555

56-
$this->connection->exec('UPDATE test SET data = \'World\', id = 2 WHERE id = 1');
56+
$this->connection->executeStatement('UPDATE test SET data = \'World\', id = 2 WHERE id = 1');
5757

5858
self::assertInstanceOf(XidDTO::class, $this->getEvent());
5959
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
@@ -73,9 +73,9 @@ public function shouldGetUpdateEvent(): void
7373
*/
7474
public function shouldGetWriteEventDropTable(): void
7575
{
76-
$this->connection->exec($createExpected = 'CREATE TABLE `test` (id INTEGER(11))');
77-
$this->connection->exec('INSERT INTO `test` VALUES (1)');
78-
$this->connection->exec($dropExpected = 'DROP TABLE `test`');
76+
$this->connection->executeStatement($createExpected = 'CREATE TABLE `test` (id INTEGER(11))');
77+
$this->connection->executeStatement('INSERT INTO `test` VALUES (1)');
78+
$this->connection->executeStatement($dropExpected = 'DROP TABLE `test`');
7979

8080
/** @var QueryDTO $event */
8181
$event = $this->getEvent();
@@ -101,15 +101,15 @@ public function shouldGetWriteEventDropTable(): void
101101
/** @var QueryDTO $event */
102102
$event = $this->getEvent();
103103
self::assertInstanceOf(QueryDTO::class, $event);
104-
self::assertContains($dropExpected, $event->getQuery());
104+
self::assertStringContainsString($dropExpected, $event->getQuery());
105105
}
106106

107107
/**
108108
* @test
109109
*/
110110
public function shouldGetQueryEventCreateTable(): void
111111
{
112-
$this->connection->exec(
112+
$this->connection->executeStatement(
113113
$createExpected = 'CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))'
114114
);
115115

@@ -132,10 +132,10 @@ public function shouldDropColumn(): void
132132

133133
$this->connect();
134134

135-
$this->connection->exec('CREATE TABLE test_drop_column (id INTEGER(11), data VARCHAR(50))');
136-
$this->connection->exec('INSERT INTO test_drop_column VALUES (1, \'A value\')');
137-
$this->connection->exec('ALTER TABLE test_drop_column DROP COLUMN data');
138-
$this->connection->exec('INSERT INTO test_drop_column VALUES (2)');
135+
$this->connection->executeStatement('CREATE TABLE test_drop_column (id INTEGER(11), data VARCHAR(50))');
136+
$this->connection->executeStatement('INSERT INTO test_drop_column VALUES (1, \'A value\')');
137+
$this->connection->executeStatement('ALTER TABLE test_drop_column DROP COLUMN data');
138+
$this->connection->executeStatement('INSERT INTO test_drop_column VALUES (2)');
139139

140140
/** @var WriteRowsDTO $event */
141141
$event = $this->getEvent();
@@ -161,7 +161,7 @@ public function shouldFilterEvents(): void
161161
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
162162
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
163163

164-
$this->connection->exec($createTableExpected = 'CREATE TABLE test (id INTEGER(11), data VARCHAR(50))');
164+
$this->connection->executeStatement($createTableExpected = 'CREATE TABLE test (id INTEGER(11), data VARCHAR(50))');
165165

166166
/** @var QueryDTO $event */
167167
$event = $this->getEvent();
@@ -186,19 +186,19 @@ public function shouldFilterTables(): void
186186

187187
$this->connect();
188188

189-
$this->connection->exec(
189+
$this->connection->executeStatement(
190190
'CREATE TABLE test_2 (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))'
191191
);
192-
$this->connection->exec(
192+
$this->connection->executeStatement(
193193
'CREATE TABLE test_3 (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))'
194194
);
195-
$this->connection->exec(
195+
$this->connection->executeStatement(
196196
'CREATE TABLE test_4 (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))'
197197
);
198198

199-
$this->connection->exec('INSERT INTO test_4 (data) VALUES (\'foo\')');
200-
$this->connection->exec('INSERT INTO test_3 (data) VALUES (\'bar\')');
201-
$this->connection->exec('INSERT INTO test_2 (data) VALUES (\'' . $expectedValue . '\')');
199+
$this->connection->executeStatement('INSERT INTO test_4 (data) VALUES (\'foo\')');
200+
$this->connection->executeStatement('INSERT INTO test_3 (data) VALUES (\'bar\')');
201+
$this->connection->executeStatement('INSERT INTO test_2 (data) VALUES (\'' . $expectedValue . '\')');
202202

203203
$event = $this->getEvent();
204204
self::assertInstanceOf(WriteRowsDTO::class, $event);
@@ -222,9 +222,9 @@ public function shouldTruncateTable(): void
222222
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
223223
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
224224

225-
$this->connection->exec('CREATE TABLE test_truncate_column (id INTEGER(11), data VARCHAR(50))');
226-
$this->connection->exec('INSERT INTO test_truncate_column VALUES (1, \'A value\')');
227-
$this->connection->exec('TRUNCATE TABLE test_truncate_column');
225+
$this->connection->executeStatement('CREATE TABLE test_truncate_column (id INTEGER(11), data VARCHAR(50))');
226+
$this->connection->executeStatement('INSERT INTO test_truncate_column VALUES (1, \'A value\')');
227+
$this->connection->executeStatement('TRUNCATE TABLE test_truncate_column');
228228

229229
$event = $this->getEvent();
230230
self::assertSame('CREATE TABLE test_truncate_column (id INTEGER(11), data VARCHAR(50))', $event->getQuery());
@@ -250,7 +250,7 @@ public function shouldJsonSetPartialUpdateWithHoles(): void
250250

251251
$this->createAndInsertValue($create_query, $insert_query);
252252

253-
$this->connection->exec('UPDATE t1 SET j = JSON_SET(j, \'$.addr.detail.ab\', \'970785C8\')');
253+
$this->connection->executeStatementuteStatement('UPDATE t1 SET j = JSON_SET(j, \'$.addr.detail.ab\', \'970785C8\')');
254254

255255
self::assertInstanceOf(XidDTO::class, $this->getEvent());
256256
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
@@ -286,7 +286,7 @@ public function shouldJsonRemovePartialUpdateWithHoles(): void
286286

287287
$this->createAndInsertValue($create_query, $insert_query);
288288

289-
$this->connection->exec('UPDATE t1 SET j = JSON_REMOVE(j, \'$.addr.detail.ab\')');
289+
$this->connection->executeStatement('UPDATE t1 SET j = JSON_REMOVE(j, \'$.addr.detail.ab\')');
290290

291291
self::assertInstanceOf(XidDTO::class, $this->getEvent());
292292
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
@@ -322,7 +322,7 @@ public function shouldJsonReplacePartialUpdateWithHoles(): void
322322

323323
$this->createAndInsertValue($create_query, $insert_query);
324324

325-
$this->connection->exec('UPDATE t1 SET j = JSON_REPLACE(j, \'$.addr.detail.ab\', \'9707\')');
325+
$this->connection->executeStatement('UPDATE t1 SET j = JSON_REPLACE(j, \'$.addr.detail.ab\', \'9707\')');
326326

327327
self::assertInstanceOf(XidDTO::class, $this->getEvent());
328328
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
@@ -347,11 +347,11 @@ public function shouldJsonReplacePartialUpdateWithHoles(): void
347347
*/
348348
public function shouldRoteLog(): void
349349
{
350-
$this->connection->exec('FLUSH LOGS');
350+
$this->connection->executeStatement('FLUSH LOGS');
351351

352352
self::assertInstanceOf(RotateDTO::class, $this->getEvent());
353353

354-
self::assertRegExp(
354+
self::assertMatchesRegularExpression(
355355
'/^[a-z-]+\.[\d]+$/',
356356
$this->getEvent()->getEventInfo()->getBinLogCurrent()->getBinFileName()
357357
);
@@ -371,7 +371,7 @@ public function shouldUseProvidedEventDispatcher(): void
371371

372372
$this->connectWithProvidedEventDispatcher($eventDispatcher);
373373

374-
$this->connection->exec(
374+
$this->connection->executeStatement(
375375
$createExpected = 'CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))'
376376
);
377377

@@ -392,14 +392,14 @@ private function connectWithProvidedEventDispatcher(EventDispatcherInterface $ev
392392

393393
$this->connection = $this->mySQLReplicationFactory->getDbConnection();
394394

395-
$this->connection->exec('SET SESSION time_zone = "UTC"');
396-
$this->connection->exec('DROP DATABASE IF EXISTS ' . $this->database);
397-
$this->connection->exec('CREATE DATABASE ' . $this->database);
398-
$this->connection->exec('USE ' . $this->database);
399-
$this->connection->exec('SET SESSION sql_mode = \'\';');
395+
$this->connection->executeStatement('SET SESSION time_zone = "UTC"');
396+
$this->connection->executeStatement('DROP DATABASE IF EXISTS ' . $this->database);
397+
$this->connection->executeStatement('CREATE DATABASE ' . $this->database);
398+
$this->connection->executeStatement('USE ' . $this->database);
399+
$this->connection->executeStatement('SET SESSION sql_mode = \'\';');
400400

401401
self::assertInstanceOf(FormatDescriptionEventDTO::class, $this->getEvent());
402402
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
403403
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
404404
}
405-
}
405+
}

tests/Integration/TypesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ public function shouldBeNull(): void
747747
*/
748748
public function shouldBeEncodedLatin1(): void
749749
{
750-
$this->connection->exec('SET CHARSET latin1');
750+
$this->connection->executeStatement('SET CHARSET latin1');
751751

752752
$string = "\00e9";
753753

@@ -764,7 +764,7 @@ public function shouldBeEncodedLatin1(): void
764764
*/
765765
public function shouldBeEncodedUTF8(): void
766766
{
767-
$this->connection->exec('SET CHARSET utf8');
767+
$this->connection->executeStatement('SET CHARSET utf8');
768768

769769
$string = "\20ac";
770770

tests/Unit/Cache/ArrayCacheTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ArrayCacheTest extends BaseTest
1111
{
1212
private $arrayCache;
1313

14-
public function setUp()
14+
public function setUp(): void
1515
{
1616
parent::setUp();
1717
$this->arrayCache = new ArrayCache();
@@ -108,4 +108,4 @@ public function shouldHas(): void
108108
$this->arrayCache->set('foo', 'bar');
109109
self::assertTrue($this->arrayCache->has('foo'));
110110
}
111-
}
111+
}

tests/Unit/Gtid/GtidCollectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class GtidCollectionTest extends BaseTest
2222
/**
2323
* @throws GtidException
2424
*/
25-
public function setUp()
25+
public function setUp(): void
2626
{
2727
parent::setUp();
2828

@@ -55,4 +55,4 @@ public function shouldCreateCollection()
5555
{
5656
$this->assertInstanceOf(GtidCollection::class, GtidCollection::makeCollectionFromString('9b1c8d18-2a76-11e5-a26b-000c2976f3f3:1-177592'));
5757
}
58-
}
58+
}

tests/Unit/Repository/MySQLRepositoryTest.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use Doctrine\DBAL\Connection;
88
use Doctrine\DBAL\DBALException;
9+
use Doctrine\DBAL\Exception;
10+
use Doctrine\DBAL\Platforms\MySQLPlatform;
911
use MySQLReplication\Repository\FieldDTOCollection;
1012
use MySQLReplication\Repository\MasterStatusDTO;
1113
use MySQLReplication\Repository\MySQLRepository;
@@ -26,11 +28,12 @@ class MySQLRepositoryTest extends BaseTest
2628
*/
2729
private $connection;
2830

29-
public function setUp()
31+
public function setUp(): void
3032
{
3133
parent::setUp();
3234

3335
$this->connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
36+
$this->connection->method('getDatabasePlatform')->willReturn(new MySQLPlatform());
3437
$this->mySQLRepositoryTest = new MySQLRepository($this->connection);
3538
}
3639

@@ -50,7 +53,7 @@ public function shouldGetFields(): void
5053
]
5154
];
5255

53-
$this->connection->method('fetchAll')->willReturn($expected);
56+
$this->connection->method('fetchAllAssociative')->willReturn($expected);
5457

5558
self::assertEquals(FieldDTOCollection::makeFromArray($expected), $this->mySQLRepositoryTest->getFields('foo', 'bar'));
5659
}
@@ -63,7 +66,7 @@ public function shouldIsCheckSum(): void
6366
{
6467
self::assertFalse($this->mySQLRepositoryTest->isCheckSum());
6568

66-
$this->connection->method('fetchAssoc')->willReturnOnConsecutiveCalls(
69+
$this->connection->method('fetchAssociative')->willReturnOnConsecutiveCalls(
6770
['Value' => 'CRC32'],
6871
['Value' => 'NONE']
6972
);
@@ -83,7 +86,7 @@ public function shouldGetVersion(): void
8386
['Value' => '123'],
8487
];
8588

86-
$this->connection->method('fetchAll')->willReturn($expected);
89+
$this->connection->method('fetchAllAssociative')->willReturn($expected);
8790

8891
self::assertEquals('foobar123', $this->mySQLRepositoryTest->getVersion());
8992
}
@@ -101,7 +104,7 @@ public function shouldGetMasterStatus(): void
101104
'Executed_Gtid_Set' => '041de05f-a36a-11e6-bc73-000c2976f3f3:1-8023',
102105
];
103106

104-
$this->connection->method('fetchAssoc')->willReturn($expected);
107+
$this->connection->method('fetchAssociative')->willReturn($expected);
105108

106109
self::assertEquals(MasterStatusDTO::makeFromArray($expected), $this->mySQLRepositoryTest->getMasterStatus());
107110
}
@@ -121,8 +124,10 @@ public function shouldDestroy(): void
121124
public function shouldReconnect(): void
122125
{
123126
// just to cover private getConnection
124-
$this->connection->method('ping')->willReturn(false);
127+
$this->connection->method('executeQuery')->willReturnCallback(function(){
128+
throw new Exception();
129+
});
125130
$this->mySQLRepositoryTest->isCheckSum();
126131
self::assertTrue(true);
127132
}
128-
}
133+
}

0 commit comments

Comments
 (0)