class DatabaseFixtureProvider
    extends Base
Public API: explicitly declared with @visibility public.

Faker provider that generates fixtures from database tables via PDO.

Automatically detects the database driver (MySQL, PostgreSQL, SQLite) and the release of the server, and uses the appropriate schema fetcher and type mapper.

Generate a fixture from a live SQLite tabledoctest
$pdo = new \PDO('sqlite::memory:');
    $pdo->exec('CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL)');
    $provider = new \SqlFixture\Provider\DatabaseFixtureProvider(\Faker\Factory::create(), $pdo);
    $provider->fixture('users', ['name' => 'Alice']) // => ['name' => 'Alice']
Read the release of the connected serverdoctest
$provider = new \SqlFixture\Provider\DatabaseFixtureProvider(\Faker\Factory::create(), new \PDO('sqlite::memory:'));
    $provider->getVersion() // => 'sqlite-3.47.2'

Methods§

public function __construct(
    Generator $faker,
    PDO $connection,
    ?TypeMapperInterface $typeMapper = null,
    ?HydratorInterface $hydrator = null,
    ?SchemaFetcherInterface $schemaFetcher = null,
    string|null $version = null,
)

Initializes the collaborators and declared state for this object.

Parameters

$fakerGenerator
$connectionPDO
$typeMapper?TypeMapperInterface
$hydrator?HydratorInterface
$schemaFetcher?SchemaFetcherInterface
$versionstring|nullVersion tag such as 'mysql-8.4.7', or null to match the release the server reports

Throws

DriverDetectionException If the connection does not report a driver name or a server version
UnsupportedDriverException If the driver of the connection is not supported
UnsupportedVersionException If the version tag is not a supported release of the driver
Calls 8
public function fixture<T of object>(
    string $tableName,
    array<string, mixed> $overrides = [],
    class-string<T>|null $className = null,
): ($className is null ? array<string, mixed> : T)
public function clearCache(): void

Clear the schema cache.

Test cases 1
Calls 1
public function getFixtureGenerator(): FixtureGenerator

Get the underlying fixture generator.

Test cases 1
public function getDriver(): string

Private surface 5§

Implementation details, listed for orientation only.

private FixtureGenerator $fixtureGenerator
private SchemaFetcherInterface $schemaFetcher
private string $driver
private ServerVersion $version
private DatabaseSchemaCache $schemaCache

Test cases 19§

Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.

Dedicated tests 11
Other tests reaching this symbol 8