From 90520c25899921294d386e267cb042e632cf0cad Mon Sep 17 00:00:00 2001 From: TavoNiievez Date: Sun, 6 Feb 2022 10:08:21 -0500 Subject: [PATCH 1/4] Update Codeception interfaces --- composer.json | 2 +- readme.md | 2 +- src/Codeception/Module/DataFactory.php | 5 +---- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 60b8d2d..a81a7ce 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "minimum-stability": "dev", "require": { "php": "^8.0", - "codeception/codeception": "^5.0.0-alpha1", + "codeception/codeception": "dev-5.0-interfaces as 5.0.x-dev", "league/factory-muffin": "^3.3", "league/factory-muffin-faker": "^2.3" }, 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..3ecdb97 100644 --- a/src/Codeception/Module/DataFactory.php +++ b/src/Codeception/Module/DataFactory.php @@ -175,10 +175,7 @@ class DataFactory extends \Codeception\Module implements DependsOnModule, Requir public ?FactoryMuffin $factoryMuffin = null; - /** - * @var array - */ - protected $config = ['factories' => null, 'customStore' => null]; + protected array $config = ['factories' => null, 'customStore' => null]; public function _requires(): array { From 16ce1227790a4cb88283784ff6d4acfec9e14b2c Mon Sep 17 00:00:00 2001 From: TavoNiievez Date: Sun, 6 Feb 2022 10:22:38 -0500 Subject: [PATCH 2/4] Reformat code --- src/Codeception/Module/DataFactory.php | 32 +++++++++++++++----------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/Codeception/Module/DataFactory.php b/src/Codeception/Module/DataFactory.php index 3ecdb97..7e87120 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 = <<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).'); } @@ -225,12 +229,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; } @@ -265,7 +269,7 @@ public function onReconfigure($settings = []) * ]); * ``` * - * @throws \League\FactoryMuffin\Exceptions\DefinitionAlreadyDefinedException + * @throws FactoryMuffinDefinitionAlreadyDefinedException */ public function _define(string $model, array $fields): Definition { From 7dafd5fd2220e30d561935ebdf1a1f433ef7747a Mon Sep 17 00:00:00 2001 From: Dan Barrett Date: Fri, 11 Feb 2022 23:52:01 +1100 Subject: [PATCH 3/4] Improved support for Codeception 5/PHP 8 (#17) --- .gitattributes | 1 - composer.json | 18 ++++++++++++------ src/Codeception/Module/DataFactory.php | 14 +++++++++++--- 3 files changed, 23 insertions(+), 10 deletions(-) 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 a81a7ce..ec3794a 100644 --- a/composer.json +++ b/composer.json @@ -1,28 +1,34 @@ { "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": "dev-5.0-interfaces as 5.0.x-dev", + "codeception/codeception": "dev-5.0-interfaces as 5.0.0", "league/factory-muffin": "^3.3", "league/factory-muffin-faker": "^2.3" }, + "conflict": { + "codeception/codeception": "<5.0" + }, + "minimum-stability": "dev", "autoload": { "classmap": [ "src/" ] }, "config": { - "classmap-authoritative": true + "classmap-authoritative": true, + "sort-packages": true } } diff --git a/src/Codeception/Module/DataFactory.php b/src/Codeception/Module/DataFactory.php index 7e87120..45116cd 100644 --- a/src/Codeception/Module/DataFactory.php +++ b/src/Codeception/Module/DataFactory.php @@ -179,12 +179,18 @@ class DataFactory extends Module implements DependsOnModule, RequiresPackage public ?FactoryMuffin $factoryMuffin = null; - protected array $config = ['factories' => null, 'customStore' => null]; + /** + * @var array + */ + 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"', ]; } @@ -243,7 +249,9 @@ public function _after(TestInterface $test) public function _depends(): array { - return [ORM::class => $this->dependencyMessage]; + return [ + ORM::class => $this->dependencyMessage, + ]; } /** From b22525d4bf03b818d3a0c54634d44be9c02bcd47 Mon Sep 17 00:00:00 2001 From: Gintautas Miselis Date: Mon, 18 Jul 2022 18:59:43 +0300 Subject: [PATCH 4/4] Update dependencies --- composer.json | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index ec3794a..08bccdb 100644 --- a/composer.json +++ b/composer.json @@ -14,14 +14,11 @@ "homepage": "https://codeception.com/", "require": { "php": "^8.0", - "codeception/codeception": "dev-5.0-interfaces as 5.0.0", + "codeception/codeception": "^5.0.0-RC6", "league/factory-muffin": "^3.3", "league/factory-muffin-faker": "^2.3" }, - "conflict": { - "codeception/codeception": "<5.0" - }, - "minimum-stability": "dev", + "minimum-stability": "RC", "autoload": { "classmap": [ "src/"