Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update codebase to PHP 7.4 #55

Merged
merged 2 commits into from Nov 22, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
php: [7.3, 7.4, 8.0]
php: [7.4, 8.0, 8.1]

steps:
- name: Checkout code
Expand All @@ -26,4 +26,4 @@ jobs:
run: composer update --prefer-dist --no-progress --no-interaction

- name: Run test suite
run: php vendor/bin/phpunit
run: php vendor/bin/phpunit
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -13,7 +13,7 @@ Inspired by MiniTest of Ruby now you combine BDD and classical TDD style in one

## Installation

*Requires PHP >= 7.3*
*Requires PHP >= 7.4*

* Install with Composer:

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -14,7 +14,7 @@
}
],
"require": {
"php": ">=7.3.0",
"php": ">=7.4.0",
"myclabs/deep-copy": "^1.10",
"phpunit/phpunit": "^8.0|^9.0"
},
Expand Down
5 changes: 5 additions & 0 deletions src/Codeception/Specify.php
Expand Up @@ -23,6 +23,7 @@ public function specify(string $thing, Closure $code = null, $examples = []): ?s
$this->runSpec($thing, $code, $examples);
return null;
}

return $this;
}

Expand All @@ -32,6 +33,7 @@ public function describe(string $feature, Closure $code = null): ?self
$this->runSpec($feature, $code);
return null;
}

return $this;
}

Expand All @@ -41,6 +43,7 @@ public function it(string $specification, Closure $code = null, $examples = []):
$this->runSpec($specification, $code, $examples);
return $this;
}

TestCase::markTestIncomplete();
return $this;
}
Expand All @@ -56,6 +59,7 @@ public function should(string $behavior, Closure $code = null, $examples = []):
$this->runSpec('should ' . $behavior, $code, $examples);
return $this;
}

TestCase::markTestIncomplete();
return $this;
}
Expand All @@ -66,6 +70,7 @@ public function shouldNot(string $behavior, Closure $code = null, $examples = []
$this->runSpec('should not ' . $behavior, $code, $examples);
return $this;
}

TestCase::markTestIncomplete();
return $this;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Codeception/Specify/ObjectProperty.php
Expand Up @@ -46,7 +46,7 @@ public function __construct($owner, $property, $value = null)

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

$this->initValue = ($value === null ? $this->getValue() : $value);
$this->initValue = ($value ?? $this->getValue());
}

public function getName(): string
Expand All @@ -57,7 +57,7 @@ public function getName(): string
/**
* Restores initial value
*/
public function restoreValue()
public function restoreValue(): void
{
$this->setValue($this->initValue);
}
Expand All @@ -73,7 +73,7 @@ public function getValue()
/**
* @param mixed $value
*/
public function setValue($value)
public function setValue($value): void
{
$this->property->setValue($this->owner, $value);
}
Expand Down
10 changes: 4 additions & 6 deletions src/Codeception/Specify/ResultPrinter.php
Expand Up @@ -15,13 +15,11 @@ class ResultPrinter extends DefaultResultPrinter
protected function writeProgress(string $progress): void
{
$this->write($progress);
$this->column++;
$this->numTestsRun++;
++$this->column;
++$this->numTestsRun;

if ($this->column == $this->maxColumn || $this->numTestsRun == $this->numTests) {
if ($this->column == $this->maxColumn) {
$this->writeNewLine();
}
if ($this->column === $this->maxColumn) {
$this->writeNewLine();
}
}
}
24 changes: 11 additions & 13 deletions src/Codeception/Specify/SpecifyHooks.php
Expand Up @@ -15,21 +15,15 @@

trait SpecifyHooks
{
private $afterSpecify = [];
private array $afterSpecify = [];

private $beforeSpecify = [];
private array $beforeSpecify = [];

/**
* @var DeepCopy
*/
private $copier;
private ?DeepCopy $copier = null;

/**
* @var SpecifyTest
*/
private $currentSpecifyTest;
private ?SpecifyTest $currentSpecifyTest = null;

private $specifyName = '';
private string $specifyName = '';

private function getCurrentSpecifyTest(): SpecifyTest
{
Expand All @@ -43,7 +37,7 @@ private function getCurrentSpecifyTest(): SpecifyTest
*/
private function runSpec(string $specification, Closure $callable = null, $params = [])
{
if (!$callable) {
if ($callable === null) {
return;
}

Expand Down Expand Up @@ -106,8 +100,10 @@ private function getSpecifyExamples($params): array
if (!is_array($params['examples'])) {
throw new RuntimeException("Examples should be an array");
}

return $params['examples'];
}

return [[]];
}

Expand All @@ -116,6 +112,7 @@ private function specifyGetPhpUnitReflection(): ?ReflectionClass
if ($this instanceof TestCase) {
return new ReflectionClass(TestCase::class);
}

return null;
}

Expand Down Expand Up @@ -161,7 +158,8 @@ private function getSpecifyObjectProperties(): array
if (!$docBlock) {
continue;
}
if (preg_match('~\*(\s+)?@specify\s?~', $docBlock)) {

if (preg_match('#\*(\s+)?@specify\s?#', $docBlock)) {
$property->setAccessible(true);
$clonedProperties[] = new ObjectProperty($this, $property);
}
Expand Down
35 changes: 16 additions & 19 deletions src/Codeception/Specify/SpecifyTest.php
Expand Up @@ -12,25 +12,29 @@

class SpecifyTest implements Test, SelfDescribing
{
protected $name;
protected string $name = '';

protected $test;
/** @var callable */
protected $test = null;

protected $example;
protected array $example = [];

/**
* @var mixed|null
*/
protected $throws;

public function __construct($test)
public function __construct(callable $test)
{
$this->test = $test;
}

public function setName($name)
public function setName(string $name): void
{
$this->name = $name;
}

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

/**
* Runs a test and collects its result in a TestResult instance.
*
* @param TestResult|null $result
*
* @return TestResult
*/
public function run(TestResult $result = null): TestResult
{
try {
call_user_func_array($this->test, $this->example);
} catch (AssertionFailedError $e) {
$result->addFailure(clone($this), $e, $result->time());
} catch (AssertionFailedError $error) {
$result->addFailure(clone($this), $error, $result->time());
}

return $result;
}

/**
* @param mixed $example
*/
public function setExample($example)
public function setExample(array $example): void
{
$this->example = $example;
}

/**
* @param mixed $throws
*/
public function setThrows($throws)
public function setThrows($throws): void
{
$this->throws = $throws;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ObjectPropertyTest.php
Expand Up @@ -6,6 +6,8 @@

final class ObjectPropertyTest extends SpecifyUnitTest
{
private ?string $prop = null;

private $private = 'private';

public function testConstruction()
Expand Down