Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A data factory module for Codeception.

## Requirements

* `PHP 7.1` or higher.
* `PHP 7.4` or higher.

## Installation

Expand Down
37 changes: 12 additions & 25 deletions src/Codeception/Module/DataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@
*/
class DataFactory extends \Codeception\Module implements DependsOnModule, RequiresPackage
{
/**
* @var string
*/
protected $dependencyMessage = <<<EOF
protected string $dependencyMessage = <<<EOF
ORM module (like Doctrine2) or Framework module with ActiveRecord support is required:
--
modules:
Expand All @@ -173,15 +170,10 @@ class DataFactory extends \Codeception\Module implements DependsOnModule, Requir

/**
* ORM module on which we we depend on.
*
* @var ORM
*/
public $ormModule;
public ?ORM $ormModule = null;

/**
* @var FactoryMuffin
*/
public $factoryMuffin;
public ?FactoryMuffin $factoryMuffin = null;

/**
* @var array
Expand All @@ -191,7 +183,7 @@ class DataFactory extends \Codeception\Module implements DependsOnModule, Requir
public function _requires()
{
return [
\League\FactoryMuffin\FactoryMuffin::class => '"league/factory-muffin": "^3.0"',
FactoryMuffin::class => '"league/factory-muffin": "^3.0"',
];
}

Expand All @@ -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'];
Expand Down Expand Up @@ -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
*/
Expand All @@ -263,6 +254,7 @@ public function onReconfigure($settings = [])
if (!$skipCleanup && !$this->ormModule->_getConfig('cleanup')) {
$this->factoryMuffin->deleteSaved();
}

$this->_beforeSuite($settings);
}

Expand All @@ -274,7 +266,6 @@ public function onReconfigure($settings = [])
* 'name' => $faker->name,
* 'email' => $faker->email
* ]);
*
* ```
*
* @throws \League\FactoryMuffin\Exceptions\DefinitionAlreadyDefinedException
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down