Skip to content

Commit

Permalink
Merge pull request #152 from Ciloe/add-support-php8
Browse files Browse the repository at this point in the history
Issue #151 : Add support for PHP 8
  • Loading branch information
OwlyCode authored Feb 4, 2021
2 parents fd99f02 + c31772b commit 0d2b11e
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 40 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/ci-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: CI Tests
on:
release:
types: [opened, reopened]
push:
pull_request:
types: [opened, reopened]

jobs:
run:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ ubuntu-latest, macos-latest ]
php-versions: [ '7.3', '7.4', '8.0' ]
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: phpunit

- name: Install dependencies
run: composer --prefer-source -n install

- name: Launch test
run: bin/phpunit
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
language: php
php:
- 7.0
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
install:
- composer --prefer-source -n install
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
}
],
"require": {
"php": "^7.0",
"php": "^7.2 || ^8.0",
"symfony/console": "^3.4 || ^4.3 || ^5.0",
"symfony/finder": "^3.4 || ^4.3 || ^5.0",
"symfony/filesystem": "^3.4 || ^4.3 || ^5.0"
},
"require-dev": {
"phpunit/phpunit": "^6.5 || ^7.2"
"phpunit/phpunit": "^8.0 || ^9.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/Validator/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function validate(RulesetInterface $ruleset, TokenStream $tokens)
}

usort($violations, function (Violation $a, Violation $b) {
return $a->getLine() > $b->getLine();
return $a->getLine() - $b->getLine();
});

return $violations;
Expand Down
46 changes: 23 additions & 23 deletions tests/Console/LintCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class LintCommandTest extends TestCase
/** @var CommandTester */
private $commandTester;

public function setUp()
public function setUp(): void
{
$container = new Container();
$command = new LintCommand();
Expand All @@ -31,7 +31,7 @@ public function testExecute()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 0);
$this->assertContains('No violation found.', $output);
$this->assertStringContainsString('No violation found.', $output);
}

public function testMultipleBasePaths()
Expand All @@ -44,7 +44,7 @@ public function testMultipleBasePaths()
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 1);
$this->assertStringStartsWith('tests/data/basepaths/a/bad.html.twig', $output);
$this->assertContains("\ntests/data/basepaths/b/bad.html.twig", $output);
$this->assertStringContainsString("\ntests/data/basepaths/b/bad.html.twig", $output);
}

public function testExecuteWithError()
Expand All @@ -56,7 +56,7 @@ public function testExecuteWithError()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 1);
$this->assertContains('ERROR', $output);
$this->assertStringContainsString('ERROR', $output);
}

public function testExecuteWithIgnoredErrors()
Expand All @@ -69,7 +69,7 @@ public function testExecuteWithIgnoredErrors()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 0);
$this->assertContains('ERROR', $output);
$this->assertStringContainsString('ERROR', $output);
}

public function testExecuteWithIgnoredWarnings()
Expand All @@ -82,7 +82,7 @@ public function testExecuteWithIgnoredWarnings()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 0);
$this->assertContains('WARNING', $output);
$this->assertStringContainsString('WARNING', $output);

$this->commandTester->execute([
'--severity' => 'error',
Expand All @@ -92,7 +92,7 @@ public function testExecuteWithIgnoredWarnings()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 1);
$this->assertContains('WARNING', $output);
$this->assertStringContainsString('WARNING', $output);
}

public function testExecuteWithExclude()
Expand All @@ -105,7 +105,7 @@ public function testExecuteWithExclude()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 0);
$this->assertContains('No violation found.', $output);
$this->assertStringContainsString('No violation found.', $output);
}

public function testErrorsOnlyDisplayBlocking()
Expand All @@ -119,10 +119,10 @@ public function testErrorsOnlyDisplayBlocking()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 1);
$this->assertNotContains('l.1 c.7 : WARNING Unused variable "foo".', $output);
$this->assertContains('l.2 c.2 : ERROR A print statement should start with 1 space.', $output);
$this->assertContains('l.2 c.13 : ERROR There should be 0 space between the closing parenthese and its content.', $output);
$this->assertContains('2 violation(s) found', $output);
$this->assertStringNotContainsString('l.1 c.7 : WARNING Unused variable "foo".', $output);
$this->assertStringContainsString('l.2 c.2 : ERROR A print statement should start with 1 space.', $output);
$this->assertStringContainsString('l.2 c.13 : ERROR There should be 0 space between the closing parenthese and its content.', $output);
$this->assertStringContainsString('2 violation(s) found', $output);
}

