Skip to content

Commit

Permalink
Fix getting table name when the table schema is an empty string (#617)
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Coder264 authored Apr 17, 2024
1 parent 0e5091b commit a38edf4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AuditConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getTableName(ClassMetadataInfo $metadata)
{
$tableName = $metadata->getTableName();

if (null !== $metadata->getSchemaName()) {
if (null !== $metadata->getSchemaName() && '' !== $metadata->getSchemaName()) {
$tableName = $metadata->getSchemaName().'.'.$tableName;
}

Expand Down
61 changes: 61 additions & 0 deletions tests/AuditConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\EntityAuditBundle\Tests;

use Doctrine\ORM\Mapping\ClassMetadata;
use PHPUnit\Framework\TestCase;
use SimpleThings\EntityAudit\AuditConfiguration;
use Sonata\EntityAuditBundle\Tests\Fixtures\Core\ArticleAudit;

final class AuditConfigurationTest extends TestCase
{
public function testItReturnsCorrectTableNameWhenTableSchemaIsNull(): void
{
$auditConfig = new AuditConfiguration();

$metadata = new ClassMetadata(ArticleAudit::class);
$metadata->setPrimaryTable([
'name' => 'foo',
'schema' => null,
]);

static::assertSame('foo_audit', $auditConfig->getTableName($metadata));
}

public function testItReturnsCorrectTableNameWhenTableSchemaIsEmptyString(): void
{
$auditConfig = new AuditConfiguration();

$metadata = new ClassMetadata(ArticleAudit::class);
$metadata->setPrimaryTable([
'name' => 'foo',
'schema' => '',
]);

static::assertSame('foo_audit', $auditConfig->getTableName($metadata));
}

public function testItReturnsCorrectTableNameWhenTableSchemaIsSet(): void
{
$auditConfig = new AuditConfiguration();

$metadata = new ClassMetadata(ArticleAudit::class);
$metadata->setPrimaryTable([
'name' => 'foo',
'schema' => 'xyz',
]);

static::assertSame('xyz.foo_audit', $auditConfig->getTableName($metadata));
}
}

0 comments on commit a38edf4

Please sign in to comment.