Skip to content

Commit

Permalink
Code standards updated to PHP 7.1 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
TavoNiievez authored May 27, 2021
1 parent cf66d54 commit 6762e5a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
50 changes: 26 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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
}
}
4 changes: 4 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down
47 changes: 23 additions & 24 deletions src/Codeception/Module/DataFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

namespace Codeception\Module;

use Codeception\Lib\Interfaces\DataMapper;
Expand All @@ -7,6 +10,7 @@
use Codeception\Exception\ModuleException;
use Codeception\Lib\Interfaces\RequiresPackage;
use Codeception\TestInterface;
use League\FactoryMuffin\Definition;
use League\FactoryMuffin\FactoryMuffin;
use League\FactoryMuffin\Stores\RepositoryStore;
use League\FactoryMuffin\Stores\StoreInterface;
Expand Down Expand Up @@ -153,6 +157,9 @@
*/
class DataFactory extends \Codeception\Module implements DependsOnModule, RequiresPackage
{
/**
* @var string
*/
protected $dependencyMessage = <<<EOF
ORM module (like Doctrine2) or Framework module with ActiveRecord support is required:
--
Expand All @@ -175,12 +182,15 @@ class DataFactory extends \Codeception\Module implements DependsOnModule, Requir
*/
public $factoryMuffin;

/**
* @var array
*/
protected $config = ['factories' => null, 'customStore' => null];

public function _requires()
{
return [
'League\FactoryMuffin\FactoryMuffin' => '"league/factory-muffin": "^3.0"',
\League\FactoryMuffin\FactoryMuffin::class => '"league/factory-muffin": "^3.0"',
];
}

Expand Down Expand Up @@ -219,23 +229,27 @@ protected function getStore()
: null;
}

public function _inject(ORM $orm)
public function _inject(ORM $orm): void
{
$this->ormModule = $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();
}

public function _depends()
{
return ['Codeception\Lib\Interfaces\ORM' => $this->dependencyMessage];
return [\Codeception\Lib\Interfaces\ORM::class => $this->dependencyMessage];
}


Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 6762e5a

Please sign in to comment.