Skip to content

Commit b718b4b

Browse files
authored
Update codebase to PHP 7.4 (#55)
1 parent 2256435 commit b718b4b

File tree

11 files changed

+64
-62
lines changed

11 files changed

+64
-62
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88

99
strategy:
1010
matrix:
11-
php: [7.3, 7.4, 8.0]
11+
php: [7.4, 8.0, 8.1]
1212

1313
steps:
1414
- name: Checkout code
@@ -26,4 +26,4 @@ jobs:
2626
run: composer update --prefer-dist --no-progress --no-interaction
2727

2828
- name: Run test suite
29-
run: php vendor/bin/phpunit
29+
run: php vendor/bin/phpunit

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Inspired by MiniTest of Ruby now you combine BDD and classical TDD style in one
1313

1414
## Installation
1515

16-
*Requires PHP >= 7.3*
16+
*Requires PHP >= 7.4*
1717

1818
* Install with Composer:
1919

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
}
1515
],
1616
"require": {
17-
"php": ">=7.3.0",
17+
"php": ">=7.4.0",
1818
"myclabs/deep-copy": "^1.10",
1919
"phpunit/phpunit": "^8.0|^9.0"
2020
},

src/Codeception/Specify.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function specify(string $thing, Closure $code = null, $examples = []): ?s
2323
$this->runSpec($thing, $code, $examples);
2424
return null;
2525
}
26+
2627
return $this;
2728
}
2829

@@ -32,6 +33,7 @@ public function describe(string $feature, Closure $code = null): ?self
3233
$this->runSpec($feature, $code);
3334
return null;
3435
}
36+
3537
return $this;
3638
}
3739

@@ -41,6 +43,7 @@ public function it(string $specification, Closure $code = null, $examples = []):
4143
$this->runSpec($specification, $code, $examples);
4244
return $this;
4345
}
46+
4447
TestCase::markTestIncomplete();
4548
return $this;
4649
}
@@ -56,6 +59,7 @@ public function should(string $behavior, Closure $code = null, $examples = []):
5659
$this->runSpec('should ' . $behavior, $code, $examples);
5760
return $this;
5861
}
62+
5963
TestCase::markTestIncomplete();
6064
return $this;
6165
}
@@ -66,6 +70,7 @@ public function shouldNot(string $behavior, Closure $code = null, $examples = []
6670
$this->runSpec('should not ' . $behavior, $code, $examples);
6771
return $this;
6872
}
73+
6974
TestCase::markTestIncomplete();
7075
return $this;
7176
}

src/Codeception/Specify/ObjectProperty.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct($owner, $property, $value = null)
4646

4747
$this->property->setAccessible(true);
4848

49-
$this->initValue = ($value === null ? $this->getValue() : $value);
49+
$this->initValue = ($value ?? $this->getValue());
5050
}
5151

5252
public function getName(): string
@@ -57,7 +57,7 @@ public function getName(): string
5757
/**
5858
* Restores initial value
5959
*/
60-
public function restoreValue()
60+
public function restoreValue(): void
6161
{
6262
$this->setValue($this->initValue);
6363
}
@@ -73,7 +73,7 @@ public function getValue()
7373
/**
7474
* @param mixed $value
7575
*/
76-
public function setValue($value)
76+
public function setValue($value): void
7777
{
7878
$this->property->setValue($this->owner, $value);
7979
}

src/Codeception/Specify/ResultPrinter.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ class ResultPrinter extends DefaultResultPrinter
1515
protected function writeProgress(string $progress): void
1616
{
1717
$this->write($progress);
18-
$this->column++;
19-
$this->numTestsRun++;
18+
++$this->column;
19+
++$this->numTestsRun;
2020

21-
if ($this->column == $this->maxColumn || $this->numTestsRun == $this->numTests) {
22-
if ($this->column == $this->maxColumn) {
23-
$this->writeNewLine();
24-
}
21+
if ($this->column === $this->maxColumn) {
22+
$this->writeNewLine();
2523
}
2624
}
2725
}

src/Codeception/Specify/SpecifyHooks.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,15 @@
1515

