Skip to content

Commit e67040a

Browse files
authored
Update codebase to PHP 7.4 (#26)
1 parent a35dcdb commit e67040a

File tree

21 files changed

+511
-473
lines changed

21 files changed

+511
-473
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434

3535
strategy:
3636
matrix:
37-
php: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0]
37+
php: [7.4, 8.0]
3838

3939
steps:
4040
- name: Checkout code

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name":"codeception/module-db",
33
"description":"DB module for Codeception",
44
"keywords":["codeception", "db-testing", "database-testing"],
5-
"homepage":"http://codeception.com/",
5+
"homepage":"https://codeception.com/",
66
"type":"library",
77
"license":"MIT",
88
"authors":[
@@ -15,7 +15,9 @@
1515
],
1616
"minimum-stability": "RC",
1717
"require": {
18-
"php": ">=5.6.0 <9.0",
18+
"php": "^7.4 | ^8.0",
19+
"ext-json": "*",
20+
"ext-pdo": "*",
1921
"codeception/codeception": "*@dev"
2022
},
2123
"conflict": {

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ A database module for Codeception.
77
[![Total Downloads](https://poser.pugx.org/codeception/module-db/downloads)](https://packagist.org/packages/codeception/module-db)
88
[![License](https://poser.pugx.org/codeception/module-db/license)](/LICENSE)
99

10+
## Requirements
11+
12+
* `PHP 7.4` or higher.
13+
1014
## Installation
1115

1216
```

src/Codeception/Lib/DbPopulator.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Codeception\Lib;
46

57
/**
68
* Populates a db using a parameterized command built from the Db module configuration.
79
*/
810
class DbPopulator
911
{
10-
/**
11-
* @var array
12-
*/
13-
protected $config;
12+
protected array $config = [];
1413

15-
/**
16-
* @var array
17-
*/
18-
protected $commands;
14+
protected array $commands = [];
1915

2016
/**
2117
* Constructs a DbPopulator object for the given command and Db module.
2218
*
23-
* @param $config
2419
* @internal param string $command The parameterized command to evaluate and execute later.
2520
* @internal param Codeception\Module\Db|null $dbModule The Db module used to build the populator command or null.
2621
*/
27-
public function __construct($config)
22+
public function __construct(array $config)
2823
{
2924
$this->config = $config;
30-
3125
//Convert To Array Format
32-
if (isset($this->config['dump']) && !is_array($this->config['dump'])) {
33-
$this->config['dump'] = [$this->config['dump']];
26+
if (!isset($this->config['dump'])) {
27+
return;
3428
}
29+
30+
if (is_array($this->config['dump'])) {
31+
return;
32+
}
33+
34+
$this->config['dump'] = [$this->config['dump']];
3535
}
3636

3737
/**
@@ -53,15 +53,15 @@ public function __construct($config)
5353
* @param string|null $dumpFile The dump file to build the command with.
5454
* @return string The resulting command string after evaluating any configuration's key
5555
*/
56-
protected function buildCommand($command, $dumpFile = null)
56+
protected function buildCommand(string $command, string $dumpFile = null): string
5757
{
58-
$dsn = isset($this->config['dsn']) ? $this->config['dsn'] : '';
58+
$dsn = $this->config['dsn'] ?? '';
5959
$dsnVars = [];
60-
$dsnWithoutDriver = preg_replace('/^[a-z]+:/i', '', $dsn);
60+
$dsnWithoutDriver = preg_replace('#^[a-z]+:#i', '', $dsn);
6161
foreach (explode(';', $dsnWithoutDriver) as $item) {
6262
$keyValueTuple = explode('=', $item);
6363
if (count($keyValueTuple) > 1) {
64-
list($k, $v) = array_values($keyValueTuple);
64+
[$k, $v] = array_values($keyValueTuple);
6565
$dsnVars[$k] = $v;
6666
}
6767
}
@@ -79,17 +79,16 @@ protected function buildCommand($command, $dumpFile = null)
7979

8080
unset($vars[$key]);
8181
}
82+
8283
return str_replace(array_keys($vars), $vars, $command);
8384
}
8485

8586
/**
8687
* Executes the command built using the Db module configuration.
8788
*
8889
* Uses the PHP `exec` to spin off a child process for the built command.
89-
*
90-
* @return bool
9190
*/
92-
public function run()
91+
public function run(): bool
9392
{
9493
foreach ($this->buildCommands() as $command) {
9594
$this->runCommand($command);
@@ -98,26 +97,26 @@ public function run()
9897
return true;
9998
}
10099

101-
private function runCommand($command)
100+
private function runCommand($command): void
102101
{
103-
codecept_debug("[Db] Executing Populator: `$command`");
102+
codecept_debug("[Db] Executing Populator: `{$command}`");
104103

105104
exec($command, $output, $exitCode);
106105

107106
if (0 !== $exitCode) {
108107
throw new \RuntimeException(
109108
"The populator command did not end successfully: \n" .
110-
" Exit code: $exitCode \n" .
109+
" Exit code: {$exitCode} \n" .
111110
" Output:" . implode("\n", $output)
112111
);
113112
}
114113

115114
codecept_debug("[Db] Populator Finished.");
116115
}
117116

118-
public function buildCommands()
117+
public function buildCommands(): array
119118
{
120-
if ($this->commands !== null) {
119+
if ($this->commands !== []) {
121120
return $this->commands;
122121
} elseif (!isset($this->config['dump']) || $this->config['dump'] === false) {
123122
return [$this->buildCommand($this->config['populator'])];

0 commit comments

Comments
 (0)