Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Jul 28, 2024
1 parent a6efb5b commit 9b409d7
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/Auditor/ForeignKeyColumnNameMismatchMysqlAuditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace Orisai\DbAudit\Auditor;

/**
* TODO
* - chybějící cizí klíč u sloupce odpovídajícího patternu
* - cizí klíč u sloupce neodpovídajícího patternu
*/
final class ForeignKeyColumnNameMismatchMysqlAuditor extends ForeignKeyColumnNameMismatchAuditor
{

public function analyse(): array
{
// TODO: Implement analyse() method.
// - chybějící cizí klíč u sloupce odpovídajícího patternu
// - cizí klíč u sloupce neodpovídajícího patternu
// - pattern config - regex?
// - foo_id
// - fkFoo
return [];
}

Expand Down
3 changes: 3 additions & 0 deletions src/Auditor/OutdatedCollationMysqlAuditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ final class OutdatedCollationMysqlAuditor extends OutdatedCollationAuditor
public function analyse(): array
{
// TODO: Implement analyse() method.
// - pro začátek jednoduchý whitelist? / blacklist?
// - a kombinovat s character set
// - chceme ideálně upgradovat na kompatibilní set
return [];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,41 @@

use DateTime;
use DateTimeImmutable;
use Dibi\Connection;
use Dibi\Connection as DibiConnection;
use Generator;
use Nextras\Dbal\Connection as NextrasConnection;
use Orisai\DbAudit\Dbal\DbalAdapter;
use Orisai\DbAudit\Dbal\DibiAdapter;
use Orisai\DbAudit\Dbal\NextrasAdapter;
use PHPUnit\Framework\TestCase;
use Tests\Orisai\DbAudit\Helper\MysqlConnectionConfig;

final class DibiAdapterTest extends TestCase
final class DbalAdapterTest extends TestCase
{

public function testMysql(): void
public function provide(): Generator
{
$dbal = new DibiAdapter(new Connection([
'driver' => 'mysqli',
'host' => '127.0.0.1',
'port' => (int) '3306',
'user' => 'root',
'password' => 'root',
]));
$config = new MysqlConnectionConfig(
'127.0.0.1',
'root',
'root',
(int) '3306',
);

yield [
new DibiAdapter(new DibiConnection($config->toDibi())),
];

yield [
new NextrasAdapter(new NextrasConnection($config->toNextras())),
];
}

/**
* @dataProvider provide
*/
public function test(DbalAdapter $dbal): void
{
$query = $dbal->query('SELECT version() as version;');

self::assertCount(1, $query);
Expand Down
51 changes: 51 additions & 0 deletions tests/Unit/Report/ColumnViolationSourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php declare(strict_types = 1);

namespace Tests\Orisai\DbAudit\Unit\Report;

use Orisai\DbAudit\Report\ColumnViolationSource;
use PHPUnit\Framework\TestCase;

final class ColumnViolationSourceTest extends TestCase
{

public function testBasic(): void
{
$source = new ColumnViolationSource('database', null, 'table', 'column');

self::assertSame('database', $source->getDatabase());
self::assertNull($source->getSchema());
self::assertSame('table', $source->getTable());
self::assertSame('column', $source->getColumn());

self::assertNull($source->getColumnType());

self::assertSame(
'[table][column]',
$source->toString(),
);
self::assertSame(
$source->toString(),
(string) $source,
);
}

public function testSchema(): void
{
$source = new ColumnViolationSource('database2', 'schema2', 'table2', 'column2');

self::assertSame('database2', $source->getDatabase());
self::assertSame('schema2', $source->getSchema());
self::assertSame('table2', $source->getTable());
self::assertSame('column2', $source->getColumn());

self::assertSame(
'[schema2][table2][column2]',
$source->toString(),
);
self::assertSame(
$source->toString(),
(string) $source,
);
}

}
47 changes: 47 additions & 0 deletions tests/Unit/Report/TableViolationSourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php declare(strict_types = 1);

namespace Tests\Orisai\DbAudit\Unit\Report;

use Orisai\DbAudit\Report\TableViolationSource;
use PHPUnit\Framework\TestCase;

final class TableViolationSourceTest extends TestCase
{

public function testBasic(): void
{
$source = new TableViolationSource('database', null, 'table');

self::assertSame('database', $source->getDatabase());
self::assertNull($source->getSchema());
self::assertSame('table', $source->getTable());

self::assertSame(
'[table]',
$source->toString(),
);
self::assertSame(
$source->toString(),
(string) $source,
);
}

public function testSchema(): void
{
$source = new TableViolationSource('database2', 'schema2', 'table2');

self::assertSame('database2', $source->getDatabase());
self::assertSame('schema2', $source->getSchema());
self::assertSame('table2', $source->getTable());

self::assertSame(
'[schema2][table2]',
$source->toString(),
);
self::assertSame(
$source->toString(),
(string) $source,
);
}

}
22 changes: 22 additions & 0 deletions tests/Unit/Report/ViolationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace Tests\Orisai\DbAudit\Unit\Report;

use Orisai\DbAudit\Report\TableViolationSource;
use Orisai\DbAudit\Report\Violation;
use PHPUnit\Framework\TestCase;

final class ViolationTest extends TestCase
{

public function test(): void
{
$source = new TableViolationSource('database', null, 'table');
$violation = new Violation('key', 'message', $source);

self::assertSame('key', $violation->getKey());
self::assertSame('message', $violation->getMessage());
self::assertSame($source, $violation->getSource());
}

}

0 comments on commit 9b409d7

Please sign in to comment.