public function testErrorsDisplayAll()
Expand All @@ -136,10 +136,10 @@ public function testErrorsDisplayAll()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 1);
$this->assertContains('l.1 c.7 : WARNING Unused variable "foo".', $output);
$this->assertContains('l.2 c.2 : ERROR A print statement should start with 1 space.', $output);
$this->assertContains('l.2 c.13 : ERROR There should be 0 space between the closing parenthese and its content.', $output);
$this->assertContains('3 violation(s) found', $output);
$this->assertStringContainsString('l.1 c.7 : WARNING Unused variable "foo".', $output);
$this->assertStringContainsString('l.2 c.2 : ERROR A print statement should start with 1 space.', $output);
$this->assertStringContainsString('l.2 c.13 : ERROR There should be 0 space between the closing parenthese and its content.', $output);
$this->assertStringContainsString('3 violation(s) found', $output);
}

public function testSyntaxErrorThrow()
Expand Down Expand Up @@ -168,8 +168,8 @@ public function testSyntaxErrorNotThrow()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 1);
$this->assertContains('1 violation(s) found', $output);
$this->assertContains('l.1 c.17 : ERROR Unexpected "}"', $output);
$this->assertStringContainsString('1 violation(s) found', $output);
$this->assertStringContainsString('l.1 c.17 : ERROR Unexpected "}"', $output);
}

public function testSyntaxErrorNotThrowOmitArgument()
Expand All @@ -183,8 +183,8 @@ public function testSyntaxErrorNotThrowOmitArgument()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 1);
$this->assertContains('1 violation(s) found', $output);
$this->assertContains('l.1 c.17 : ERROR Unexpected "}"', $output);
$this->assertStringContainsString('1 violation(s) found', $output);
$this->assertStringContainsString('l.1 c.17 : ERROR Unexpected "}"', $output);
}

public function testConfigFileWithoutCliPath()
Expand All @@ -197,7 +197,7 @@ public function testConfigFileWithoutCliPath()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 1);
$this->assertContains('tests/data/basepaths/a/bad.html.twig
$this->assertStringContainsString('tests/data/basepaths/a/bad.html.twig
l.1 c.8 : WARNING Unused variable "foo".
tests/data/basepaths/b/bad.html.twig
l.1 c.8 : WARNING Unused variable "foo".
Expand All @@ -214,7 +214,7 @@ public function testConfigFileWithCliPath()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 1);
$this->assertContains('tests/data/basepaths/a/bad.html.twig
$this->assertStringContainsString('tests/data/basepaths/a/bad.html.twig
l.1 c.8 : WARNING Unused variable "foo".
tests/data/basepaths/b/bad.html.twig
l.1 c.8 : WARNING Unused variable "foo".
Expand All @@ -234,7 +234,7 @@ public function testConfigFileSamePathWithRulesetOverrides()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 1);
$this->assertContains('{
$this->assertStringContainsString('{
"failures": 1,
"files": [
{
Expand Down
4 changes: 2 additions & 2 deletions tests/CorpusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CorpusTest extends TestCase
{
private $commandTester;

public function setUp()
public function setUp(): void
{
$container = new Container();
$command = new LintCommand();
Expand All @@ -29,6 +29,6 @@ public function testExecute()
$output = $this->commandTester->getDisplay();
$statusCode = $this->commandTester->getStatusCode();
$this->assertSame($statusCode, 0);
$this->assertContains('No violation found.', $output);
$this->assertStringContainsString('No violation found.', $output);
}
}
14 changes: 6 additions & 8 deletions tests/Reporter/ConsoleReporterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ public function testReport()
;

$output
->expects($this->at(1))
->expects($this->exactly(3))
->method('writeln')
->with('<comment>l.10 c.20</comment> : ERROR You are not allowed to do that.')
;

$output
->expects($this->at(2))
->method('writeln')
->with('<error>1 violation(s) found</error>')
->withConsecutive(
['<comment>template.twig</comment>'],
['<comment>l.10 c.20</comment> : ERROR You are not allowed to do that.'],
['<error>1 violation(s) found</error>']
)
;

$reporter->report($output, [
Expand Down
2 changes: 1 addition & 1 deletion tests/Rule/ForbiddenFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ForbiddenFunctionsTest extends TestCase
{
private $tokens;

public function setUp()
public function setUp(): void
{
$lexer = new Lexer();
$source = new Source(
Expand Down

0 comments on commit 0d2b11e

Please sign in to comment.