class FixtureProvider
    extends SqlSchemaProvider
Public API: explicitly declared with @visibility public.

Faker provider that generates fixtures from CREATE TABLE SQL statements.

The dialect and, optionally, the version tag select the release the statements are read for; omitting the version tag uses the default of the dialect.

Read statements as a MySQL 8.0 server doesdoctest
$provider = new \SqlFixture\Provider\FixtureProvider(\Faker\Factory::create(), dialect: 'mysql', version: 'mysql-8.0.44');
    $provider->getVersion() // => 'mysql-8.0.44'
Generate a row while leaving the auto-increment key to the databasedoctest
$provider = new \SqlFixture\Provider\FixtureProvider(\Faker\Factory::create());
    $provider->fixture('CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(30))', ['name' => 'Alice']) // => ['name' => 'Alice']
Generate linked rows from registered schemasdoctest
$provider = new \SqlFixture\Provider\FixtureProvider(\Faker\Factory::create());
    $provider->registerSchema('CREATE TABLE users (id INT PRIMARY KEY)');
    $provider->registerSchema('CREATE TABLE posts (user_id INT)');
    $rows = $provider->fixtures('users.id < posts.user_id', ['users' => ['id' => 9], 'posts' => 2]);
    $rows->rows('posts') // => [['user_id' => 9], ['user_id' => 9]]

Methods§

public function __construct(
    Generator $faker,
    ?TypeMapperInterface $typeMapper = null,
    ?HydratorInterface $hydrator = null,
    ?SchemaParserInterface $schemaParser = null,
    string $dialect = PlatformFactory::DRIVER_MYSQL,
    string|null $version = null,
)

Parameters

$fakerGenerator
$typeMapper?TypeMapperInterface
$hydrator?HydratorInterface
$schemaParser?SchemaParserInterface
$dialectstringSQL dialect: 'mysql', 'pgsql' or 'sqlite'
$versionstring|nullVersion tag such as 'mysql-8.4.7', or null for the default of the dialect

Throws

UnsupportedDriverException If the dialect is not supported
UnsupportedVersionException If the version tag is not a supported release of the dialect
Calls 7
public function fixture<T of object>(
    string $createTableSql,
    array<string, mixed> $overrides = [],
    class-string<T>|null $className = null,
    string|null $dialect = null,
    string|null $version = null,
): ($className is null ? array<string, mixed> : T)

Generate a fixture from a CREATE TABLE SQL statement.

Parameters

$createTableSqlstringCREATE TABLE SQL statement
$overridesarray<string, mixed>Override values
$classNameclass-string<T>|nullDeserialization target class
$dialectstring|nullSQL dialect for this specific call (overrides constructor default)
$versionstring|nullVersion tag for this specific call (overrides constructor default; the default of the dialect when only the dialect is overridden)

Returns

($className is null ? array<string, mixed> : T)
Test cases 52
Calls 2
public function fixtures(
    FixturePlan|string $plan,
    array<string, int|array<mixed>|TableOverrides> $overrides = [],
): FixtureSet

Generate the rows a plan describes.

Every table the plan names has to have been registered, either through registerSchema() or by generating a fixture from its DDL first.

Parameters

$planFixturePlan|stringA plan, or the relation syntax for one
$overridesarray<string, int|array<mixed>|TableOverrides>Table name => what to override

Returns

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

Get the underlying fixture generator.

Test cases 1
public function getVersion(): string

Private surface 5§

Implementation details, listed for orientation only.

private FixtureGenerator $fixtureGenerator
private string $dialect
private ServerVersion $version
private Generator $faker
private StaticSchemaResolver $schemaResolver

Test cases 63§

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

Dedicated tests 46
Other tests reaching this symbol 17