Skip to content

Commit c1ca028

Browse files
committed
test fixes
1 parent 1ad6122 commit c1ca028

File tree

12 files changed

+85
-66
lines changed

12 files changed

+85
-66
lines changed

tests/Integration/BaseTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
/** @noinspection PhpUnhandledExceptionInspection */
3+
4+
declare(strict_types=1);
25

36
namespace MySQLReplication\Tests\Integration;
47

@@ -60,7 +63,6 @@ protected function setUp(): void
6063
self::assertInstanceOf(FormatDescriptionEventDTO::class, $this->getEvent());
6164
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
6265
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
63-
6466
}
6567

6668
public function connect(): void
@@ -88,8 +90,6 @@ protected function getEvent(): EventDTO
8890
return $this->currentEvent;
8991
}
9092
}
91-
92-
return $this->currentEvent;
9393
}
9494

9595
protected function tearDown(): void
@@ -99,18 +99,18 @@ protected function tearDown(): void
9999
$this->disconnect();
100100
}
101101

102-
protected function checkForVersion(float $version): bool
103-
{
104-
return (float)$this->connection->fetchOne('SELECT VERSION()') < $version;
105-
}
106-
107102
protected function disconnect(): void
108103
{
109104
$this->mySQLReplicationFactory->unregisterSubscriber($this->testEventSubscribers);
110105
$this->mySQLReplicationFactory = null;
111106
$this->connection = null;
112107
}
113108

109+
protected function checkForVersion(float $version): bool
110+
{
111+
return (float)$this->connection->fetchOne('SELECT VERSION()') < $version;
112+
}
113+
114114
protected function createAndInsertValue(string $createQuery, string $insertQuery): EventDTO
115115
{
116116
$this->connection->executeStatement($createQuery);

tests/Integration/BasicTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
<?php
2+
/** @noinspection PhpPossiblePolymorphicInvocationInspection */
3+
4+
/** @noinspection PhpUnhandledExceptionInspection */
25

36
declare(strict_types=1);
47

@@ -39,8 +42,8 @@ public function shouldGetDeleteEvent(): void
3942
/** @var DeleteRowsDTO $event */
4043
$event = $this->getEvent();
4144
self::assertInstanceOf(DeleteRowsDTO::class, $event);
42-
self::assertEquals($event->getValues()[0]['id'], 1);
43-
self::assertEquals($event->getValues()[0]['data'], 'Hello World');
45+
self::assertEquals(1, $event->getValues()[0]['id']);
46+
self::assertEquals('Hello World', $event->getValues()[0]['data']);
4447
}
4548

4649
/**
@@ -62,10 +65,10 @@ public function shouldGetUpdateEvent(): void
6265
/** @var UpdateRowsDTO $event */
6366
$event = $this->getEvent();
6467
self::assertInstanceOf(UpdateRowsDTO::class, $event);
65-
self::assertEquals($event->getValues()[0]['before']['id'], 1);
66-
self::assertEquals($event->getValues()[0]['before']['data'], 'Hello');
67-
self::assertEquals($event->getValues()[0]['after']['id'], 2);
68-
self::assertEquals($event->getValues()[0]['after']['data'], 'World');
68+
self::assertEquals(1, $event->getValues()[0]['before']['id']);
69+
self::assertEquals('Hello', $event->getValues()[0]['before']['data']);
70+
self::assertEquals(2, $event->getValues()[0]['after']['id']);
71+
self::assertEquals('World', $event->getValues()[0]['after']['data']);
6972
}
7073

7174
/**
@@ -240,7 +243,7 @@ public function shouldTruncateTable(): void
240243
public function shouldJsonSetPartialUpdateWithHoles(): void
241244
{
242245
if ($this->checkForVersion(5.7) || BinLogServerInfo::isMariaDb()) {
243-
$this->markTestIncomplete('Only for mysql 5.7 or higher');
246+
self::markTestIncomplete('Only for mysql 5.7 or higher');
244247
}
245248

246249
$expected = '{"age":22,"addr":{"code":100,"detail":{"ab":"970785C8 - C299"}},"name":"Alice"}';
@@ -250,7 +253,7 @@ public function shouldJsonSetPartialUpdateWithHoles(): void
250253

251254
$this->createAndInsertValue($create_query, $insert_query);
252255

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

255258
self::assertInstanceOf(XidDTO::class, $this->getEvent());
256259
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
@@ -276,7 +279,7 @@ public function shouldJsonSetPartialUpdateWithHoles(): void
276279
public function shouldJsonRemovePartialUpdateWithHoles(): void
277280
{
278281
if ($this->checkForVersion(5.7) || BinLogServerInfo::isMariaDb()) {
279-
$this->markTestIncomplete('Only for mysql 5.7 or higher');
282+
self::markTestIncomplete('Only for mysql 5.7 or higher');
280283
}
281284

282285
$expected = '{"age":22,"addr":{"code":100,"detail":{"ab":"970785C8-C299"}},"name":"Alice"}';
@@ -312,7 +315,7 @@ public function shouldJsonRemovePartialUpdateWithHoles(): void
312315
public function shouldJsonReplacePartialUpdateWithHoles(): void
313316
{
314317
if ($this->checkForVersion(5.7) || BinLogServerInfo::isMariaDb()) {
315-
$this->markTestIncomplete('Only for mysql 5.7 or higher');
318+
self::markTestIncomplete('Only for mysql 5.7 or higher');
316319
}
317320

318321
$expected = '{"age":22,"addr":{"code":100,"detail":{"ab":"970785C8-C299"}},"name":"Alice"}';

tests/Integration/TestEventSubscribers.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
declare(strict_types=1);
34

45
namespace MySQLReplication\Tests\Integration;

tests/Integration/TypesTest.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
<?php
2+
/** @noinspection PhpUnhandledExceptionInspection */
3+
4+
/** @noinspection PhpPossiblePolymorphicInvocationInspection */
5+
26
declare(strict_types=1);
37

