Skip to content

Commit

Permalink
Fix test for the MariaDB v11.4.3 and v11.5.2 (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Sep 6, 2024
1 parent 5f8148a commit ed9f0e6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/Persistence/Sql/Expression.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ private function castGetValue($v): ?string
}

// for PostgreSQL/Oracle CLOB/BLOB datatypes and PDO driver
if (is_resource($v) && get_resource_type($v) === 'stream') { // @phpstan-ignore function.impossibleType
if (is_resource($v) && get_resource_type($v) === 'stream') {
$platform = $this->connection->getDatabasePlatform();
if ($platform instanceof PostgreSQLPlatform || $platform instanceof OraclePlatform) {
$v = stream_get_contents($v);
Expand Down
9 changes: 8 additions & 1 deletion tests/Schema/MigratorFkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

use Atk4\Data\Exception;
use Atk4\Data\Model;
use Atk4\Data\Persistence\Sql\Mysql\Connection as MysqlConnection;
use Atk4\Data\Schema\TestCase;
use Doctrine\DBAL\Exception as DbalException;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
Expand Down Expand Up @@ -227,7 +229,12 @@ public function testForeignKeyViolationDuringSetup(): void

$client->insert(['name' => 'Leos', 'country_id' => 10]);

$this->expectException(DbalException::class);
// remove if once https://jira.mariadb.org/browse/MDEV-34892 is fixed
if ($this->getDatabasePlatform() instanceof MySQLPlatform && MysqlConnection::isServerMariaDb($this->getConnection())) {
self::assertTrue(true); // @phpstan-ignore staticMethod.alreadyNarrowedType
} else {
$this->expectException(DbalException::class);
}
$this->createMigrator()->createForeignKey($client->getReference('country_id'));
}

Expand Down
39 changes: 12 additions & 27 deletions tests/Schema/MigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,18 @@ public function testCreateSetModel(): void
], $user->export());
}

public function testCreateSetModelIgnoreJoinField(): void
{
$model = new TestUserWithJoin($this->db);
$migrator = $this->createMigrator($model);

$modelFields = array_keys($model->getFields());
$migratorFields = array_keys($migrator->table->getColumns());

self::assertSame(['role_name'], array_values(array_diff($modelFields, $migratorFields)));
self::assertSame([], array_values(array_diff($migratorFields, $modelFields)));
}

public function testIntrospectTableToModelBasic(): void
{
$creatingMigrator = $this->createDemoMigrator('user')->create();
Expand Down Expand Up @@ -407,33 +419,6 @@ public function testIntrospectTableToModelSetPersistence(): void
self::assertTrue($model->issetPersistence());
self::assertSame(['id', 'a'], array_keys($model->getFields()));
}

public function testJoinFieldsAreNotCreated(): void
{
$model = new TestUserWithJoin($this->db);
$migrator = $this->createMigrator($model);
self::assertSame([
'id',
'name',
'password',
'is_admin',
'notes',
'main_role_id',
'role_id',
], array_keys($migrator->table->getColumns()));
$migrator->create();

$model = $this->createMigrator()->introspectTableToModel('user');
self::assertSame([
'id',
'name',
'password',
'is_admin',
'notes',
'main_role_id',
'role_id',
], array_keys($model->getFields()));
}
}

class TestUser extends Model
Expand Down

0 comments on commit ed9f0e6

Please sign in to comment.