1616
trait SpecifyHooks
1717
{
18-
private $afterSpecify = [];
18+
private array $afterSpecify = [];
1919

20-
private $beforeSpecify = [];
20+
private array $beforeSpecify = [];
2121

22-
/**
23-
* @var DeepCopy
24-
*/
25-
private $copier;
22+
private ?DeepCopy $copier = null;
2623

27-
/**
28-
* @var SpecifyTest
29-
*/
30-
private $currentSpecifyTest;
24+
private ?SpecifyTest $currentSpecifyTest = null;
3125

32-
private $specifyName = '';
26+
private string $specifyName = '';
3327

3428
private function getCurrentSpecifyTest(): SpecifyTest
3529
{
@@ -43,7 +37,7 @@ private function getCurrentSpecifyTest(): SpecifyTest
4337
*/
4438
private function runSpec(string $specification, Closure $callable = null, $params = [])
4539
{
46-
if (!$callable) {
40+
if ($callable === null) {
4741
return;
4842
}
4943

@@ -106,8 +100,10 @@ private function getSpecifyExamples($params): array
106100
if (!is_array($params['examples'])) {
107101
throw new RuntimeException("Examples should be an array");
108102
}
103+
109104
return $params['examples'];
110105
}
106+
111107
return [[]];
112108
}
113109

@@ -116,6 +112,7 @@ private function specifyGetPhpUnitReflection(): ?ReflectionClass
116112
if ($this instanceof TestCase) {
117113
return new ReflectionClass(TestCase::class);
118114
}
115+
119116
return null;
120117
}
121118

@@ -161,7 +158,8 @@ private function getSpecifyObjectProperties(): array
161158
if (!$docBlock) {
162159
continue;
163160
}
164-
if (preg_match('~\*(\s+)?@specify\s?~', $docBlock)) {
161+
162+
if (preg_match('#\*(\s+)?@specify\s?#', $docBlock)) {
165163
$property->setAccessible(true);
166164
$clonedProperties[] = new ObjectProperty($this, $property);
167165
}

src/Codeception/Specify/SpecifyTest.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,29 @@
1212

1313
class SpecifyTest implements Test, SelfDescribing
1414
{
15-
protected $name;
15+
protected string $name = '';
1616

17-
protected $test;
17+
/** @var callable */
18+
protected $test = null;
1819

19-
protected $example;
20+
protected array $example = [];
2021

22+
/**
23+
* @var mixed|null
24+
*/
2125
protected $throws;
2226

23-
public function __construct($test)
27+
public function __construct(callable $test)
2428
{
2529
$this->test = $test;
2630
}
2731

28-
public function setName($name)
32+
public function setName(string $name): void
2933
{
3034
$this->name = $name;
3135
}
3236

33-
public function toString() : string
37+
public function toString(): string
3438
{
3539
return $this->name;
3640
}
@@ -49,8 +53,7 @@ public function getName($withDataSet = true): string
4953
* Count elements of an object
5054
* @link http://php.net/manual/en/countable.count.php
5155
* @return int The custom count as an integer.
52-
* </p>
53-
* <p>
56+
*
5457
* The return value is cast to an integer.
5558
* @since 5.1.0
5659
*/
@@ -61,33 +64,27 @@ public function count(): int
6164

6265
/**
6366
* Runs a test and collects its result in a TestResult instance.
64-
*
65-
* @param TestResult|null $result
66-
*
67-
* @return TestResult
6867
*/
6968
public function run(TestResult $result = null): TestResult
7069
{
7170
try {
7271
call_user_func_array($this->test, $this->example);
73-
} catch (AssertionFailedError $e) {
74-
$result->addFailure(clone($this), $e, $result->time());
72+
} catch (AssertionFailedError $error) {
73+
$result->addFailure(clone($this), $error, $result->time());
7574
}
75+
7676
return $result;
7777
}
7878

79-
/**
80-
* @param mixed $example
81-
*/
82-
public function setExample($example)
79+
public function setExample(array $example): void
8380
{
8481
$this->example = $example;
8582
}
8683

8784
/**
8885
* @param mixed $throws
8986
*/
90-
public function setThrows($throws)
87+
public function setThrows($throws): void
9188
{
9289
$this->throws = $throws;
9390
}

tests/ObjectPropertyTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
final class ObjectPropertyTest extends SpecifyUnitTest
88
{
9+
private ?string $prop = null;
10+
911
private $private = 'private';
1012

1113
public function testConstruction()

0 commit comments

Comments
 (0)