48
namespace MySQLReplication\Tests\Integration;
@@ -275,9 +279,9 @@ public function shouldBeTimestampMySQL56(): void
275279
* Since MariaDB 10.1, MariaDB has defaulted to the MySQL format ...
276280
*/
277281
if (BinLogServerInfo::isMariaDb() && $this->checkForVersion(10.1)) {
278-
$this->markTestIncomplete('Only for mariadb 10.1 or higher');
282+
self::markTestIncomplete('Only for mariadb 10.1 or higher');
279283
} elseif ($this->checkForVersion(5.6)) {
280-
$this->markTestIncomplete('Only for mysql 5.6 or higher');
284+
self::markTestIncomplete('Only for mysql 5.6 or higher');
281285
}
282286

283287
$create_query = 'CREATE TABLE test (test0 TIMESTAMP(0),
@@ -543,7 +547,8 @@ public function shouldBeBit(): void
543547
self::assertEquals('100010101101', $event->getValues()[0]['test3']);
544548
self::assertEquals('101100111', $event->getValues()[0]['test4']);
545549
self::assertEquals(
546-
'1101011010110100100111100011010100010100101110111011101011011010', $event->getValues()[0]['test5']
550+
'1101011010110100100111100011010100010100101110111011101011011010',
551+
$event->getValues()[0]['test5']
547552
);
548553
}
549554

@@ -700,7 +705,8 @@ public function shouldBeGeometry(): void
700705
$event = $this->createAndInsertValue($create_query, $insert_query);
701706

702707
self::assertEquals(
703-
'000000000101000000000000000000f03f000000000000f03f', bin2hex($event->getValues()[0]['test'])
708+
'000000000101000000000000000000f03f000000000000f03f',
709+
bin2hex($event->getValues()[0]['test'])
704710
);
705711
}
706712

@@ -740,7 +746,6 @@ public function shouldBeNull(): void
740746
self::assertNull($event->getValues()[0]['test3']);
741747
self::assertEquals(42, $event->getValues()[0]['test7']);
742748
self::assertEquals(84, $event->getValues()[0]['test20']);
743-
744749
}
745750

746751
/**
@@ -783,7 +788,7 @@ public function shouldBeEncodedUTF8(): void
783788
public function shouldBeJson(): void
784789
{
785790
if ($this->checkForVersion(5.7) || BinLogServerInfo::isMariaDb()) {
786-
$this->markTestIncomplete('Only for mysql 5.7 or higher');
791+
self::markTestIncomplete('Only for mysql 5.7 or higher');
787792
}
788793

789794
$create_query = 'CREATE TABLE t1 (i INT, j JSON)';

tests/Unit/BaseTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MySQLReplication\Tests\Unit;
46

57
use PHPUnit\Framework\TestCase;
68

7-
/**
8-
* Class BaseTest
9-
* @package MySQLReplication\Unit
10-
*/
119
abstract class BaseTest extends TestCase
1210
{
1311
}

tests/Unit/BinaryDataReader/BinaryDataReaderTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
2+
/** @noinspection PhpUnhandledExceptionInspection */
3+
24
declare(strict_types=1);
35

4-
namespace BinaryDataReader\Unit;
6+
namespace MySQLReplication\Tests\Unit\BinaryDataReader;
57

