From f4d05d6cf3429e75b236a8b585c88c6afb153460 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Fri, 24 Jan 2020 08:46:46 -0500 Subject: [PATCH 1/7] Set up GitHub Actions --- .github/workflows/push.yml | 30 ++++++++++++++++++++++++++++++ src/Printer.php | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/push.yml diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 0000000..51f4498 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,30 @@ +name: CI +on: push +jobs: + run: + runs-on: ${{ matrix.operating-system }} + strategy: + fail-fast: false + matrix: + operating-system: [ubuntu-latest, windows-latest, macos-latest] + php-versions: ['7.3', '7.4'] + name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v1 + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring + coverage: xdebug + + - name: Composer dependencies + run: composer install --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist + + - name: Run phpunit + run: ./vendor/bin/phpunit + + - name: Run phpcs + run: ./vendor/bin/phpcs diff --git a/src/Printer.php b/src/Printer.php index 422e588..b884718 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -73,7 +73,7 @@ protected function getCurrentType() protected function relativePath(string $path) { - return str_replace(getcwd() . '/', '', $path); + return str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $path); } protected function getReflectionFromTest(string $name) From 661c7066991ce3354f4923c6144b799ab2a3ade6 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Sat, 1 Feb 2020 21:25:19 +0000 Subject: [PATCH 2/7] Make printer work on Windows --- src/Printer.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Printer.php b/src/Printer.php index b884718..014cf26 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -40,13 +40,16 @@ protected function printDefectTrace(TestFailure $defect): void $e = $defect->thrownException(); $errorLines = array_filter( - explode(PHP_EOL, (string)$e), + explode("\n", (string)$e), function ($l) { return $l; } ); - list($path, $line) = explode(":", end($errorLines)); + $error = end($errorLines); + $lineIndex = strrpos($error, ":"); + $path = substr($error, 0, $lineIndex); + $line = substr($error, $lineIndex+1); if (!$path) { list($path, $line) = $this->getReflectionFromTest( From ba0161e5e4cf075c9225b4e985c3259831fcd228 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Sun, 2 Feb 2020 09:32:22 +0000 Subject: [PATCH 3/7] Fix Windows paths --- src/Printer.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Printer.php b/src/Printer.php index 014cf26..6f9b716 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -49,7 +49,7 @@ function ($l) { $error = end($errorLines); $lineIndex = strrpos($error, ":"); $path = substr($error, 0, $lineIndex); - $line = substr($error, $lineIndex+1); + $line = substr($error, $lineIndex + 1); if (!$path) { list($path, $line) = $this->getReflectionFromTest( @@ -76,7 +76,10 @@ protected function getCurrentType() protected function relativePath(string $path) { - return str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $path); + $relative = str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $path); + // Translate \ in to / for Windows + $relative = str_replace('\\', '/', $relative); + return $relative; } protected function getReflectionFromTest(string $name) From 6534c5b8ce7a6efa36b184e053c8d47bcceb6299 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Sun, 2 Feb 2020 09:39:35 +0000 Subject: [PATCH 4/7] Fixed message population on Windows --- src/Printer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Printer.php b/src/Printer.php index 6f9b716..8efe1f3 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -44,7 +44,7 @@ protected function printDefectTrace(TestFailure $defect): void function ($l) { return $l; } - ); + ); $error = end($errorLines); $lineIndex = strrpos($error, ":"); @@ -57,7 +57,7 @@ function ($l) { ); } - $message = explode(PHP_EOL, $e->getMessage())[0]; + $message = explode("\n", $e->getMessage())[0]; $type = $this->getCurrentType(); $file = "file={$this->relativePath($path)}"; From 47a83417621c5cfa7831c282bf49423f21ddc0fb Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Sun, 2 Feb 2020 09:41:36 +0000 Subject: [PATCH 5/7] Fix CS --- src/Printer.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Printer.php b/src/Printer.php index 8efe1f3..ff4e06a 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -44,7 +44,7 @@ protected function printDefectTrace(TestFailure $defect): void function ($l) { return $l; } - ); + ); $error = end($errorLines); $lineIndex = strrpos($error, ":"); @@ -57,7 +57,7 @@ function ($l) { ); } - $message = explode("\n", $e->getMessage())[0]; + $message = explode("\n", $e->getMessage())[0]; $type = $this->getCurrentType(); $file = "file={$this->relativePath($path)}"; From c52420bc5dfcd67a6de379a00b0c46f1841843e4 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Sun, 2 Feb 2020 09:45:51 +0000 Subject: [PATCH 6/7] Update phpcs.xml --- phpcs.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpcs.xml b/phpcs.xml index 92dd337..a84529f 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,6 +1,6 @@ PSR12 - ./src + src From f3b184e38d0f64bb363a603d7097bb6568a36e33 Mon Sep 17 00:00:00 2001 From: Michael Heap Date: Sun, 2 Feb 2020 13:55:27 +0000 Subject: [PATCH 7/7] Create .gitattributes --- .gitattributes | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fcadb2c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf