diff --git a/.gitattributes b/.gitattributes index 87f3679..2d44cfe 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,6 +2,5 @@ /tests export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/Robofile.php export-ignore /*.md export-ignore /*.yml export-ignore diff --git a/composer.json b/composer.json index 60b8d2d..08bccdb 100644 --- a/composer.json +++ b/composer.json @@ -1,28 +1,31 @@ { "name": "codeception/module-datafactory", "description": "DataFactory module for Codeception", - "keywords": [ "codeception" ], - "homepage": "https://codeception.com/", - "type": "library", "license": "MIT", + "type": "library", + "keywords": [ + "codeception" + ], "authors": [ { "name": "Michael Bodnarchuk" } ], - "minimum-stability": "dev", + "homepage": "https://codeception.com/", "require": { "php": "^8.0", - "codeception/codeception": "^5.0.0-alpha1", + "codeception/codeception": "^5.0.0-RC6", "league/factory-muffin": "^3.3", "league/factory-muffin-faker": "^2.3" }, + "minimum-stability": "RC", "autoload": { "classmap": [ "src/" ] }, "config": { - "classmap-authoritative": true + "classmap-authoritative": true, + "sort-packages": true } } diff --git a/readme.md b/readme.md index 11ac0e5..ffd5154 100644 --- a/readme.md +++ b/readme.md @@ -9,7 +9,7 @@ A data factory module for Codeception. ## Requirements -* `PHP 7.4` or higher. +* `PHP 8.0` or higher. ## Installation diff --git a/src/Codeception/Module/DataFactory.php b/src/Codeception/Module/DataFactory.php index 6f07c43..45116cd 100644 --- a/src/Codeception/Module/DataFactory.php +++ b/src/Codeception/Module/DataFactory.php @@ -4,13 +4,15 @@ namespace Codeception\Module; +use Codeception\Exception\ModuleException; use Codeception\Lib\Interfaces\DataMapper; use Codeception\Lib\Interfaces\DependsOnModule; use Codeception\Lib\Interfaces\ORM; -use Codeception\Exception\ModuleException; use Codeception\Lib\Interfaces\RequiresPackage; +use Codeception\Module; use Codeception\TestInterface; use League\FactoryMuffin\Definition; +use League\FactoryMuffin\Exceptions\DefinitionAlreadyDefinedException as FactoryMuffinDefinitionAlreadyDefinedException; use League\FactoryMuffin\FactoryMuffin; use League\FactoryMuffin\Stores\RepositoryStore; use League\FactoryMuffin\Stores\StoreInterface; @@ -27,10 +29,10 @@ * } * ``` * - * Generation rules can be defined in a factories file. + * Generation rules can be defined in a factories file. * Create a folder for factories files: `tests/_support/factories`. * - * Create an ampty PHP file inside that folder `factories.php`. + * Create an empty PHP file inside that folder `factories.php`. * Follow [FactoryMuffin documentation](https://github.com/thephpleague/factory-muffin) to set valid rules. * Randomly generated data provided by [Faker](https://github.com/fzaninotto/Faker) library. * @@ -127,10 +129,10 @@ * ``` * * ### Custom store - * + * * You can define a custom store for Factory Muffin using `customStore` parameter. It can be a simple class or a factory with `create` method. * The instantiated object must implement `\League\FactoryMuffin\Stores\StoreInterface`. - * + * * Store factory example: * ```yaml * modules: @@ -138,10 +140,10 @@ * - DataFactory: * customStore: \common\tests\store\MyCustomStoreFactory * ``` - * + * * ```php * use League\FactoryMuffin\Stores\StoreInterface; - * + * * class MyCustomStoreFactory * { * public function create(): StoreInterface @@ -149,14 +151,14 @@ * return CustomStore(); * } * } - * + * * class CustomStore implements StoreInterface * { * // ... * } * ``` */ -class DataFactory extends \Codeception\Module implements DependsOnModule, RequiresPackage +class DataFactory extends Module implements DependsOnModule, RequiresPackage { protected string $dependencyMessage = << */ - protected $config = ['factories' => null, 'customStore' => null]; + protected array $config = [ + 'factories' => null, + 'customStore' => null, + ]; public function _requires(): array { return [ - FactoryMuffin::class => '"league/factory-muffin": "^3.0"', + FactoryMuffin::class => '"league/factory-muffin": "^3.3"', ]; } @@ -193,8 +200,8 @@ public function _beforeSuite($settings = []) $this->factoryMuffin = new FactoryMuffin($store); if ($this->config['factories']) { - foreach ((array) $this->config['factories'] as $factoryPath) { - $realpath = realpath(codecept_root_dir().$factoryPath); + foreach ((array)$this->config['factories'] as $factoryPath) { + $realpath = realpath(codecept_root_dir() . $factoryPath); if ($realpath === false) { throw new ModuleException($this, 'The path to one of your factories is not correct. Please specify the directory relative to the codeception.yml file (ie. _support/factories).'); } @@ -228,12 +235,12 @@ public function _inject(ORM $orm): void public function _after(TestInterface $test) { $skipCleanup = array_key_exists('cleanup', $this->config) && $this->config['cleanup'] === false; - $cleanupOrmModule_Config = $this->ormModule->_getConfig('cleanup'); + $cleanupOrmModuleConfig = $this->ormModule->_getConfig('cleanup'); if ($skipCleanup) { return; } - if ($cleanupOrmModule_Config) { + if ($cleanupOrmModuleConfig) { return; } @@ -242,7 +249,9 @@ public function _after(TestInterface $test) public function _depends(): array { - return [ORM::class => $this->dependencyMessage]; + return [ + ORM::class => $this->dependencyMessage, + ]; } /** @@ -268,7 +277,7 @@ public function onReconfigure($settings = []) * ]); * ``` * - * @throws \League\FactoryMuffin\Exceptions\DefinitionAlreadyDefinedException + * @throws FactoryMuffinDefinitionAlreadyDefinedException */ public function _define(string $model, array $fields): Definition {