diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fcadb2c --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf 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/phpcs.xml b/phpcs.xml index 92dd337..a84529f 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,6 +1,6 @@ PSR12 - ./src + src diff --git a/src/Printer.php b/src/Printer.php index 422e588..ff4e06a 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( @@ -54,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)}"; @@ -73,7 +76,10 @@ protected function getCurrentType() protected function relativePath(string $path) { - return str_replace(getcwd() . '/', '', $path); + $relative = str_replace(getcwd() . DIRECTORY_SEPARATOR, '', $path); + // Translate \ in to / for Windows + $relative = str_replace('\\', '/', $relative); + return $relative; } protected function getReflectionFromTest(string $name)