Download the PHP package k-kinzal/sql-fixture without Composer
On this page you can find all versions of the php package k-kinzal/sql-fixture. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download k-kinzal/sql-fixture
More information about k-kinzal/sql-fixture
Files in k-kinzal/sql-fixture
Package sql-fixture
Short Description Generate PHP-Faker based fixtures from SQL schemas
License MIT
Informations about the package sql-fixture
SQL Fixture
A FakerPHP provider for generating test fixture data from SQL schemas. Parses CREATE TABLE statements and generates type-appropriate fake data.
Overview
SQL Fixture reads your database schema (CREATE TABLE) and automatically generates realistic fixture data with correct types, lengths, and constraints. It supports MySQL and SQLite with three usage modes:
FixtureProvider- Generate fixtures from CREATE TABLE SQL stringsDatabaseFixtureProvider- Generate fixtures from a live database connection (PDO)FileFixtureProvider- Generate fixtures from a directory of DDL files
All modes support object hydration via ReflectionHydrator, converting generated data directly into typed PHP objects.
Requirements
- PHP 8.1 or higher
- fakerphp/faker ^1.23
- phpmyadmin/sql-parser ^5.11
Installation
Usage
From SQL Strings
Use FixtureProvider when you have CREATE TABLE SQL available:
From Database Connection
Use DatabaseFixtureProvider with a PDO connection to generate fixtures from your actual database schema:
From DDL Files
Use FileFixtureProvider with a directory containing .sql files:
Overriding Values
Pass specific values to override generated data:
Object Hydration
Generate typed PHP objects directly using ReflectionHydrator:
The hydrator handles:
- Constructor parameter matching (exact name or snake_case to camelCase conversion)
- Type casting (string to int/float/bool, JSON decode for arrays)
- Default values and nullable parameters
- Property-based hydration for classes without constructors
SQLite Support
Supported Types
MySQL
| Category | Types |
|---|---|
| Integer | TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT |
| Decimal | FLOAT, DOUBLE, REAL, DECIMAL, NUMERIC |
| String | CHAR, VARCHAR, TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT |
| Binary | BINARY, VARBINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB |
| Enum/Set | ENUM, SET |
| Date/Time | DATE, TIME, DATETIME, TIMESTAMP, YEAR |
| JSON | JSON |
| Boolean | BOOL, BOOLEAN |
| Bit | BIT |
| Spatial | POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON, GEOMETRYCOLLECTION |
SQLite
| Affinity | Mapped Types |
|---|---|
| INTEGER | INT, INTEGER, TINYINT, SMALLINT, MEDIUMINT, BIGINT, INT2, INT8 |
| TEXT | CHAR, VARCHAR, TEXT, CLOB, TINYTEXT, MEDIUMTEXT, LONGTEXT |
| REAL | FLOAT, DOUBLE, REAL |
| BLOB | BLOB, BINARY, VARBINARY |
| NUMERIC | BOOLEAN, DATE, DATETIME, TIMESTAMP, DECIMAL |
Column Handling
- AUTO_INCREMENT / AUTOINCREMENT columns are skipped (not generated)
- Generated columns (
ASexpressions) are skipped - Nullable columns have a 10% chance of returning null/default
- UNSIGNED constraint is respected for numeric types
- Length/precision/scale are respected for string and decimal types
- ENUM/SET values are randomly selected from the declared options
- DEFAULT values are used when a nullable column generates null
Extensibility
Customize behavior by providing your own implementations:
Development
License
MIT License. See LICENSE for details.