classDatabaseFixtureProvider
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.
$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
$faker | Generator | |
$connection | PDO | |
$typeMapper | ?TypeMapperInterface | |
$hydrator | ?HydratorInterface | |
$schemaFetcher | ?SchemaFetcherInterface |
Calls 7
- static-call
Base::__construct()line 46 - static-call PlatformFactory::detectDriver() line 48
- static-call PlatformFactory::createTypeMapper() line 50
- static-call PlatformFactory::createSchemaParser() line 51
- static-call PlatformFactory::createSchemaFetcher() line 53
- new DatabaseSchemaCache line 54
- new FixtureGenerator line 55
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)Generate a fixture from a database table.
Parameters
$tableName | string | Table name (e.g., "users" or "mydb.users") |
$overrides | array<string, mixed> | Override values |
$className | class-string<T>|null | Deserialization target class |
Returns
($className is null ? array<string, mixed> : T)Test cases 12
SqliteIntegrationTest::allSqliteTypesFixturecallsSqliteIntegrationTest::databaseFixtureProviderWithSqlitecallsSqliteIntegrationTest::fixtureWithHydrationcallsSqliteIntegrationTest::fixtureWithOverridescallsSqliteIntegrationTest::insertAndSelectFixturecallsDatabaseFixtureProviderTest::testClearCacheAllowsRefetchcallsDatabaseFixtureProviderTest::testFixtureGeneratesArrayFromSqliteTablecallsDatabaseFixtureProviderTest::testFixtureNormalizesQuotedTableNamescallsDatabaseFixtureProviderTest::testFixtureWithCustomSchemaFetchercallsDatabaseFixtureProviderTest::testFixtureWithCustomTypeMappercallsDatabaseFixtureProviderTest::testFixtureWithOverridescallsDatabaseFixtureProviderTest::testSchemaCacheWorksOnSecondCallcalls
Calls 2
- method-call DatabaseSchemaCache::getSchema() line 72
- method-call FixtureGenerator::generate() line 73
public function clearCache(): voidpublic function getFixtureGenerator(): FixtureGeneratorGet the underlying fixture generator.
Returns
Test cases 1
public function getDriver(): stringGet the detected driver name.
Returns
stringPrivate surface 4§
Implementation details, listed for orientation only.
private FixtureGenerator $fixtureGeneratorprivate SchemaFetcherInterface $schemaFetcherprivate string $driverprivate DatabaseSchemaCache $schemaCacheTest cases 14§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 9
DatabaseFixtureProviderTest::testClearCacheAllowsRefetchcallsDatabaseFixtureProviderTest::testFixtureGeneratesArrayFromSqliteTablecallsDatabaseFixtureProviderTest::testFixtureNormalizesQuotedTableNamescallsDatabaseFixtureProviderTest::testFixtureWithCustomSchemaFetchercallsDatabaseFixtureProviderTest::testFixtureWithCustomTypeMappercallsDatabaseFixtureProviderTest::testFixtureWithOverridescallsDatabaseFixtureProviderTest::testGetDriverReturnsSqlitecallsDatabaseFixtureProviderTest::testGetFixtureGeneratorReturnsInstancecallsDatabaseFixtureProviderTest::testSchemaCacheWorksOnSecondCallcalls