From 8fdacfdf9b76ca8b14de9c8d4b455b6f538cd4d3 Mon Sep 17 00:00:00 2001 From: Mitchell Macpherson Date: Tue, 10 Nov 2020 03:40:21 +1100 Subject: [PATCH 01/14] Centralised repeated code Simplified 'Printer' class designator Added PHPUnit 6 support --- .github/workflows/push.yml | 2 +- composer.json | 1 + src/Functions/helpers.php | 122 +++++++++++++++++++++++++++++ src/Printer.php | 28 ++----- src/Printer6.php | 37 +++++++++ src/Printer7.php | 76 +----------------- src/Printer8.php | 32 +++++++- src/Printer9.php | 5 +- src/Trait8.php | 108 ------------------------- test/_files/HelperFunctionTest.php | 64 +++++++++++++++ 10 files changed, 266 insertions(+), 209 deletions(-) create mode 100644 src/Functions/helpers.php create mode 100644 src/Printer6.php delete mode 100644 src/Trait8.php create mode 100644 test/_files/HelperFunctionTest.php diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index b5482b5..3ffa600 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -10,7 +10,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] php-versions: ["7.3", "7.4"] - phpunit-version: ["7", "8", "9"] + phpunit-version: ["6", "7", "8", "9"] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.os }} (PHPUnit ${{ matrix.phpunit-version }}) steps: - name: Checkout diff --git a/composer.json b/composer.json index 1f4c881..ba9e60d 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,7 @@ } ], "autoload": { + "files": ["src/Functions/helpers.php"], "psr-4": { "mheap\\GithubActionsReporter\\": "src" } diff --git a/src/Functions/helpers.php b/src/Functions/helpers.php new file mode 100644 index 0000000..c316016 --- /dev/null +++ b/src/Functions/helpers.php @@ -0,0 +1,122 @@ +=') == true && + ($upperVersion === true || version_compare($version, $upperVersion, '<=') == true) + ) { + return $class; + } + } + + return null; +} + +/** + * @param TestFailure $defect + * + * @return string + * @throws \ReflectionException + * @internal + */ +function printDefectTrace($defect) +{ + $e = $defect->thrownException(); + + $errorLines = array_filter( + explode("\n", (string)$e), + static function ($l) { + return $l; + } + ); + + $error = end($errorLines); + $lineIndex = strrpos($error, ":"); + $path = substr($error, 0, $lineIndex); + $line = substr($error, $lineIndex + 1); + + list($reflectedPath, $reflectedLine) = getReflectionFromTest( + $defect->getTestName() + ); + + if ($path !== $reflectedPath) { + $path = $reflectedPath; + $line = $reflectedLine; + } + + $message = explode("\n", $defect->getExceptionAsString()); + $message = implode('%0A', $message); + + // Some messages might contain paths. Let's convert thost to relative paths too + $message = relativePath($message); + $message = preg_replace('/%0A$/', '', $message); + + $type = $defect->isFailure() ? 'error' : 'warning'; + $path = relativePath($path); + $file = "file={$path}"; + $line = "line={$line}"; + + return "::{$type} $file,$line::{$message}\n"; +} + +/** + * @param string $path + * + * @return mixed + * @internal + */ +function relativePath($path) +{ + $relative = str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $path); + + // Translate \ in to / for Windows + return str_replace('\\', '/', $relative); +} + +/** + * @param string $name + * + * @return array + * @throws \ReflectionException + * @internal + */ +function getReflectionFromTest($name) +{ + list($klass, $method) = explode('::', $name); + + // Handle data providers + $parts = explode(" ", $method, 2); + if (count($parts) > 1) { + $method = $parts[0]; + } + + $c = new ReflectionClass($klass); + $m = $c->getMethod($method); + + return [$m->getFileName(), $m->getStartLine()]; +} diff --git a/src/Printer.php b/src/Printer.php index 28774a5..14a3057 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -5,31 +5,15 @@ namespace mheap\GithubActionsReporter; use PHPUnit\Runner\Version; -use PHPUnit_TextUI_ResultPrinter; -$low = version_compare(Version::series(), '7.0', '>='); -$high = version_compare(Version::series(), '7.99.99', '<='); +use function mheap\GithubActionsReporter\Functions\determinePrinter; -if ($low && $high) { - class Printer extends Printer7 - { - } -} - -$low = version_compare(Version::series(), '8.0', '>='); -$high = version_compare(Version::series(), '8.99.99', '<='); +$class = determinePrinter(Version::series()); -if ($low && $high) { - class Printer extends Printer8 - { - } +if ($class === null) { + throw new \RuntimeException('Unable to find supporting PHPUnit print for your version'); } -$low = version_compare(Version::series(), '9.0', '>='); -$high = true; // version_compare(Version::series(),'8.99.99','<='); - -if ($low && $high) { - class Printer extends Printer9 - { - } +if (class_alias($class, '\mheap\GithubActionsReporter\Printer') === false) { + throw new \RuntimeException('Unable to setup autoloading alias for printer'); } diff --git a/src/Printer6.php b/src/Printer6.php new file mode 100644 index 0000000..04d4aab --- /dev/null +++ b/src/Printer6.php @@ -0,0 +1,37 @@ +write(printDefectTrace($defect)); + } +} diff --git a/src/Printer7.php b/src/Printer7.php index 6ad7a21..bd59fa3 100644 --- a/src/Printer7.php +++ b/src/Printer7.php @@ -6,6 +6,8 @@ use PHPUnit\Framework\TestFailure; use PHPUnit\Framework\TestResult; +use function mheap\GithubActionsReporter\Functions\printDefectTrace; + class Printer7 extends ResultPrinter { protected $currentType = null; @@ -24,11 +26,6 @@ protected function printFooter(TestResult $result): void protected function printDefects(array $defects, string $type): void { - $this->currentType = $type; - - foreach ($defects as $i => $defect) { - $this->printDefect($defect, $i); - } } protected function printDefectHeader(TestFailure $defect, int $count): void @@ -37,73 +34,6 @@ protected function printDefectHeader(TestFailure $defect, int $count): void protected function printDefectTrace(TestFailure $defect): void { - $e = $defect->thrownException(); - - $errorLines = array_filter( - explode("\n", (string)$e), - function ($l) { - return $l; - } - ); - - $error = end($errorLines); - $lineIndex = strrpos($error, ":"); - $path = substr($error, 0, $lineIndex); - $line = substr($error, $lineIndex + 1); - - list($reflectedPath, $reflectedLine) = $this->getReflectionFromTest( - $defect->getTestName() - ); - - if ($path !== $reflectedPath) { - $path = $reflectedPath; - $line = $reflectedLine; - } - - $message = explode("\n", $defect->getExceptionAsString()); - $message = implode('%0A', $message); - - // Some messages might contain paths. Let's convert thost to relative paths too - $message = $this->relativePath($message); - - $message = preg_replace('/%0A$/', '', $message); - - $type = $this->getCurrentType(); - $file = "file={$this->relativePath($path)}"; - $line = "line={$line}"; - $this->write("::{$type} $file,$line::{$message}\n"); - } - - protected function getCurrentType() - { - if (in_array($this->currentType, ['error', 'failure'])) { - return 'error'; - } - - return 'warning'; - } - - protected function relativePath(string $path) - { - $relative = str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $path); - // Translate \ in to / for Windows - $relative = str_replace('\\', '/', $relative); - return $relative; - } - - protected function getReflectionFromTest(string $name) - { - list($klass, $method) = explode('::', $name); - - // Handle data providers - $parts = explode(" ", $method, 2); - if (count($parts) > 1) { - $method = $parts[0]; - } - - $c = new \ReflectionClass($klass); - $m = $c->getMethod($method); - - return [$m->getFileName(), $m->getStartLine()]; + $this->write(printDefectTrace($defect)); } } diff --git a/src/Printer8.php b/src/Printer8.php index f5b2336..8e74815 100644 --- a/src/Printer8.php +++ b/src/Printer8.php @@ -2,9 +2,39 @@ namespace mheap\GithubActionsReporter; +use PHPUnit\Framework\TestFailure; +use PHPUnit\Framework\TestResult; use PHPUnit\TextUI\ResultPrinter; +use function mheap\GithubActionsReporter\Functions\getCurrentType; +use function mheap\GithubActionsReporter\Functions\printDefects; + class Printer8 extends ResultPrinter { - use Trait8; + protected $currentType = null; + + protected function printHeader(TestResult $result): void + { + } + + protected function writeProgress(string $progress): void + { + } + + protected function printFooter(TestResult $result): void + { + } + + protected function printDefects(array $defects, string $type): void + { + $this->write(printDefects($defects, $type)); + } + + protected function printDefectHeader(TestFailure $defect, int $count): void + { + } + + protected function printDefectTrace(TestFailure $defect): void + { + } } diff --git a/src/Printer9.php b/src/Printer9.php index 6b5cc7e..78a2a2f 100644 --- a/src/Printer9.php +++ b/src/Printer9.php @@ -2,9 +2,6 @@ namespace mheap\GithubActionsReporter; -use PHPUnit\TextUI\DefaultResultPrinter; - -class Printer9 extends DefaultResultPrinter +class Printer9 extends Printer8 { - use Trait8; } diff --git a/src/Trait8.php b/src/Trait8.php deleted file mode 100644 index 0ef2a2f..0000000 --- a/src/Trait8.php +++ /dev/null @@ -1,108 +0,0 @@ -currentType = $type; - - foreach ($defects as $i => $defect) { - $this->printDefect($defect, $i); - } - } - - protected function printDefectHeader(TestFailure $defect, int $count): void - { - } - - protected function printDefectTrace(TestFailure $defect): void - { - $e = $defect->thrownException(); - - $errorLines = array_filter( - explode("\n", (string)$e), - function ($l) { - return $l; - } - ); - - $error = end($errorLines); - $lineIndex = strrpos($error, ":"); - $path = substr($error, 0, $lineIndex); - $line = substr($error, $lineIndex + 1); - - list($reflectedPath, $reflectedLine) = $this->getReflectionFromTest( - $defect->getTestName() - ); - - if ($path !== $reflectedPath) { - $path = $reflectedPath; - $line = $reflectedLine; - } - - $message = explode("\n", $defect->getExceptionAsString()); - $message = implode('%0A', $message); - - // Some messages might contain paths. Let's convert thost to relative paths too - $message = $this->relativePath($message); - - $message = preg_replace('/%0A$/', '', $message); - - $type = $this->getCurrentType(); - $file = "file={$this->relativePath($path)}"; - $line = "line={$line}"; - $this->write("::{$type} $file,$line::{$message}\n"); - } - - protected function getCurrentType() - { - if (in_array($this->currentType, ['error', 'failure'])) { - return 'error'; - } - - return 'warning'; - } - - protected function relativePath(string $path) - { - $relative = str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $path); - // Translate \ in to / for Windows - $relative = str_replace('\\', '/', $relative); - return $relative; - } - - protected function getReflectionFromTest(string $name) - { - list($klass, $method) = explode('::', $name); - - // Handle data providers - $parts = explode(" ", $method, 2); - if (count($parts) > 1) { - $method = $parts[0]; - } - - $c = new \ReflectionClass($klass); - $m = $c->getMethod($method); - - return [$m->getFileName(), $m->getStartLine()]; - } -} diff --git a/test/_files/HelperFunctionTest.php b/test/_files/HelperFunctionTest.php new file mode 100644 index 0000000..ebb9bfb --- /dev/null +++ b/test/_files/HelperFunctionTest.php @@ -0,0 +1,64 @@ + [ + 'version' => 'aaa', + 'expected' => null + ]; + + yield 'minor version 9.4' => [ + 'version' => '9.4', + 'expected' => Printer9::class + ]; + + yield 'major version 9' => [ + 'version' => '9.0', + 'expected' => Printer9::class + ]; + + yield 'minor version 9.1' => [ + 'version' => '9.1', + 'expected' => Printer9::class + ]; + + yield 'minor version 8.2' => [ + 'version' => '8.2', + 'expected' => Printer8::class + ]; + + yield 'patch version 7.0.1' => [ + 'version' => '7.0.1', + 'expected' => Printer7::class + ]; + + yield 'minor version 6.5' => [ + 'version' => '6.5', + 'expected' => Printer6::class + ]; + + yield 'minor version 5' => [ + 'version' => '5.0', + 'expected' => null + ]; + } + /** + * @dataProvider getInputsForVersionSelection() + */ + public function testVersionSelector($version, $expected): void + { + $result = determinePrinter($version); + + self::assertSame($expected, $result); + } +} From c415071f28061f13c124e471a5261a3fb1c486db Mon Sep 17 00:00:00 2001 From: Mitchell Macpherson Date: Tue, 10 Nov 2020 03:46:24 +1100 Subject: [PATCH 02/14] Update setup-php version in GHA --- .github/workflows/push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 3ffa600..c0adb06 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -17,7 +17,7 @@ jobs: uses: actions/checkout@v2 - name: Setup PHP - uses: shivammathur/setup-php@v1 + uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php-versions }} extensions: mbstring From ebb02cf7b05df7e8d87fa886e8e0f8cf12289f87 Mon Sep 17 00:00:00 2001 From: Mitchell Macpherson Date: Tue, 10 Nov 2020 04:11:21 +1100 Subject: [PATCH 03/14] Fixed some PEBKAC --- src/Functions/helpers.php | 6 +++--- src/Printer6.php | 15 +++++++++++++- src/Printer7.php | 12 +++++++++-- src/Printer8.php | 13 ++++++++++-- src/Printer9.php | 42 ++++++++++++++++++++++++++++++++++++++- 5 files changed, 79 insertions(+), 9 deletions(-) diff --git a/src/Functions/helpers.php b/src/Functions/helpers.php index c316016..e4a770e 100644 --- a/src/Functions/helpers.php +++ b/src/Functions/helpers.php @@ -39,12 +39,13 @@ function determinePrinter($version) /** * @param TestFailure $defect + * @param string $defectType * * @return string * @throws \ReflectionException * @internal */ -function printDefectTrace($defect) +function printDefectTrace($defect, $defectType) { $e = $defect->thrownException(); @@ -76,12 +77,11 @@ static function ($l) { $message = relativePath($message); $message = preg_replace('/%0A$/', '', $message); - $type = $defect->isFailure() ? 'error' : 'warning'; $path = relativePath($path); $file = "file={$path}"; $line = "line={$line}"; - return "::{$type} $file,$line::{$message}\n"; + return "::{$defectType} $file,$line::{$message}\n"; } /** diff --git a/src/Printer6.php b/src/Printer6.php index 04d4aab..e442f2d 100644 --- a/src/Printer6.php +++ b/src/Printer6.php @@ -10,6 +10,11 @@ class Printer6 extends ResultPrinter { + /** + * @var null|string + */ + private $currentType; + protected function printHeader(): void { } @@ -24,14 +29,22 @@ protected function printFooter(TestResult $result): void protected function printDefects(array $defects, $type): void { + $this->currentType = (in_array($type, ['error', 'failure']) === true) ? 'error' : 'warning'; + + foreach ($defects as $i => $defect) { + $this->printDefect($defect, $i); + } } protected function printDefectHeader(TestFailure $defect, $count): void { } + /** + * @throws \ReflectionException + */ protected function printDefectTrace(TestFailure $defect): void { - $this->write(printDefectTrace($defect)); + $this->write(printDefectTrace($defect, $this->currentType)); } } diff --git a/src/Printer7.php b/src/Printer7.php index bd59fa3..ee9f9c5 100644 --- a/src/Printer7.php +++ b/src/Printer7.php @@ -10,7 +10,10 @@ class Printer7 extends ResultPrinter { - protected $currentType = null; + /** + * @var null|string + */ + private $currentType; protected function printHeader(): void { @@ -26,6 +29,11 @@ protected function printFooter(TestResult $result): void protected function printDefects(array $defects, string $type): void { + $this->currentType = (in_array($type, ['error', 'failure']) === true) ? 'error' : 'warning'; + + foreach ($defects as $i => $defect) { + $this->printDefect($defect, $i); + } } protected function printDefectHeader(TestFailure $defect, int $count): void @@ -34,6 +42,6 @@ protected function printDefectHeader(TestFailure $defect, int $count): void protected function printDefectTrace(TestFailure $defect): void { - $this->write(printDefectTrace($defect)); + $this->write(printDefectTrace($defect, $this->currentType)); } } diff --git a/src/Printer8.php b/src/Printer8.php index 8e74815..ed51138 100644 --- a/src/Printer8.php +++ b/src/Printer8.php @@ -8,10 +8,14 @@ use function mheap\GithubActionsReporter\Functions\getCurrentType; use function mheap\GithubActionsReporter\Functions\printDefects; +use function mheap\GithubActionsReporter\Functions\printDefectTrace; class Printer8 extends ResultPrinter { - protected $currentType = null; + /** + * @var null|string + */ + private $currentType; protected function printHeader(TestResult $result): void { @@ -27,7 +31,11 @@ protected function printFooter(TestResult $result): void protected function printDefects(array $defects, string $type): void { - $this->write(printDefects($defects, $type)); + $this->currentType = (in_array($type, ['error', 'failure']) === true) ? 'error' : 'warning'; + + foreach ($defects as $i => $defect) { + $this->printDefect($defect, $i); + } } protected function printDefectHeader(TestFailure $defect, int $count): void @@ -36,5 +44,6 @@ protected function printDefectHeader(TestFailure $defect, int $count): void protected function printDefectTrace(TestFailure $defect): void { + $this->write(printDefectTrace($defect, $this->currentType)); } } diff --git a/src/Printer9.php b/src/Printer9.php index 78a2a2f..89c31bc 100644 --- a/src/Printer9.php +++ b/src/Printer9.php @@ -2,6 +2,46 @@ namespace mheap\GithubActionsReporter; -class Printer9 extends Printer8 +use PHPUnit\Framework\TestFailure; +use PHPUnit\Framework\TestResult; +use PHPUnit\TextUI\DefaultResultPrinter; + +use function mheap\GithubActionsReporter\Functions\printDefectTrace; + +class Printer9 extends DefaultResultPrinter { + /** + * @var null|string + */ + private $currentType; + + protected function printHeader(TestResult $result): void + { + } + + protected function writeProgress(string $progress): void + { + } + + protected function printFooter(TestResult $result): void + { + } + + protected function printDefects(array $defects, string $type): void + { + $this->currentType = (in_array($type, ['error', 'failure']) === true) ? 'error' : 'warning'; + + foreach ($defects as $i => $defect) { + $this->printDefect($defect, $i); + } + } + + protected function printDefectHeader(TestFailure $defect, int $count): void + { + } + + protected function printDefectTrace(TestFailure $defect): void + { + $this->write(printDefectTrace($defect, $this->currentType)); + } } From 8e1280f4bd6b88d2b0a73ac5bbb10c2cc0209b5d Mon Sep 17 00:00:00 2001 From: Mitchell Macpherson Date: Tue, 10 Nov 2020 04:15:52 +1100 Subject: [PATCH 04/14] Fixed PHPCS --- src/Functions/helpers.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Functions/helpers.php b/src/Functions/helpers.php index e4a770e..4167bc5 100644 --- a/src/Functions/helpers.php +++ b/src/Functions/helpers.php @@ -27,7 +27,8 @@ function determinePrinter($version) ]; foreach ($versionMatrix as list($lowerVersion, $upperVersion, $class)) { - if (version_compare($version, $lowerVersion, '>=') == true && + if ( + version_compare($version, $lowerVersion, '>=') == true && ($upperVersion === true || version_compare($version, $upperVersion, '<=') == true) ) { return $class; From 056db3598c92ba939075014b95432b060f96f782 Mon Sep 17 00:00:00 2001 From: Mitchell Macpherson Date: Tue, 10 Nov 2020 04:30:19 +1100 Subject: [PATCH 05/14] Added new test to PHPunit testsuite changed linefeed detection --- phpunit.xml.dist | 3 ++ src/Functions/helpers.php | 5 ++- test/Unit/HelperFunctionTest.php | 64 ++++++++++++++++++++++++++++++ test/_files/HelperFunctionTest.php | 64 ------------------------------ 4 files changed, 71 insertions(+), 65 deletions(-) create mode 100644 test/Unit/HelperFunctionTest.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2b2002c..c31b621 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,6 +14,9 @@ ./test/ + + ./test/Unit/ + diff --git a/src/Functions/helpers.php b/src/Functions/helpers.php index 4167bc5..df7436f 100644 --- a/src/Functions/helpers.php +++ b/src/Functions/helpers.php @@ -76,7 +76,10 @@ static function ($l) { // Some messages might contain paths. Let's convert thost to relative paths too $message = relativePath($message); - $message = preg_replace('/%0A$/', '', $message); + $lineFeedPosition = strpos($message, '%0A'); + if (is_int($lineFeedPosition) === true) { + $message = substr($message, 0, $lineFeedPosition); + } $path = relativePath($path); $file = "file={$path}"; diff --git a/test/Unit/HelperFunctionTest.php b/test/Unit/HelperFunctionTest.php new file mode 100644 index 0000000..ebb9bfb --- /dev/null +++ b/test/Unit/HelperFunctionTest.php @@ -0,0 +1,64 @@ + [ + 'version' => 'aaa', + 'expected' => null + ]; + + yield 'minor version 9.4' => [ + 'version' => '9.4', + 'expected' => Printer9::class + ]; + + yield 'major version 9' => [ + 'version' => '9.0', + 'expected' => Printer9::class + ]; + + yield 'minor version 9.1' => [ + 'version' => '9.1', + 'expected' => Printer9::class + ]; + + yield 'minor version 8.2' => [ + 'version' => '8.2', + 'expected' => Printer8::class + ]; + + yield 'patch version 7.0.1' => [ + 'version' => '7.0.1', + 'expected' => Printer7::class + ]; + + yield 'minor version 6.5' => [ + 'version' => '6.5', + 'expected' => Printer6::class + ]; + + yield 'minor version 5' => [ + 'version' => '5.0', + 'expected' => null + ]; + } + /** + * @dataProvider getInputsForVersionSelection() + */ + public function testVersionSelector($version, $expected): void + { + $result = determinePrinter($version); + + self::assertSame($expected, $result); + } +} diff --git a/test/_files/HelperFunctionTest.php b/test/_files/HelperFunctionTest.php index ebb9bfb..e69de29 100644 --- a/test/_files/HelperFunctionTest.php +++ b/test/_files/HelperFunctionTest.php @@ -1,64 +0,0 @@ - [ - 'version' => 'aaa', - 'expected' => null - ]; - - yield 'minor version 9.4' => [ - 'version' => '9.4', - 'expected' => Printer9::class - ]; - - yield 'major version 9' => [ - 'version' => '9.0', - 'expected' => Printer9::class - ]; - - yield 'minor version 9.1' => [ - 'version' => '9.1', - 'expected' => Printer9::class - ]; - - yield 'minor version 8.2' => [ - 'version' => '8.2', - 'expected' => Printer8::class - ]; - - yield 'patch version 7.0.1' => [ - 'version' => '7.0.1', - 'expected' => Printer7::class - ]; - - yield 'minor version 6.5' => [ - 'version' => '6.5', - 'expected' => Printer6::class - ]; - - yield 'minor version 5' => [ - 'version' => '5.0', - 'expected' => null - ]; - } - /** - * @dataProvider getInputsForVersionSelection() - */ - public function testVersionSelector($version, $expected): void - { - $result = determinePrinter($version); - - self::assertSame($expected, $result); - } -} From d17d8fdb96ddb018b591aee0831028e1ce9c6138 Mon Sep 17 00:00:00 2001 From: Mitchell Macpherson Date: Tue, 10 Nov 2020 04:32:16 +1100 Subject: [PATCH 06/14] Fixed bug in phpt? --- test/_files/HelperFunctionTest.php | 0 test/states-test.phpt | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 test/_files/HelperFunctionTest.php diff --git a/test/_files/HelperFunctionTest.php b/test/_files/HelperFunctionTest.php deleted file mode 100644 index e69de29..0000000 diff --git a/test/states-test.phpt b/test/states-test.phpt index acf678e..532720b 100644 --- a/test/states-test.phpt +++ b/test/states-test.phpt @@ -21,4 +21,4 @@ PHPUnit\TextUI\Command::main(); ::error file=test/_files/PrinterStatesTest.php,line=12::Failed asserting that false is true. ::error file=test/_files/PrinterStatesTest.php,line=54::Failed asserting that false is true. ::warning file=test/_files/PrinterStatesTest.php,line=37::This is a risky test -::warning file=test/_files/PrinterStatesTest.php,line=40::This test did not perform any assertions%0A%0Atest/_files/PrinterStatesTest.php:40 +::warning file=test/_files/PrinterStatesTest.php,line=40::This test did not perform any assertions From 476a2f10c2fca1cc3214437f21cac9a7caae2ef7 Mon Sep 17 00:00:00 2001 From: Mitchell Macpherson Date: Tue, 10 Nov 2020 10:30:48 +1100 Subject: [PATCH 07/14] Reverted incorrectly modified line ending replacer --- src/Functions/helpers.php | 5 +---- test/states-test.phpt | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Functions/helpers.php b/src/Functions/helpers.php index df7436f..4167bc5 100644 --- a/src/Functions/helpers.php +++ b/src/Functions/helpers.php @@ -76,10 +76,7 @@ static function ($l) { // Some messages might contain paths. Let's convert thost to relative paths too $message = relativePath($message); - $lineFeedPosition = strpos($message, '%0A'); - if (is_int($lineFeedPosition) === true) { - $message = substr($message, 0, $lineFeedPosition); - } + $message = preg_replace('/%0A$/', '', $message); $path = relativePath($path); $file = "file={$path}"; diff --git a/test/states-test.phpt b/test/states-test.phpt index 532720b..acf678e 100644 --- a/test/states-test.phpt +++ b/test/states-test.phpt @@ -21,4 +21,4 @@ PHPUnit\TextUI\Command::main(); ::error file=test/_files/PrinterStatesTest.php,line=12::Failed asserting that false is true. ::error file=test/_files/PrinterStatesTest.php,line=54::Failed asserting that false is true. ::warning file=test/_files/PrinterStatesTest.php,line=37::This is a risky test -::warning file=test/_files/PrinterStatesTest.php,line=40::This test did not perform any assertions +::warning file=test/_files/PrinterStatesTest.php,line=40::This test did not perform any assertions%0A%0Atest/_files/PrinterStatesTest.php:40 From 22037eedfa116b29e409048d8db9f84c5f7a2490 Mon Sep 17 00:00:00 2001 From: Mitchell Macpherson Date: Tue, 17 Nov 2020 00:55:57 +1100 Subject: [PATCH 08/14] Separate phpt tests between phpunti versions --- test/statest-test-phpunit6.phpt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/statest-test-phpunit6.phpt diff --git a/test/statest-test-phpunit6.phpt b/test/statest-test-phpunit6.phpt new file mode 100644 index 0000000..e69de29 From 952dd7ee16833f7c42aa480fd36d9555c182c079 Mon Sep 17 00:00:00 2001 From: Mitchell Macpherson Date: Tue, 17 Nov 2020 01:06:11 +1100 Subject: [PATCH 09/14] Separate state tests between PHPunit versions --- test/states-test.phpt | 2 ++ test/statest-test-phpunit6.phpt | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/test/states-test.phpt b/test/states-test.phpt index acf678e..fa1acbf 100644 --- a/test/states-test.phpt +++ b/test/states-test.phpt @@ -1,5 +1,7 @@ --TEST-- phpunit -c tests/_files/phpunit.xml tests/_files/PrinterStatesTest.php +--SKIPIF-- +=') === false) echo 'skip'; ?> --FILE-- =') === true) echo 'skip'; ?> +--FILE-- + +--EXPECTF-- +%%VERSION%% + +::error file=test/_files/PrinterStatesTest.php,line=17::strpos() expects at least 2 parameters, 0 given +::error file=test/_files/PrinterStatesTest.php,line=22::Error: Call to undefined method PrinterStatesTest::isMissing() +::warning file=test/_files/PrinterStatesTest.php,line=32::This is a test warning +::error file=test/_files/PrinterStatesTest.php,line=12::Failed asserting that false is true. +::error file=test/_files/PrinterStatesTest.php,line=54::Failed asserting that false is true. +::warning file=test/_files/PrinterStatesTest.php,line=37::This is a risky test +::warning file=test/_files/PrinterStatesTest.php,line=40::This test did not perform any assertions From e55ddd60ea2d0282adc2081e206fdccb88de9fed Mon Sep 17 00:00:00 2001 From: Mitchell Macpherson Date: Tue, 17 Nov 2020 01:15:24 +1100 Subject: [PATCH 10/14] Remove Printer6 --- .github/workflows/push.yml | 4 +-- src/Functions/helpers.php | 2 -- src/Printer6.php | 50 -------------------------------- test/Unit/HelperFunctionTest.php | 6 ---- test/states-test.phpt | 2 -- test/statest-test-phpunit6.phpt | 26 ----------------- 6 files changed, 2 insertions(+), 88 deletions(-) delete mode 100644 src/Printer6.php delete mode 100644 test/statest-test-phpunit6.phpt diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index c0adb06..7f113bf 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -9,8 +9,8 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - php-versions: ["7.3", "7.4"] - phpunit-version: ["6", "7", "8", "9"] + php-versions: ["7.3", "7.4", "8"] + phpunit-version: ["7", "8", "9"] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.os }} (PHPUnit ${{ matrix.phpunit-version }}) steps: - name: Checkout diff --git a/src/Functions/helpers.php b/src/Functions/helpers.php index 4167bc5..cc8f5e5 100644 --- a/src/Functions/helpers.php +++ b/src/Functions/helpers.php @@ -2,7 +2,6 @@ namespace mheap\GithubActionsReporter\Functions; -use mheap\GithubActionsReporter\Printer6; use mheap\GithubActionsReporter\Printer7; use mheap\GithubActionsReporter\Printer8; use mheap\GithubActionsReporter\Printer9; @@ -20,7 +19,6 @@ function determinePrinter($version) { $versionMatrix = [ // greater than equals, lower than equals, printer FQCN - ['6.0', '6.99.99', Printer6::class], ['7.0', '7.99.99', Printer7::class], ['8.0', '8.99.99', Printer8::class], ['9.0', true, Printer9::class], diff --git a/src/Printer6.php b/src/Printer6.php deleted file mode 100644 index e442f2d..0000000 --- a/src/Printer6.php +++ /dev/null @@ -1,50 +0,0 @@ -currentType = (in_array($type, ['error', 'failure']) === true) ? 'error' : 'warning'; - - foreach ($defects as $i => $defect) { - $this->printDefect($defect, $i); - } - } - - protected function printDefectHeader(TestFailure $defect, $count): void - { - } - - /** - * @throws \ReflectionException - */ - protected function printDefectTrace(TestFailure $defect): void - { - $this->write(printDefectTrace($defect, $this->currentType)); - } -} diff --git a/test/Unit/HelperFunctionTest.php b/test/Unit/HelperFunctionTest.php index ebb9bfb..ddb420e 100644 --- a/test/Unit/HelperFunctionTest.php +++ b/test/Unit/HelperFunctionTest.php @@ -1,6 +1,5 @@ Printer7::class ]; - yield 'minor version 6.5' => [ - 'version' => '6.5', - 'expected' => Printer6::class - ]; - yield 'minor version 5' => [ 'version' => '5.0', 'expected' => null diff --git a/test/states-test.phpt b/test/states-test.phpt index fa1acbf..acf678e 100644 --- a/test/states-test.phpt +++ b/test/states-test.phpt @@ -1,7 +1,5 @@ --TEST-- phpunit -c tests/_files/phpunit.xml tests/_files/PrinterStatesTest.php ---SKIPIF-- -=') === false) echo 'skip'; ?> --FILE-- =') === true) echo 'skip'; ?> ---FILE-- - ---EXPECTF-- -%%VERSION%% - -::error file=test/_files/PrinterStatesTest.php,line=17::strpos() expects at least 2 parameters, 0 given -::error file=test/_files/PrinterStatesTest.php,line=22::Error: Call to undefined method PrinterStatesTest::isMissing() -::warning file=test/_files/PrinterStatesTest.php,line=32::This is a test warning -::error file=test/_files/PrinterStatesTest.php,line=12::Failed asserting that false is true. -::error file=test/_files/PrinterStatesTest.php,line=54::Failed asserting that false is true. -::warning file=test/_files/PrinterStatesTest.php,line=37::This is a risky test -::warning file=test/_files/PrinterStatesTest.php,line=40::This test did not perform any assertions From 145750145aed56cd6700074d9d6d0ee98e155df2 Mon Sep 17 00:00:00 2001 From: Mitchell Macpherson Date: Tue, 17 Nov 2020 01:17:53 +1100 Subject: [PATCH 11/14] Remove PHP8 test --- .github/workflows/push.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 7f113bf..9e24aef 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - php-versions: ["7.3", "7.4", "8"] + php-versions: ["7.3", "7.4"] phpunit-version: ["7", "8", "9"] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.os }} (PHPUnit ${{ matrix.phpunit-version }}) steps: From def0c6bb75069b6b7735f6b43c713e738f6aa339 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Fri, 20 Nov 2020 19:46:49 +0000 Subject: [PATCH 12/14] Revert "Remove Printer6" This reverts commit e55ddd60ea2d0282adc2081e206fdccb88de9fed. --- .github/workflows/push.yml | 2 +- src/Functions/helpers.php | 2 ++ src/Printer6.php | 50 ++++++++++++++++++++++++++++++++ test/Unit/HelperFunctionTest.php | 6 ++++ test/states-test.phpt | 2 ++ test/statest-test-phpunit6.phpt | 26 +++++++++++++++++ 6 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 src/Printer6.php create mode 100644 test/statest-test-phpunit6.phpt diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 9e24aef..c0adb06 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -10,7 +10,7 @@ jobs: matrix: os: [ubuntu-latest, windows-latest, macos-latest] php-versions: ["7.3", "7.4"] - phpunit-version: ["7", "8", "9"] + phpunit-version: ["6", "7", "8", "9"] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.os }} (PHPUnit ${{ matrix.phpunit-version }}) steps: - name: Checkout diff --git a/src/Functions/helpers.php b/src/Functions/helpers.php index cc8f5e5..4167bc5 100644 --- a/src/Functions/helpers.php +++ b/src/Functions/helpers.php @@ -2,6 +2,7 @@ namespace mheap\GithubActionsReporter\Functions; +use mheap\GithubActionsReporter\Printer6; use mheap\GithubActionsReporter\Printer7; use mheap\GithubActionsReporter\Printer8; use mheap\GithubActionsReporter\Printer9; @@ -19,6 +20,7 @@ function determinePrinter($version) { $versionMatrix = [ // greater than equals, lower than equals, printer FQCN + ['6.0', '6.99.99', Printer6::class], ['7.0', '7.99.99', Printer7::class], ['8.0', '8.99.99', Printer8::class], ['9.0', true, Printer9::class], diff --git a/src/Printer6.php b/src/Printer6.php new file mode 100644 index 0000000..e442f2d --- /dev/null +++ b/src/Printer6.php @@ -0,0 +1,50 @@ +currentType = (in_array($type, ['error', 'failure']) === true) ? 'error' : 'warning'; + + foreach ($defects as $i => $defect) { + $this->printDefect($defect, $i); + } + } + + protected function printDefectHeader(TestFailure $defect, $count): void + { + } + + /** + * @throws \ReflectionException + */ + protected function printDefectTrace(TestFailure $defect): void + { + $this->write(printDefectTrace($defect, $this->currentType)); + } +} diff --git a/test/Unit/HelperFunctionTest.php b/test/Unit/HelperFunctionTest.php index ddb420e..ebb9bfb 100644 --- a/test/Unit/HelperFunctionTest.php +++ b/test/Unit/HelperFunctionTest.php @@ -1,5 +1,6 @@ Printer7::class ]; + yield 'minor version 6.5' => [ + 'version' => '6.5', + 'expected' => Printer6::class + ]; + yield 'minor version 5' => [ 'version' => '5.0', 'expected' => null diff --git a/test/states-test.phpt b/test/states-test.phpt index acf678e..fa1acbf 100644 --- a/test/states-test.phpt +++ b/test/states-test.phpt @@ -1,5 +1,7 @@ --TEST-- phpunit -c tests/_files/phpunit.xml tests/_files/PrinterStatesTest.php +--SKIPIF-- +=') === false) echo 'skip'; ?> --FILE-- =') === true) echo 'skip'; ?> +--FILE-- + +--EXPECTF-- +%%VERSION%% + +::error file=test/_files/PrinterStatesTest.php,line=17::strpos() expects at least 2 parameters, 0 given +::error file=test/_files/PrinterStatesTest.php,line=22::Error: Call to undefined method PrinterStatesTest::isMissing() +::warning file=test/_files/PrinterStatesTest.php,line=32::This is a test warning +::error file=test/_files/PrinterStatesTest.php,line=12::Failed asserting that false is true. +::error file=test/_files/PrinterStatesTest.php,line=54::Failed asserting that false is true. +::warning file=test/_files/PrinterStatesTest.php,line=37::This is a risky test +::warning file=test/_files/PrinterStatesTest.php,line=40::This test did not perform any assertions From b489c6a3b86c06868efe228d120451a079fd53a0 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Fri, 20 Nov 2020 20:18:49 +0000 Subject: [PATCH 13/14] Make --SKIPIF-- work in .phpt tests --- test/states-test.phpt | 5 ++++- test/statest-test-phpunit6.phpt | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/test/states-test.phpt b/test/states-test.phpt index fa1acbf..329b543 100644 --- a/test/states-test.phpt +++ b/test/states-test.phpt @@ -1,7 +1,10 @@ --TEST-- phpunit -c tests/_files/phpunit.xml tests/_files/PrinterStatesTest.php --SKIPIF-- -=') === false) echo 'skip'; ?> +=') === false) echo 'skip'; +?> --FILE-- =') === true) echo 'skip'; ?> +=') === true) echo 'skip'; +?> --FILE-- Date: Fri, 20 Nov 2020 20:20:42 +0000 Subject: [PATCH 14/14] Rename states-test-phpunit6.php --- test/{statest-test-phpunit6.phpt => states-test-phpunit6.phpt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{statest-test-phpunit6.phpt => states-test-phpunit6.phpt} (100%) diff --git a/test/statest-test-phpunit6.phpt b/test/states-test-phpunit6.phpt similarity index 100% rename from test/statest-test-phpunit6.phpt rename to test/states-test-phpunit6.phpt