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

Test why CI / Code validation (push) fails #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
59 changes: 11 additions & 48 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,31 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: MilesChou/composer-action/install@master
- uses: docker://php:7.3-alpine
- uses: MilesChou/composer-action/8.0/install@master
- uses: docker://php:8.0-alpine
with:
args: vendor/bin/phpcs --colors -p --standard=PSR2 -s src
- uses: MilesChou/composer-action@master
with:
args: require --dev phpstan/phpstan
- uses: docker://php:7.3-alpine
- uses: docker://php:8.0-alpine
with:
args: vendor/bin/phpstan analyze src --level=7
php56:
name: Test on PHP 5.6
php80:
name: Test on PHP 8.0
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: MilesChou/composer-action/5.6/install@master
- uses: docker://php:5.6-alpine
- uses: MilesChou/composer-action/8.0/install@master
- uses: docker://php:8.0-alpine
with:
args: vendor/bin/codecept run
php70:
name: Test on PHP 7.0
php81:
name: Test on PHP 8.1
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: MilesChou/composer-action/7.0/install@master
- uses: docker://php:7.0-alpine
with:
args: vendor/bin/codecept run
php71:
name: Test on PHP 7.1
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: MilesChou/composer-action/7.1/install@master
- uses: docker://php:7.1-alpine
with:
args: vendor/bin/codecept run
php72:
name: Test on PHP 7.2
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: MilesChou/composer-action/7.2/install@master
- uses: docker://php:7.2-alpine
with:
args: vendor/bin/codecept run
php73:
name: Test on PHP 7.3
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: MilesChou/composer-action/7.3/install@master
- uses: docker://php:7.3-alpine
with:
args: vendor/bin/codecept run
php74:
name: Test on PHP 7.4
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
# Install on 7.3 as a 7.4 actions is still not available.
- uses: MilesChou/composer-action/7.3/install@master
- uses: docker://php:7.4-alpine
- uses: MilesChou/composer-action/8.1/install@master
- uses: docker://php:8.1-alpine
with:
args: vendor/bin/codecept run
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Require PHP 8.0, Codeception 5.0.

## [0.2.4] - 2020-02-05
### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class WidgetTest extends Codeception\TestCase\Test
The package is based on the snapshot support added in Codeception since version `2.5.0`, as such the library requirments are:
* PHP 5.6+
* Codeception 2.5+
*

