From ea5b2e18caca6c341fb8ceff2ce8e4fddb77d0df Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 10 Feb 2022 14:51:53 +0100 Subject: [PATCH] Support Laravel 9 (#419) * Fix tests for Laravel 9 (#421) * Set base path to Laravel application correctly Co-authored-by: Michel Bardelmeijer --- .github/workflows/ci.yml | 66 +++++---------------- composer.json | 9 +-- phpunit.xml | 3 +- src/Command/Lint.php | 2 +- tests/Command/Lint/FinderTest.php | 11 ++-- tests/Command/Lint/FormatTest.php | 7 ++- tests/ServiceProvider/Bindings/TwigTest.php | 2 +- tests/TwigBridgeTestTrait.php | 3 +- 8 files changed, 33 insertions(+), 70 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 619cb81d..8bcf2cc1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,26 +12,16 @@ jobs: fail-fast: true matrix: php: [ '7.2', '7.3', '7.4', '8.0', '8.1' ] - laravel: [ '5.5', '5.6', '5.7', '5.8', '6', '7', '8' ] + laravel: ['6', '7', '8', '9' ] exclude: - php: '7.2' laravel: '8' - - php: '8.0' - laravel: '5.5' - - php: '8.0' - laravel: '5.6' - - php: '8.0' - laravel: '5.7' - - php: '8.0' - laravel: '5.8' - - php: '8.1' - laravel: '5.5' - - php: '8.1' - laravel: '5.6' - - php: '8.1' - laravel: '5.7' - - php: '8.1' - laravel: '5.8' + - php: '7.2' + laravel: '9' + - php: '7.3' + laravel: '9' + - php: '7.4' + laravel: '9' - php: '8.1' laravel: '6' - php: '8.1' @@ -53,38 +43,6 @@ jobs: - name: Setup Problem Matchers run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Select Laravel 5.5 - uses: nick-invision/retry@v1 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require "laravel/framework:5.5.*" "phpunit/phpunit:^6.5.14" --no-update --no-interaction - if: "matrix.laravel == '5.5'" - - - name: Select Laravel 5.6 - uses: nick-invision/retry@v1 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require "laravel/framework:5.6.*" "phpunit/phpunit:^7.5.20" --no-update --no-interaction - if: "matrix.laravel == '5.6'" - - - name: Select Laravel 5.7 - uses: nick-invision/retry@v1 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require "laravel/framework:5.7.*" "phpunit/phpunit:^7.5.20" --no-update --no-interaction - if: "matrix.laravel == '5.7'" - - - name: Select Laravel 5.8 - uses: nick-invision/retry@v1 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require "laravel/framework:5.8.*" "phpunit/phpunit:^7.5.20|^8.5.8" --no-update --no-interaction - if: "matrix.laravel == '5.8'" - - name: Select Laravel 6 uses: nick-invision/retry@v1 with: @@ -108,6 +66,14 @@ jobs: max_attempts: 5 command: composer require "laravel/framework:8.*" "phpunit/phpunit:^9.3.7" --no-update --no-interaction if: "matrix.laravel == '8'" + + - name: Select Laravel 9 + uses: nick-invision/retry@v1 + with: + timeout_minutes: 5 + max_attempts: 5 + command: composer require "laravel/framework:9.*" "phpunit/phpunit:^9.3.7" --no-update --no-interaction + if: "matrix.laravel == '9'" - name: Install PHP Dependencies uses: nick-invision/retry@v1 @@ -124,4 +90,4 @@ jobs: - name: Check code coverage if: ${{ matrix.php == '8.1' }} - uses: codecov/codecov-action@v2.1.0 \ No newline at end of file + uses: codecov/codecov-action@v2.1.0 diff --git a/composer.json b/composer.json index 7644c3fb..8e2e25a6 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,12 @@ "require": { "php": "^7.2.5 || ^8.0", "twig/twig": "~3.0", - "illuminate/support": "^5.5 || ^6.0 || ^7.0 || ^8.0", - "illuminate/view": "^5.5 || ^6.0 || ^7.0 || ^8.0" + "illuminate/support": "^6|^7|^8|^9", + "illuminate/view": "^6|^7|^8|^9" }, "require-dev": { "ext-json": "*", - "laravel/framework": "^5.5 || ^6.0 || ^7.0 || ^8.0", + "laravel/framework": "^6|^7|^8|^9", "mockery/mockery": "^1.3.1", "phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.7", "squizlabs/php_codesniffer": "^3.6" @@ -49,5 +49,6 @@ } } }, - "minimum-stability": "dev" + "minimum-stability": "dev", + "prefer-stable": true } diff --git a/phpunit.xml b/phpunit.xml index e7aa5898..0dc1b280 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,7 +8,6 @@ convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" - syntaxCheck="false" > @@ -41,4 +40,4 @@ - \ No newline at end of file + diff --git a/src/Command/Lint.php b/src/Command/Lint.php index 8f19f9df..b04d2c63 100644 --- a/src/Command/Lint.php +++ b/src/Command/Lint.php @@ -154,7 +154,7 @@ protected function getFiles($filename, array $files, array $directories) } // If no files passed, use the view paths - if (empty($search)) { + if (empty($search) && !empty($paths)) { foreach ($this->getFinder($paths) as $file) { $search[] = $file->getRealPath(); } diff --git a/tests/Command/Lint/FinderTest.php b/tests/Command/Lint/FinderTest.php index 8292f413..885be604 100644 --- a/tests/Command/Lint/FinderTest.php +++ b/tests/Command/Lint/FinderTest.php @@ -3,8 +3,6 @@ namespace TwigBridge\Tests\Command\Lint; use Mockery as m; -use Symfony\Component\Console\Input\ArrayInput; -use Symfony\Component\Console\Output\StreamOutput; use TwigBridge\Command\Lint; class FinderTest extends Base @@ -19,19 +17,18 @@ public function testGet() public function testSet() { - $data = ['fooBar']; - + /** @var \Symfony\Component\Finder\Finder|\Mockery\MockInterface $finder */ $finder = m::mock('Symfony\Component\Finder\Finder'); $finder->shouldReceive('files')->andReturn($finder); $finder->shouldReceive('in')->andReturn($finder); - $finder->shouldReceive('name')->andReturn($data); + $finder->shouldReceive('name')->andReturn($finder); + $finder->shouldReceive('count')->andReturn(1); $app = $this->getApplication(); $command = new Lint; $command->setLaravel($app); $command->setFinder($finder); - $command->setFinder($finder); - $this->assertEquals($data, $command->getFinder([__DIR__])); + $this->assertEquals(1, $command->getFinder([__DIR__])->count()); } } diff --git a/tests/Command/Lint/FormatTest.php b/tests/Command/Lint/FormatTest.php index a2a57e76..37768cd9 100644 --- a/tests/Command/Lint/FormatTest.php +++ b/tests/Command/Lint/FormatTest.php @@ -59,7 +59,7 @@ public function testEmptyJSON() } /** - * @expectedException InvalidArgumentException + * @expectedException \InvalidArgumentException */ public function testInvalidFormat() { @@ -70,13 +70,14 @@ public function testInvalidFormat() $command->setLaravel($app); - $finder = m::mock('Symfony\Component\Finder\Finder'); + /** @var \Symfony\Component\Finder\Finder|\Mockery\MockInterface $finder */ + $finder = m::mock('Symfony\Component\Finder\Finder')->makePartial(); $finder->shouldReceive('files')->andReturn($finder); $finder->shouldReceive('in')->andReturn($finder); $finder->shouldReceive('name')->andReturn($finder); $command->setFinder($finder); - $input = new ArrayInput([ + $input = new ArrayInput([ '--format' => 'foo' ]); $output = m::mock('Symfony\Component\Console\Output\NullOutput')->makePartial(); diff --git a/tests/ServiceProvider/Bindings/TwigTest.php b/tests/ServiceProvider/Bindings/TwigTest.php index ce141c98..cb0a731b 100644 --- a/tests/ServiceProvider/Bindings/TwigTest.php +++ b/tests/ServiceProvider/Bindings/TwigTest.php @@ -29,7 +29,7 @@ public function testTwigOptions() // Make sure that twig.options sets the storage path automatically $this->assertEmpty($config['cache']); - $this->assertEquals(realpath($options['cache']), realpath(__DIR__.'/../..').'/storage/framework/views/twig'); + $this->assertEquals(realpath(__DIR__.'/../..') . '/storage/framework/views/twig', $options['cache']); // Make sure same config is returned $options['cache'] = null; diff --git a/tests/TwigBridgeTestTrait.php b/tests/TwigBridgeTestTrait.php index e9bb9dd8..d2d68340 100644 --- a/tests/TwigBridgeTestTrait.php +++ b/tests/TwigBridgeTestTrait.php @@ -32,8 +32,7 @@ public function tearDown(): void */ protected function getApplication(array $customConfig = []) { - $app = new Application; - $app->instance('path', __DIR__); + $app = new Application(__DIR__); $app['env'] = 'production'; $app['path.config'] = __DIR__ . '/config';