diff --git a/.github/workflows/ci-tests.yaml b/.github/workflows/ci-tests.yaml new file mode 100644 index 0000000..090fca4 --- /dev/null +++ b/.github/workflows/ci-tests.yaml @@ -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 diff --git a/.travis.yml b/.travis.yml index 85607ab..61a4671 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/composer.json b/composer.json index 4393f47..078f67b 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/src/Validator/Validator.php b/src/Validator/Validator.php index eb682d3..a04d3a0 100644 --- a/src/Validator/Validator.php +++ b/src/Validator/Validator.php @@ -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; diff --git a/tests/Console/LintCommandTest.php b/tests/Console/LintCommandTest.php index 8e6a20f..7e35d7c 100644 --- a/tests/Console/LintCommandTest.php +++ b/tests/Console/LintCommandTest.php @@ -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(); @@ -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() @@ -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() @@ -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() @@ -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() @@ -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', @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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". @@ -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". @@ -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": [ { diff --git a/tests/CorpusTest.php b/tests/CorpusTest.php index d0e4edc..cee6e60 100644 --- a/tests/CorpusTest.php +++ b/tests/CorpusTest.php @@ -11,7 +11,7 @@ class CorpusTest extends TestCase { private $commandTester; - public function setUp() + public function setUp(): void { $container = new Container(); $command = new LintCommand(); @@ -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); } } diff --git a/tests/Reporter/ConsoleReporterTest.php b/tests/Reporter/ConsoleReporterTest.php index d198b8b..b509901 100644 --- a/tests/Reporter/ConsoleReporterTest.php +++ b/tests/Reporter/ConsoleReporterTest.php @@ -18,15 +18,13 @@ public function testReport() ; $output - ->expects($this->at(1)) + ->expects($this->exactly(3)) ->method('writeln') - ->with('l.10 c.20 : ERROR You are not allowed to do that.') - ; - - $output - ->expects($this->at(2)) - ->method('writeln') - ->with('1 violation(s) found') + ->withConsecutive( + ['template.twig'], + ['l.10 c.20 : ERROR You are not allowed to do that.'], + ['1 violation(s) found'] + ) ; $reporter->report($output, [ diff --git a/tests/Rule/ForbiddenFunctionsTest.php b/tests/Rule/ForbiddenFunctionsTest.php index ad03f0d..fe9a66e 100644 --- a/tests/Rule/ForbiddenFunctionsTest.php +++ b/tests/Rule/ForbiddenFunctionsTest.php @@ -12,7 +12,7 @@ class ForbiddenFunctionsTest extends TestCase { private $tokens; - public function setUp() + public function setUp(): void { $lexer = new Lexer(); $source = new Source(