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

Tests incompatible with doctrine/dbal 3.x #12

Open
Kleinast opened this issue Feb 21, 2022 · 1 comment
Open

Tests incompatible with doctrine/dbal 3.x #12

Kleinast opened this issue Feb 21, 2022 · 1 comment

Comments

@Kleinast
Copy link

I forked the project to try fix an issue I have with update doctrine/dbal 3.x and it seem some tests doesn't work at all with doctrine/dbal 3.x

@aso824
Copy link

aso824 commented Mar 7, 2023

Quick fix for it - create your DBALConnection class, like mine:

use ComPHPPuebla\Fixtures\Database\DBALConnection as BaseDBALConnection;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Column;

final class DBALConnection extends BaseDBALConnection
{
    private Connection $connection;

    public function __construct(Connection $connection)
    {
        parent::__construct($connection);

        $this->connection = $connection;
    }

    public function primaryKeyOf(string $table): string
    {
        $schema = $this->connection->createSchemaManager();

        $primaryKeys = $schema->listTableDetails($table)->getPrimaryKeyColumns();

        /** @var Column|null $firstPrimaryKey */
        $firstPrimaryKey = reset($primaryKeys);

        return $firstPrimaryKey->getName();
    }
}

Symfony config:

  when@test:
      services:
          App\Core\Infrastructure\Fixtures\DBALConnection:
              arguments:
                  $connection: '@doctrine.dbal.default_connection'
  
          ComPHPPuebla\Fixtures\Fixture:
              arguments:
                  $connection: '@App\Core\Infrastructure\Fixtures\DBALConnection'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants