Skip to content

Commit c310edb

Browse files
committed
Merge branch 'krowinski-master'
2 parents f0fa732 + 2e87e3c commit c310edb

File tree

5 files changed

+43
-34
lines changed

5 files changed

+43
-34
lines changed

.github/workflows/tests.yml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,25 @@ jobs:
66

77
strategy:
88
matrix:
9-
php: [ '8.2' ]
9+
php: [ '8.2', '8.3', '8.4' ]
1010
mysql-version: [ '5.7', '8.0', '8.4' ]
1111

12-
services:
13-
mysql:
14-
image: "mysql:${{ matrix.mysql-version }}"
15-
env:
16-
MYSQL_ROOT_PASSWORD: root
17-
MYSQL_DATABASE: mysqlreplication_test
18-
ports:
19-
- 3306/tcp
20-
2112
steps:
2213
- name: Checkout
2314
uses: actions/checkout@v2
2415

25-
- name: Start mysql service
26-
run: |
27-
echo -e "\n[mysqld]\nserver-id=1\nbinlog_format=row\nlog_bin=/var/log/mysql/mysql-bin.log\nbinlog_rows_query_log_events=ON" | sudo tee -a /etc/mysql/my.cnf
28-
sudo /etc/init.d/mysql start
29-
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql -proot
16+
- uses: shogo82148/actions-setup-mysql@v1
17+
with:
18+
mysql-version: "${{ matrix.mysql-version }}"
19+
my-cnf: |
20+
server-id=1
21+
binlog_format=row
22+
binlog_rows_query_log_events=ON
23+
log_bin=binlog
24+
root-password: root
25+
26+
- name: set up timezones
27+
run: mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root mysql -proot
3028

3129
- name: Setup PHP, with composer and extensions
3230
uses: shivammathur/setup-php@v2
@@ -39,7 +37,7 @@ jobs:
3937

4038
- name: Cache Composer packages
4139
id: composer-cache
42-
uses: actions/cache@v2
40+
uses: actions/cache@v4
4341
with:
4442
path: vendor
4543
key: ${{ runner.os }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}

src/MySQLReplication/Event/RowsQueryEvent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ class RowsQueryEvent extends EventCommon
1616
{
1717
public function makeRowsQueryDTO(): RowsQueryDTO
1818
{
19-
// $this->binaryDataReader->advance(1);
19+
$this->binaryDataReader->advance(1);
2020
return new RowsQueryDTO(
2121
$this->eventInfo,
22-
$this->binaryDataReader->read($this->binaryDataReader->readInt8()),
22+
$this->binaryDataReader->read($this->eventInfo->getSizeNoHeader() - 1),
2323
);
2424
}
2525
}

src/MySQLReplication/MySQLReplicationFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class MySQLReplicationFactory
3333

3434
public function __construct(
3535
Config $config,
36-
RepositoryInterface|null $repository = null,
37-
CacheInterface|null $cache = null,
38-
EventDispatcherInterface|null $eventDispatcher = null,
39-
SocketInterface|null $socket = null,
40-
LoggerInterface|null $logger = null
36+
?RepositoryInterface $repository = null,
37+
?CacheInterface $cache = null,
38+
?EventDispatcherInterface $eventDispatcher = null,
39+
?SocketInterface $socket = null,
40+
?LoggerInterface $logger = null
4141
) {
4242
$config->validate();
4343

src/MySQLReplication/Repository/MySQLRepository.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,14 @@ public function getVersion(): string
6565

6666
public function getMasterStatus(): MasterStatusDTO
6767
{
68-
if(version_compare($this->getVersion(),"8.4.0")>=0){
69-
$data = $this->getConnection()
70-
->fetchAssociative('SHOW BINARY LOG STATUS');
71-
}else{
72-
$data = $this->getConnection()
73-
->fetchAssociative('SHOW MASTER STATUS');
74-
}
68+
$query = 'SHOW MASTER STATUS';
69+
70+
if (str_starts_with($this->getVersion(), '8.4')) {
71+
$query = 'SHOW BINARY LOG STATUS';
72+
}
73+
74+
$data = $this->getConnection()
75+
->fetchAssociative($query);
7576
if (empty($data)) {
7677
throw new BinLogException(
7778
MySQLReplicationException::BINLOG_NOT_ENABLED,

tests/Integration/RowsQueryTest.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44

55
namespace MySQLReplication\Tests\Integration;
66

7+
use Generator;
78
use MySQLReplication\Definitions\ConstEventType;
89
use MySQLReplication\Event\DTO\QueryDTO;
910
use MySQLReplication\Event\DTO\RowsQueryDTO;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1012

1113
final class RowsQueryTest extends BaseCase
1214
{
13-
public function testThatTheEditingQueryIsReadFromBinLog(): void
15+
#[DataProvider('provideQueries')]
16+
public function testThatTheEditingQueryIsReadFromBinLog(string $query): void
1417
{
1518
$this->connection->executeStatement(
1619
'CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))'
1720
);
1821

19-
$insertQuery = 'INSERT INTO test (data) VALUES(\'Hello\') /* Foo:Bar; */';
20-
$this->connection->executeStatement($insertQuery);
22+
$this->connection->executeStatement($query);
2123

2224
// The Create Table Query ... irrelevant content for this test
2325
self::assertInstanceOf(QueryDTO::class, $this->getEvent());
@@ -26,7 +28,15 @@ public function testThatTheEditingQueryIsReadFromBinLog(): void
2628

2729
$rowsQueryEvent = $this->getEvent();
2830
self::assertInstanceOf(RowsQueryDTO::class, $rowsQueryEvent);
29-
self::assertSame($insertQuery, $rowsQueryEvent->query);
31+
self::assertSame($query, $rowsQueryEvent->query);
32+
}
33+
34+
public static function provideQueries(): Generator
35+
{
36+
yield 'Short Query' => ['INSERT INTO test (data) VALUES(\'Hello\') /* Foo:Bar; */'];
37+
38+
$comment = '/* Foo:Bar; Bar:Baz; Baz:Quo; Quo:Foo; Quo:Foo; Quo:Foo; Quo:Foo; Foo:Baz; */';
39+
yield 'Extra Long Query' => [$comment . ' INSERT INTO test (data) VALUES(\'Hello\') ' . $comment];
3040
}
3141

3242
protected function getIgnoredEvents(): array

0 commit comments

Comments
 (0)