Databuilder-php is a simple library that allows to define Spryker databuilders in PHP classes. This greatly improves readability and type hinting.
To install Databuilder-php, run the command below and you will get the latest version
composer require --dev gustasva/databuilder-php
- First we need to add PHP databuilders autoloading as Spryker autoloads only PyzTest directory for testing.
"autoload-dev": {
"psr-4": {
"_data\\": "tests/_data/",
- Next we create databuilders directory in _data directory.
├── ...
├── tests
├── _data
├── Builders
- Next we create Databuilders. Naming convention here is SomethingDatabuilder
namespace _data\Builders;
use Databuilder\Databuilder;
class SomethingDatabuilder extends Databuilder
- Define builder:
- First level of array is transfer name
- Second level of array is the place where you define databuilder properties
- For faker parameters or methods use
$this->faker->method()
- For literal values use
=value
- For faker parameters or methods use
- In getName() method we're defining the name of xml databuilder. If we return
name
from this method the xml databuilder will be namedname.databuilder.xml
Example displayed below:
return [
'Something' => [
'name' => $this->faker->word(),
'value' => '=thisIsSomeValue',
- Run databuilder generator:
vendor/bin/databuilder