68
use MySQLReplication\BinaryDataReader\BinaryDataReader;
79
use MySQLReplication\BinaryDataReader\BinaryDataReaderException;
@@ -167,7 +169,8 @@ public function shouldReadLengthCodedPascalString(): void
167169
{
168170
$expected = 255;
169171
self::assertSame(
170-
$expected, hexdec(
172+
$expected,
173+
hexdec(
171174
bin2hex(
172175
$this->getBinaryRead(pack('cc', 1, $expected))->readLengthString(1)
173176
)
@@ -209,7 +212,8 @@ public function shouldReadDouble(): void
209212
public function shouldReadTableId(): void
210213
{
211214
self::assertSame(
212-
'7456176998088', $this->getBinaryRead(pack('v3', 2570258120, 2570258120, 2570258120))->readTableId()
215+
'7456176998088',
216+
$this->getBinaryRead(pack('v3', 2570258120, 2570258120, 2570258120))->readTableId()
213217
);
214218
}
215219

tests/Unit/Cache/ArrayCacheTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
2+
/** @noinspection PhpUnhandledExceptionInspection */
3+
24
declare(strict_types=1);
35

4-
namespace BinaryDataReader\Unit;
6+
namespace MySQLReplication\Tests\Unit\Cache;
57

68
use MySQLReplication\Cache\ArrayCache;
79
use MySQLReplication\Config\ConfigBuilder;

tests/Unit/Config/ConfigTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?php
2+
/** @noinspection PhpUnhandledExceptionInspection */
3+
24
declare(strict_types=1);
35

4-
namespace BinaryDataReader\Unit;
6+
namespace MySQLReplication\Tests\Unit\Config;
57

68
use MySQLReplication\Config\Config;
79
use MySQLReplication\Config\ConfigBuilder;
@@ -145,7 +147,7 @@ public function shouldCheckHeartbeatPeriod($heartbeatPeriod): void
145147
$config = (new ConfigBuilder())->withHeartbeatPeriod($heartbeatPeriod)->build();
146148
$config::validate();
147149

148-
self::assertSame((float) $heartbeatPeriod, $config::getHeartbeatPeriod());
150+
self::assertSame((float)$heartbeatPeriod, $config::getHeartbeatPeriod());
149151
}
150152

151153
public function shouldValidateProvider(): array

tests/Unit/Event/RowEvent/TableMapTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
declare(strict_types=1);
34

45
namespace MySQLReplication\Tests\Unit\Event\RowEvent;
56

@@ -38,6 +39,7 @@ public function shouldMakeTableMap(): void
3839
self::assertSame($expected['columnDTOCollection'], $tableMap->getColumnDTOCollection());
3940

4041
self::assertInstanceOf(\JsonSerializable::class, $tableMap);
42+
/** @noinspection JsonEncodingApiUsageInspection */
4143
self::assertSame(json_encode($expected), json_encode($tableMap));
4244
}
4345
}
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace MySQLReplication\Tests\Unit\Gtid;
46

57
use MySQLReplication\Gtid\Gtid;
68
use MySQLReplication\Gtid\GtidCollection;
79
use MySQLReplication\Gtid\GtidException;
8-
use MySQLReplication\Gtid\GtidFactory;
910
use MySQLReplication\Tests\Unit\BaseTest;
1011

11-
/**
12-
* Class GtidCollectionTest
13-
* @package Unit\Gtid
14-
*/
1512
class GtidCollectionTest extends BaseTest
1613
{
1714
/**
1815
* @var GtidCollection
1916
*/
2017
private $gtidCollection;
2118

22-
/**
23-
* @throws GtidException
24-
*/
2519
public function setUp(): void
2620
{
2721
parent::setUp();
@@ -37,22 +31,26 @@ public function setUp(): void
3731
*/
3832
public function shouldGetEncodedLength(): void
3933
{
40-
$this->assertSame(88, $this->gtidCollection->getEncodedLength());
34+
self::assertSame(88, $this->gtidCollection->getEncodedLength());
4135
}
4236

4337
/**
4438
* @test
4539
*/
4640
public function shouldGetEncoded(): void
4741
{
48-
$this->assertSame('02000000000000009b1c8d182a7611e5a26b000c2976f3f301000000000000000100000000000000b8b5020000000000bbbbbbbbccccffffddddaaaaaaaaaaaa010000000000000001000000000000000200000000000000', bin2hex($this->gtidCollection->getEncoded()));
42+
self::assertSame(
43+
'02000000000000009b1c8d182a7611e5a26b000c2976f3f301000000000000000100000000000000b8b5020000000000bbbbbbbbccccffffddddaaaaaaaaaaaa010000000000000001000000000000000200000000000000',
44+
bin2hex($this->gtidCollection->getEncoded())
45+
);
4946
}
5047

5148
/**
5249
* @test
50+
* @throws GtidException
5351
*/
54-
public function shouldCreateCollection()
52+
public function shouldCreateCollection(): void
5553
{
56-
$this->assertInstanceOf(GtidCollection::class, GtidCollection::makeCollectionFromString('9b1c8d18-2a76-11e5-a26b-000c2976f3f3:1-177592'));
54+
self::assertCount(1, GtidCollection::makeCollectionFromString('9b1c8d18-2a76-11e5-a26b-000c2976f3f3:1-177592'));
5755
}
5856
}

0 commit comments

Comments
 (0)