## Installation

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
}
],
"require": {
"php": "^8.0",
"ext-dom": "*",
"gajus/dindent": "^2.0",
"codeception/codeception": "^2.5 || ^3.0 || ^4.0"
"codeception/codeception": "^5.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "*"
Expand Down
65 changes: 22 additions & 43 deletions src/AbstractSnapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@ class AbstractSnapshot extends Snapshot
*/
protected static $traitMethods = [];

/**
* The current content.
*
* @var string
*/
protected $current = '';

/**
* The callback that will be called on each data entry of the snapshot.
*
Expand All @@ -54,18 +47,16 @@ class AbstractSnapshot extends Snapshot
*
* @param mixed $current The current value.
*/
public function __construct($current = null)
public function __construct(protected $current = null)
{
$this->current = $current;
}

/**
* Returns the absolute path to the snapshot file that has been, or will be, generated.
*
* @return string
* @throws \ReflectionException If there's an error while building the class reflection.
*/
public function snapshotFileName()
public function snapshotFileName(): string
{
return $this->getFileName();
}
Expand All @@ -76,14 +67,14 @@ public function snapshotFileName()
* @return string The snapshot file name, including the file extension.
* @throws \ReflectionException If the class that called the class cannot be reflected.
*/
protected function getFileName()
protected function getFileName(): string
{
if (empty($this->fileName)) {
$traitMethods = static::getTraitMethods();
$backtrace = array_values(array_filter(
debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS
| DEBUG_BACKTRACE_PROVIDE_OBJECT, 5),
static function (array $backtraceEntry) use ($traitMethods) {
static function (array $backtraceEntry) use ($traitMethods): bool {
return !in_array(
$backtraceEntry['class'],
[Snapshot::class, static::class, self::class, SnapshotAssertions::class],
Expand Down Expand Up @@ -132,14 +123,14 @@ static function (array $backtraceEntry) use ($traitMethods) {
*
* @throws \ReflectionException If a reflection cannot be done on a trait method.
*/
protected static function getTraitMethods()
protected static function getTraitMethods(): array
{
if (!empty(static::$traitMethods)) {
return static::$traitMethods;
}

$reflection = new \ReflectionClass(SnapshotAssertions::class);
static::$traitMethods = array_map(function (\ReflectionMethod $method) {
static::$traitMethods = array_map(function (\ReflectionMethod $method): string {
return $method->name;
}, $reflection->getMethods());

Expand All @@ -155,7 +146,7 @@ protected static function getTraitMethods()
*
* @return int The counter, managed on a static level, for the combination.
*/
protected function getCounterFor($class, $function, $dataSetName = '')
protected function getCounterFor(string $class, string $function, string $dataSetName = '')
{
$function .= $dataSetName;

Expand All @@ -171,7 +162,7 @@ protected function getCounterFor($class, $function, $dataSetName = '')
*
* @return string The file extension, without the leading dot, of the snapshot the class will generate.
*/
public function fileExtension()
public function fileExtension(): string
{
return 'snapshot';
}
Expand All @@ -184,10 +175,8 @@ public function fileExtension()
* @param mixed $contents The snapshot contents.
*
* @throws \ReflectionException
*
* @return void
*/
public function snapshotPutContents($contents)
public function snapshotPutContents(string|bool $contents): void
{
$dataSetBackup = $this->dataSet;
$this->dataSet = $contents;
Expand All @@ -199,10 +188,8 @@ public function snapshotPutContents($contents)
* Saves the snapshot contents to the snapshot file.
*
* @throws \Exception If there's an issue reading or saving the snapshot.
*
* @return void
*/
protected function save()
protected function save(): void
{
$fileName = $this->getFileName();
$snapshotsDir = dirname($fileName);
Expand All @@ -219,19 +206,18 @@ protected function save()
*
* @return mixed The prepared snapshot contents.
*/
public function prepareSnapshotForDump()
public function prepareSnapshotForDump(): string|bool
{
return $this->dataSet;
}

/**
* Asserts the current contents match the contents of the snapshot.
*
* @return void
*
* @throws \ReflectionException If there's an issue building the snapshot file name.
*/
public function assert()
public function assert(): void
{
// Fetch data.
$data = $this->fetchData();
Expand Down Expand Up @@ -279,7 +265,7 @@ public function assert()
*
* @return mixed The fetched data, the current data by default.
*/
protected function fetchData()
protected function fetchData(): array|string|false
{
return $this->current;
}
Expand All @@ -293,19 +279,18 @@ protected function fetchData()
*
* @return bool Whether the data can be considered empty, hence invalid, or not.
*/
protected function isEmptyData($data)
protected function isEmptyData($data): bool
{
return !$data;
}

/**
* Loads the data set from the snapshot.
*
* @return void
*
* @throws \ReflectionException
*/
protected function load()
protected function load(): void
{
if (!file_exists($this->getFileName())) {
return;
Expand All @@ -326,7 +311,7 @@ protected function load()
*/
protected function printDebug($message)
{
Debug::debug(get_class($this).': '.$message);
Debug::debug($this::class.': '.$message);
}
/**
* Returns the data name taking care of doing so in a way that is compatible with different PHPUnit versions.
Expand All @@ -335,20 +320,20 @@ protected function printDebug($message)
*
* @return string The data name if available or an empty string if not available.
*/
protected function getDataName(TestCase $testCase)
protected function getDataName(TestCase $testCase): string
{
if (method_exists($testCase, 'dataName')) {
return (string)$testCase->dataName();
}

$candidates = array_reverse(class_parents($testCase));
$testCaseClass = get_class($testCase);
$testCaseClass = $testCase::class;
$candidates[$testCaseClass] = $testCaseClass;
$read = '';
foreach (array_reverse($candidates) as $class) {
try {
$read = (string)ReflectionHelper::readPrivateProperty($testCase, 'dataName', $class);
} catch (\ReflectionException $e) {
} catch (\ReflectionException) {
continue;
}
break;
Expand All @@ -361,10 +346,8 @@ protected function getDataName(TestCase $testCase)
* Overrides the base implementation to add a pre-assertion data handler.
*
* @param mixed $data The data to check.
*
* @return void
*/
protected function assertData($data)
protected function assertData(mixed $data): void
{
if ($this->dataVisitor !== null) {
list($data, $dataSet) = call_user_func($this->dataVisitor, $data, $this->dataSet);
Expand All @@ -380,10 +363,8 @@ protected function assertData($data)
* @param callable $dataVisitor The data visitor that will be called on each visit of a snapshot "node".
* The parameters passed to the visitor will be different for each snapshot; usually
* the expected data and the current data.
*
* @return void
*/
public function setDataVisitor(callable $dataVisitor)
public function setDataVisitor(callable $dataVisitor): void
{
$this->dataVisitor = $dataVisitor;
}
Expand All @@ -394,10 +375,8 @@ public function setDataVisitor(callable $dataVisitor)
* @param string $snapshotFileName The absolute path to the file the snapshot file should use.
* This value is, usually, the one produced by another snapshot `snapshotFileName()`
* method.
*
* @return void
*/
public function setSnapshotFileName($snapshotFileName)
public function setSnapshotFileName(string $snapshotFileName): void
{
$this->fileName = $snapshotFileName;
}
Expand Down
5 changes: 2 additions & 3 deletions src/CodeSnapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ class CodeSnapshot extends StringSnapshot
{
/**
* The file extension of the produced snapshots in the format, without the leading dot.
* @var string
*/
protected $extension;
protected string $extension;

/**
* CodeSnapshot constructor.
Expand All @@ -34,7 +33,7 @@ public function __construct($current = null, $extension = 'php')
/**
* {@inheritDoc}
*/
public function fileExtension()
public function fileExtension(): string
{
return 'snapshot.'.$this->extension;
}
Expand Down
Loading