Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/MySQLReplication/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,23 @@ public function validate(): void

public function checkDataBasesOnly(string $database): bool
{
return ($this->databasesOnly !== [] && !in_array($database, $this->databasesOnly, true))
|| ($this->databasesRegex !== [] && !self::matchNames($database, $this->databasesRegex));
if ($this->databasesOnly === [] && $this->databasesRegex === []) {
return false;
}

return !in_array($database, $this->databasesOnly, true)
&& !self::matchNames($database, $this->databasesRegex);
}


public function checkTablesOnly(string $table): bool
{
return ($this->tablesOnly !== [] && !in_array($table, $this->tablesOnly, true))
|| ($this->tablesRegex !== [] && !self::matchNames($table, $this->tablesRegex));
if ($this->tablesOnly === [] && $this->tablesRegex === []) {
return false;
}

return !in_array($table, $this->tablesOnly, true)
&& !self::matchNames($table, $this->tablesRegex);
}

public function checkEvent(int $type): bool
Expand Down
28 changes: 28 additions & 0 deletions tests/Unit/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ public function testShouldCheckDataBasesOnly(): void
self::assertFalse($config->checkDataBasesOnly('foo_123'));
}

public function testShouldCheckDataBasesOnlyListAndRegex(): void
{
$config = (new ConfigBuilder())
->withDatabasesOnly(['foo'])
->withDatabasesRegex(['/^instance\d+$/'])
->build();
self::assertFalse($config->checkDataBasesOnly('foo'));
self::assertFalse($config->checkDataBasesOnly('instance1'));
self::assertFalse($config->checkDataBasesOnly('instance123'));
self::assertTrue($config->checkDataBasesOnly('bar'));
self::assertTrue($config->checkDataBasesOnly('instance'));
self::assertTrue($config->checkDataBasesOnly('instanceX'));
}

public function testShouldCheckTablesOnly(): void
{
$config = (new ConfigBuilder())->build();
Expand All @@ -120,6 +134,20 @@ public function testShouldCheckTablesOnly(): void
self::assertFalse($config->checkTablesOnly('foo_123'));
}

public function testShouldCheckTablesOnlyListAndRegex(): void
{
$config = (new ConfigBuilder())
->withTablesOnly(['foo'])
->withTablesRegex(['/^instance\d+$/'])
->build();
self::assertFalse($config->checkTablesOnly('foo'));
self::assertFalse($config->checkTablesOnly('instance1'));
self::assertFalse($config->checkTablesOnly('instance123'));
self::assertTrue($config->checkTablesOnly('bar'));
self::assertTrue($config->checkTablesOnly('instance'));
self::assertTrue($config->checkTablesOnly('instanceX'));
}

public function testShouldCheckEvent(): void
{
$config = (new ConfigBuilder())->build();
Expand Down