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, SQLite) 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\DatabaseFixtureProvider(\Faker\Factory::create(), $pdo);
    $provider->fixture('users', ['name' => 'Alice']) // => ['name' => 'Alice']

Methods§

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

Initializes the collaborators and declared state for this object.

Parameters

$fakerGenerator
$connectionPDO
$typeMapper?TypeMapperInterface
$hydrator?HydratorInterface
$schemaFetcher?SchemaFetcherInterface
Calls 7
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 4§

Implementation details, listed for orientation only.

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

Test cases 14§

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

Dedicated tests 9
Other tests reaching this symbol 5