From 6762e5aae2823ab23759e26bf0192718aac8cc68 Mon Sep 17 00:00:00 2001 From: Tavo Nieves J <64917965+TavoNiievez@users.noreply.github.com> Date: Thu, 27 May 2021 15:49:40 -0500 Subject: [PATCH 1/4] Code standards updated to PHP 7.1 (#9) --- .github/workflows/main.yml | 4 +-- composer.json | 50 +++++++++++++------------- readme.md | 4 +++ src/Codeception/Module/DataFactory.php | 47 ++++++++++++------------ 4 files changed, 55 insertions(+), 50 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 501f8d1..f653150 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - php: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0] + php: [7.1, 7.2, 7.3, 7.4, 8.0] steps: - name: Checkout code @@ -26,5 +26,5 @@ jobs: - name: Install dependencies run: composer install --prefer-dist --no-progress --no-interaction --no-suggest - - name: Run test suite + - name: Run php lint run: php -l src/Codeception/Module/DataFactory.php diff --git a/composer.json b/composer.json index a2cf3f2..0b5911b 100644 --- a/composer.json +++ b/composer.json @@ -1,26 +1,28 @@ { - "name":"codeception/module-datafactory", - "description":"DataFactory module for Codeception", - "keywords":["codeception"], - "homepage":"http://codeception.com/", - "type":"library", - "license":"MIT", - "authors":[ - { - "name":"Michael Bodnarchuk" - } - ], - "minimum-stability": "RC", - "require": { - "php": ">=5.6.0 <9.0", - "codeception/codeception": "^4.0", - "league/factory-muffin": "^3.0", - "league/factory-muffin-faker": "^2.1" - }, - "autoload":{ - "classmap": ["src/"] - }, - "config": { - "classmap-authoritative": true - } + "name": "codeception/module-datafactory", + "description": "DataFactory module for Codeception", + "keywords": [ "codeception" ], + "homepage": "https://codeception.com/", + "type": "library", + "license": "MIT", + "authors": [ + { + "name": "Michael Bodnarchuk" + } + ], + "minimum-stability": "RC", + "require": { + "php": "^7.1 || ^8.0", + "codeception/codeception": "^4.0", + "league/factory-muffin": "^3.0", + "league/factory-muffin-faker": "^2.1" + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "config": { + "classmap-authoritative": true + } } diff --git a/readme.md b/readme.md index 772ec2a..658d55b 100644 --- a/readme.md +++ b/readme.md @@ -7,6 +7,10 @@ A data factory module for Codeception. [![Total Downloads](https://poser.pugx.org/codeception/module-datafactory/downloads)](https://packagist.org/packages/codeception/module-datafactory) [![License](https://poser.pugx.org/codeception/module-datafactory/license)](/LICENSE) +## Requirements + +* `PHP 7.1` or higher. + ## Installation ``` diff --git a/src/Codeception/Module/DataFactory.php b/src/Codeception/Module/DataFactory.php index 4b8e67a..5316847 100644 --- a/src/Codeception/Module/DataFactory.php +++ b/src/Codeception/Module/DataFactory.php @@ -1,4 +1,7 @@ null, 'customStore' => null]; public function _requires() { return [ - 'League\FactoryMuffin\FactoryMuffin' => '"league/factory-muffin": "^3.0"', + \League\FactoryMuffin\FactoryMuffin::class => '"league/factory-muffin": "^3.0"', ]; } @@ -219,7 +229,7 @@ protected function getStore() : null; } - public function _inject(ORM $orm) + public function _inject(ORM $orm): void { $this->ormModule = $orm; } @@ -227,7 +237,11 @@ public function _inject(ORM $orm) public function _after(TestInterface $test) { $skipCleanup = array_key_exists('cleanup', $this->config) && $this->config['cleanup'] === false; - if ($skipCleanup || $this->ormModule->_getConfig('cleanup')) { + $cleanupOrmModule_Config = $this->ormModule->_getConfig('cleanup'); + if ($skipCleanup) { + return; + } + if ($cleanupOrmModule_Config) { return; } $this->factoryMuffin->deleteSaved(); @@ -235,7 +249,7 @@ public function _after(TestInterface $test) public function _depends() { - return ['Codeception\Lib\Interfaces\ORM' => $this->dependencyMessage]; + return [\Codeception\Lib\Interfaces\ORM::class => $this->dependencyMessage]; } @@ -262,14 +276,9 @@ public function onReconfigure($settings = []) * * ``` * - * @param string $model - * @param array $fields - * - * @return \League\FactoryMuffin\Definition - * * @throws \League\FactoryMuffin\Exceptions\DefinitionAlreadyDefinedException */ - public function _define($model, $fields) + public function _define(string $model, array $fields): Definition { return $this->factoryMuffin->define($model)->setDefinitions($fields); } @@ -284,12 +293,9 @@ public function _define($model, $fields) * * Returns an instance of created user. * - * @param string $name - * @param array $extraAttrs - * * @return object */ - public function have($name, array $extraAttrs = []) + public function have(string $name, array $extraAttrs = []) { return $this->factoryMuffin->create($name, $extraAttrs); } @@ -306,12 +312,9 @@ public function have($name, array $extraAttrs = []) * * Returns an instance of created user without creating a record in database. * - * @param string $name - * @param array $extraAttrs - * * @return object */ - public function make($name, array $extraAttrs = []) + public function make(string $name, array $extraAttrs = []) { return $this->factoryMuffin->instance($name, $extraAttrs); } @@ -324,13 +327,9 @@ public function make($name, array $extraAttrs = []) * $I->haveMultiple('User', 10, ['is_active' => true]); // create 10 active users * ``` * - * @param string $name - * @param int $times - * @param array $extraAttrs - * - * @return \object[] + * @return object[] */ - public function haveMultiple($name, $times, array $extraAttrs = []) + public function haveMultiple(string $name, int $times, array $extraAttrs = []): array { return $this->factoryMuffin->seed($times, $name, $extraAttrs); } From 883cba1363b502bcf567a97a17ef30d53795404a Mon Sep 17 00:00:00 2001 From: Michael Bodnarchuk Date: Sat, 26 Jun 2021 14:14:51 +0300 Subject: [PATCH 2/4] Update DataFactory.php (#11) --- src/Codeception/Module/DataFactory.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Codeception/Module/DataFactory.php b/src/Codeception/Module/DataFactory.php index 5316847..7f0acdc 100644 --- a/src/Codeception/Module/DataFactory.php +++ b/src/Codeception/Module/DataFactory.php @@ -27,10 +27,14 @@ * } * ``` * - * Generation rules can be defined in a factories file. You will need to create `factories.php` (it is recommended to store it in `_support` dir) + * 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`. * Follow [FactoryMuffin documentation](https://github.com/thephpleague/factory-muffin) to set valid rules. - * Random data provided by [Faker](https://github.com/fzaninotto/Faker) library. + * Randomly generated data provided by [Faker](https://github.com/fzaninotto/Faker) library. * + * Here is the sample factory file: * ```php * Date: Tue, 24 Aug 2021 00:21:57 +0300 Subject: [PATCH 3/4] Update readme.md (#13) --- readme.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/readme.md b/readme.md index 658d55b..dc77128 100644 --- a/readme.md +++ b/readme.md @@ -21,6 +21,8 @@ composer require "codeception/module-datafactory" --dev See [the module documentation](https://codeception.com/docs/modules/DataFactory). +[Changelog](https://github.com/Codeception/module-datafactory/releases) + ## License `Codeception Module DataFactory` is open-sourced software licensed under the [MIT](/LICENSE) License. From 1eb9b3b0477a8973ea81c11a9d0843461544ea92 Mon Sep 17 00:00:00 2001 From: Tavo Nieves J <64917965+TavoNiievez@users.noreply.github.com> Date: Mon, 29 Nov 2021 19:53:06 -0500 Subject: [PATCH 4/4] Update codebase to PHP 7.4 (#14) --- .github/workflows/main.yml | 2 +- composer.json | 2 +- readme.md | 2 +- src/Codeception/Module/DataFactory.php | 37 +++++++++----------------- 4 files changed, 15 insertions(+), 28 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f653150..6d6f5c5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - php: [7.1, 7.2, 7.3, 7.4, 8.0] + php: [7.4, 8.0, 8.1] steps: - name: Checkout code diff --git a/composer.json b/composer.json index 0b5911b..6dfb60a 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "minimum-stability": "RC", "require": { - "php": "^7.1 || ^8.0", + "php": "^7.4 || ^8.0", "codeception/codeception": "^4.0", "league/factory-muffin": "^3.0", "league/factory-muffin-faker": "^2.1" diff --git a/readme.md b/readme.md index dc77128..11ac0e5 100644 --- a/readme.md +++ b/readme.md @@ -9,7 +9,7 @@ A data factory module for Codeception. ## Requirements -* `PHP 7.1` or higher. +* `PHP 7.4` or higher. ## Installation diff --git a/src/Codeception/Module/DataFactory.php b/src/Codeception/Module/DataFactory.php index 7f0acdc..272400e 100644 --- a/src/Codeception/Module/DataFactory.php +++ b/src/Codeception/Module/DataFactory.php @@ -158,10 +158,7 @@ */ class DataFactory extends \Codeception\Module implements DependsOnModule, RequiresPackage { - /** - * @var string - */ - protected $dependencyMessage = << '"league/factory-muffin": "^3.0"', + FactoryMuffin::class => '"league/factory-muffin": "^3.0"', ]; } @@ -206,15 +198,13 @@ public function _beforeSuite($settings = []) 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).'); } + $this->factoryMuffin->loadFactories($realpath); } } } - /** - * @return StoreInterface|null - */ - protected function getStore() + protected function getStore(): ?StoreInterface { if (!empty($this->config['customStore'])) { $store = new $this->config['customStore']; @@ -242,18 +232,19 @@ public function _after(TestInterface $test) if ($skipCleanup) { return; } + if ($cleanupOrmModule_Config) { return; } + $this->factoryMuffin->deleteSaved(); } public function _depends() { - return [\Codeception\Lib\Interfaces\ORM::class => $this->dependencyMessage]; + return [ORM::class => $this->dependencyMessage]; } - /** * @throws ModuleException */ @@ -263,6 +254,7 @@ public function onReconfigure($settings = []) if (!$skipCleanup && !$this->ormModule->_getConfig('cleanup')) { $this->factoryMuffin->deleteSaved(); } + $this->_beforeSuite($settings); } @@ -274,7 +266,6 @@ public function onReconfigure($settings = []) * 'name' => $faker->name, * 'email' => $faker->email * ]); - * * ``` * * @throws \League\FactoryMuffin\Exceptions\DefinitionAlreadyDefinedException @@ -293,10 +284,8 @@ public function _define(string $model, array $fields): Definition * ``` * * Returns an instance of created user. - * - * @return object */ - public function have(string $name, array $extraAttrs = []) + public function have(string $name, array $extraAttrs = []): object { return $this->factoryMuffin->create($name, $extraAttrs); } @@ -312,10 +301,8 @@ public function have(string $name, array $extraAttrs = []) * ``` * * Returns an instance of created user without creating a record in database. - * - * @return object */ - public function make(string $name, array $extraAttrs = []) + public function make(string $name, array $extraAttrs = []): object { return $this->factoryMuffin->instance($name, $extraAttrs); }