Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getting table name when the table schema is an empty string #617

Merged
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
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));
}
}
Loading