Skip to content

Commit

Permalink
Set up GitHub Actions (#8)
Browse files Browse the repository at this point in the history
* Set up GitHub Actions
* Make printer work on Windows
* Fix Windows paths
* Fixed message population on Windows
* Fix CS
* Update phpcs.xml
* Create .gitattributes
  • Loading branch information
mheap committed Feb 15, 2020
1 parent 5f4a36c commit 2cd2aad
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
30 changes: 30 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset name="PSR12">
<description>PSR12</description>
<file>./src</file>
<file>src</file>
<rule ref="PSR12"/>
</ruleset>
14 changes: 10 additions & 4 deletions src/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,24 @@ 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(
$defect->getTestName()
);
}

$message = explode(PHP_EOL, $e->getMessage())[0];
$message = explode("\n", $e->getMessage())[0];

$type = $this->getCurrentType();
$file = "file={$this->relativePath($path)}";
Expand All @@ -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)
Expand Down

0 comments on commit 2cd2aad

Please sign in to comment.