From 21ed43531912412747279ba9c378148704344e87 Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Thu, 20 Aug 2020 21:29:52 +0200 Subject: [PATCH 01/17] Add CI improvements --- .editorconfig | 15 +++++++++++++++ .gitattributes | 12 ++++++++++++ .styleci.yml | 1 + .travis.yml | 31 +++++++++++++++++++++++++++++++ 4 files changed, 59 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .styleci.yml create mode 100644 .travis.yml diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..b26a9a99 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +; This file is for unifying the coding style for different editors and IDEs. +; More information at https://editorconfig.org + +root = true + +[*] +charset = utf-8 +indent_size = 4 +indent_style = space +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..e83b471c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,12 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.editorconfig export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.styleci.yml export-ignore +/.scrutinizer.yml export-ignore +/.travis.yml export-ignore +/phpunit.xml.dist export-ignore +/tests export-ignore diff --git a/.styleci.yml b/.styleci.yml new file mode 100644 index 00000000..0285f179 --- /dev/null +++ b/.styleci.yml @@ -0,0 +1 @@ +preset: laravel diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..16d1ae91 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,31 @@ +sudo: required + +language: php + +php: + - 5.4 + - 5.5 + - 5.6 + - 7.0 + - 7.1 + - 7.2 + - 7.3 + - 7.4 + +env: + matrix: + - COMPOSER_FLAGS="--prefer-lowest" + - COMPOSER_FLAGS="" + +before_install: + - travis_retry composer self-update + +install: + - travis_retry composer update --prefer-source $COMPOSER_FLAGS + +script: + - phpunit + +branches: + only: + - master From b0302c1543deae915f91036605ee3eb05c317d55 Mon Sep 17 00:00:00 2001 From: Claudio Dekker <1752195+claudiodekker@users.noreply.github.com> Date: Fri, 21 Aug 2020 09:35:53 +0200 Subject: [PATCH 02/17] Update .gitattributes --- .gitattributes | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitattributes b/.gitattributes index e83b471c..0d3c50ea 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,7 +6,6 @@ /.gitattributes export-ignore /.gitignore export-ignore /.styleci.yml export-ignore -/.scrutinizer.yml export-ignore /.travis.yml export-ignore -/phpunit.xml.dist export-ignore +/phpunit.xml export-ignore /tests export-ignore From d0ebaa6d9055436a2c984b7fed35d60662e4743c Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 13:09:40 +0200 Subject: [PATCH 03/17] Disable branch limiter for now --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 16d1ae91..7ae38811 100644 --- a/.travis.yml +++ b/.travis.yml @@ -26,6 +26,6 @@ install: script: - phpunit -branches: - only: - - master +#branches: +# only: +# - master From 1ec5f013162fbe4bc3512087d29a753866a8d6d0 Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 13:12:56 +0200 Subject: [PATCH 04/17] Remove PHP <= 5.5, add PHP 8.0 PHP 5.4 & 5.5 have reached EOL and are no longer supported by Travis --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7ae38811..fc507179 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,14 +3,13 @@ sudo: required language: php php: - - 5.4 - - 5.5 - 5.6 - 7.0 - 7.1 - 7.2 - 7.3 - 7.4 + - 8.0 env: matrix: From 14ca6d62454fbfdb6c3cfd30012f4ea7e9c5b9d9 Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 13:44:15 +0200 Subject: [PATCH 05/17] Update testbench dependency for Laravel 6, 7, 8 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 745c729b..78758e6e 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "laravel/framework": "^5.4|^6.0|^7.0|^8.0" }, "require-dev": { - "orchestra/testbench": "~3.0" + "orchestra/testbench": "~3.0|^4.0|^5.0|^6.0" }, "extra": { "laravel": { From 34c3f8b43ad65f1800eaa610c9eaebc2fabfcd4e Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 13:53:31 +0200 Subject: [PATCH 06/17] Drop Laravel <= 6.0 (TestBench issues) --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 78758e6e..ee2d15e1 100644 --- a/composer.json +++ b/composer.json @@ -25,10 +25,10 @@ } }, "require": { - "laravel/framework": "^5.4|^6.0|^7.0|^8.0" + "laravel/framework": "^6.0|^7.0|^8.0" }, "require-dev": { - "orchestra/testbench": "~3.0|^4.0|^5.0|^6.0" + "orchestra/testbench": "^4.0|^5.0|^6.0" }, "extra": { "laravel": { From 3b5e25f853188cc73dc90373590d7715368476c8 Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 14:00:18 +0200 Subject: [PATCH 07/17] Remove TravisCI testing for PHP <= 7.1 Laravel 6+ has a minimum version of PHP 7.2 --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index fc507179..71294a30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,6 @@ sudo: required language: php php: - - 5.6 - - 7.0 - - 7.1 - 7.2 - 7.3 - 7.4 From b1c92f2f33dcdbe7259f5a729b65b28c03586f22 Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 14:03:46 +0200 Subject: [PATCH 08/17] Remove TravisCI config warnings --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 71294a30..4a5a1bb3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ -sudo: required - +os: linux +dist: xenial language: php php: @@ -9,7 +9,7 @@ php: - 8.0 env: - matrix: + jobs: - COMPOSER_FLAGS="--prefer-lowest" - COMPOSER_FLAGS="" From 22dcce9f77bd89bb9578485e34b091cc767e2a76 Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 15:50:14 +0200 Subject: [PATCH 09/17] Fix: TestResponse not found on Laravel 6+ --- tests/MiddlewareTest.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/MiddlewareTest.php b/tests/MiddlewareTest.php index 9488399d..ee48bf6e 100644 --- a/tests/MiddlewareTest.php +++ b/tests/MiddlewareTest.php @@ -2,10 +2,11 @@ namespace Inertia\Tests; -use Illuminate\Foundation\Testing\TestResponse; -use Illuminate\Http\Request; use Inertia\Inertia; use Inertia\Middleware; +use Illuminate\Http\Request; +use Illuminate\Testing\TestResponse; +use Illuminate\Foundation\Testing\TestResponse as LegacyTestResponse; class MiddlewareTest extends TestCase { @@ -85,6 +86,11 @@ private function makeMockResponse($request) return Inertia::render('User/Edit', ['user' => ['name' => 'Jonathan']])->toResponse($request); }); + // Laravel <= 6.0 + if (class_exists(LegacyTestResponse::class)) { + return LegacyTestResponse::fromBaseResponse($response); + } + return TestResponse::fromBaseResponse($response); } } From 864a83ad252b704d6efa20ad82b7a79ca5e16554 Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 15:56:28 +0200 Subject: [PATCH 10/17] Fix @covers annotation issue --- phpunit.xml | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index c042b781..f2eebe03 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,20 +1,22 @@ - + - - tests + + tests - - src + + src/ From e4eff766654a405f1cdb178901a5a563e87c283b Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 16:11:27 +0200 Subject: [PATCH 11/17] Fix PHPUnit issues in earlier Laravel releases --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ee2d15e1..2eb0a0a8 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } }, "require": { - "laravel/framework": "^6.0|^7.0|^8.0" + "laravel/framework": "^6.12|^7.0|^8.0" }, "require-dev": { "orchestra/testbench": "^4.0|^5.0|^6.0" From 4bc90d7213c40d1056cd0f0cff6dd91936bfa8bc Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 16:12:49 +0200 Subject: [PATCH 12/17] Remove PHP 8.0 from Travis (not yet supported) --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4a5a1bb3..e73161f9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,6 @@ php: - 7.2 - 7.3 - 7.4 - - 8.0 env: jobs: From 065e628a0f81be025b2fe4b3519ace84bc14d6fd Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 17:14:15 +0200 Subject: [PATCH 13/17] Fix failing test --- .gitignore | 2 ++ composer.json | 1 + tests/ResponseTest.php | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c4886e2e..b61f8d61 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ /vendor .DS_Store +.php_cs +.php_cs.cache .phpunit.result.cache composer.lock diff --git a/composer.json b/composer.json index 2eb0a0a8..637223d3 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "laravel/framework": "^6.12|^7.0|^8.0" }, "require-dev": { + "ext-json": "*", "orchestra/testbench": "^4.0|^5.0|^6.0" }, "extra": { diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index c4873516..bb8eee66 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -2,6 +2,7 @@ namespace Inertia\Tests; +use Arr; use Illuminate\Contracts\Support\Arrayable; use Inertia\Response; use Illuminate\View\View; @@ -103,7 +104,7 @@ public function test_lazy_resource_response() $page = $response->getData(); $expected = [ - 'data' => $users->take(2), + 'data' => $users->take(2)->toArray(), 'links' => [ 'first' => '/?page=1', 'last' => '/?page=2', @@ -123,9 +124,20 @@ public function test_lazy_resource_response() $this->assertInstanceOf(JsonResponse::class, $response); $this->assertSame('User/Index', $page->component); - $this->assertSame(json_encode($expected), json_encode($page->props->users)); $this->assertSame('/users?page=1', $page->url); $this->assertSame('123', $page->version); + + tap(json_decode(json_encode($page->props->users), true), function ($actual) use ($expected) { + // On Laravel 8+, new 'links' were added to the 'meta' section for convenience. + // We'll just inject these to our expected array to prevent testing issues + // on earlier version of Laravel. + if (Arr::has($actual, 'meta.links')) { + $expected['meta']['links'] = $actual['meta']['links']; + ksort($expected['meta']); + } + + $this->assertSame($expected, $actual); + }); } public function test_arrayable_prop_response() From f79efb142d78b97fa1371b495fb79285dba07c14 Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 15:16:49 +0000 Subject: [PATCH 14/17] Apply fixes from StyleCI --- helpers.php | 2 +- src/Middleware.php | 2 +- src/Response.php | 6 +++--- src/ResponseFactory.php | 2 +- src/ServiceProvider.php | 2 +- tests/ControllerTest.php | 4 ++-- tests/MiddlewareTest.php | 6 +++--- tests/ResponseTest.php | 15 +++++++-------- tests/ServiceProviderTest.php | 9 ++++----- 9 files changed, 23 insertions(+), 25 deletions(-) diff --git a/helpers.php b/helpers.php index cc07de2e..0a72145b 100644 --- a/helpers.php +++ b/helpers.php @@ -1,6 +1,6 @@ header('X-Inertia')) { + if (! $request->header('X-Inertia')) { return $response; } diff --git a/src/Response.php b/src/Response.php index 5623603d..981bee8c 100644 --- a/src/Response.php +++ b/src/Response.php @@ -3,11 +3,11 @@ namespace Inertia; use Closure; -use Illuminate\Support\Arr; -use Illuminate\Http\JsonResponse; -use Illuminate\Support\Facades\App; use Illuminate\Contracts\Support\Arrayable; use Illuminate\Contracts\Support\Responsable; +use Illuminate\Http\JsonResponse; +use Illuminate\Support\Arr; +use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Response as ResponseFactory; class Response implements Responsable diff --git a/src/ResponseFactory.php b/src/ResponseFactory.php index 1ccb42eb..10091b66 100644 --- a/src/ResponseFactory.php +++ b/src/ResponseFactory.php @@ -3,10 +3,10 @@ namespace Inertia; use Closure; +use Illuminate\Contracts\Support\Arrayable; use Illuminate\Support\Arr; use Illuminate\Support\Facades\App; use Illuminate\Support\Traits\Macroable; -use Illuminate\Contracts\Support\Arrayable; class ResponseFactory { diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 20c3e167..9a093955 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -2,10 +2,10 @@ namespace Inertia; +use Illuminate\Contracts\Http\Kernel; use Illuminate\Http\Request; use Illuminate\Routing\Router; use Illuminate\Support\Collection; -use Illuminate\Contracts\Http\Kernel; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Session; diff --git a/tests/ControllerTest.php b/tests/ControllerTest.php index d312fa2b..16fa6134 100644 --- a/tests/ControllerTest.php +++ b/tests/ControllerTest.php @@ -2,10 +2,10 @@ namespace Inertia\Tests; -use Inertia\Response; -use Inertia\Controller; use Illuminate\Http\Request; use Illuminate\Routing\Route; +use Inertia\Controller; +use Inertia\Response; class ControllerTest extends TestCase { diff --git a/tests/MiddlewareTest.php b/tests/MiddlewareTest.php index ee48bf6e..e94d81be 100644 --- a/tests/MiddlewareTest.php +++ b/tests/MiddlewareTest.php @@ -2,11 +2,11 @@ namespace Inertia\Tests; -use Inertia\Inertia; -use Inertia\Middleware; +use Illuminate\Foundation\Testing\TestResponse as LegacyTestResponse; use Illuminate\Http\Request; use Illuminate\Testing\TestResponse; -use Illuminate\Foundation\Testing\TestResponse as LegacyTestResponse; +use Inertia\Inertia; +use Inertia\Middleware; class MiddlewareTest extends TestCase { diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index bb8eee66..88bffc24 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -4,16 +4,16 @@ use Arr; use Illuminate\Contracts\Support\Arrayable; -use Inertia\Response; -use Illuminate\View\View; -use Illuminate\Http\Request; -use Illuminate\Support\Fluent; use Illuminate\Http\JsonResponse; -use Illuminate\Support\Collection; -use Illuminate\Http\Response as BaseResponse; -use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Http\Request; use Illuminate\Http\Resources\Json\JsonResource; use Illuminate\Http\Resources\Json\ResourceCollection; +use Illuminate\Http\Response as BaseResponse; +use Illuminate\Pagination\LengthAwarePaginator; +use Illuminate\Support\Collection; +use Illuminate\Support\Fluent; +use Illuminate\View\View; +use Inertia\Response; class ResponseTest extends TestCase { @@ -148,7 +148,6 @@ public function test_arrayable_prop_response() $user = (object) ['name' => 'Jonathan']; $resource = new class($user) implements Arrayable { - public $user; public function __construct($user) diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index d5120fe3..2940ba65 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -3,17 +3,16 @@ namespace Inertia\Tests; use Closure; -use Inertia\Inertia; -use Inertia\Middleware; use Illuminate\Http\Request; use Illuminate\Routing\Router; -use Illuminate\Support\MessageBag; use Illuminate\Support\Facades\App; -use Illuminate\Support\ViewErrorBag; -use Illuminate\Contracts\Http\Kernel; use Illuminate\Support\Facades\Blade; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Session; +use Illuminate\Support\MessageBag; +use Illuminate\Support\ViewErrorBag; +use Inertia\Inertia; +use Inertia\Middleware; class ServiceProviderTest extends TestCase { From f6cbb11a2466c2e3e12327c18e05e92d22894dc9 Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Wed, 30 Sep 2020 19:33:19 +0200 Subject: [PATCH 15/17] Lower minimal version to Laravel 6.10 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 637223d3..b77ad458 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ } }, "require": { - "laravel/framework": "^6.12|^7.0|^8.0" + "laravel/framework": "^6.10|^7.0|^8.0" }, "require-dev": { "ext-json": "*", From 19f86a63272d32008b3febace2e9ace5c9a8f3c6 Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Sat, 3 Oct 2020 21:25:50 +0200 Subject: [PATCH 16/17] Switch to Github Actions --- .github/workflows/tests.yml | 41 +++++++++++++++++++++++++++++++++++++ .travis.yml | 26 ----------------------- 2 files changed, 41 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/tests.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..dd5ccf52 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,41 @@ +name: tests + +on: + push: + pull_request: + schedule: + - cron: '0 0 * * *' + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php: + - 7.2 + - 7.3 + - 7.4 + composerFlags: + - '--prefer-lowest' + - '' + + name: PHP ${{ matrix.php }} w/ Composer ${{ matrix.composerFlags }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip + tools: composer:v2 + coverage: none + + - name: Install dependencies + run: | + composer update --prefer-dist --no-interaction --no-progress ${{ matrix.composerFlags }} + + - name: Execute tests + run: vendor/bin/phpunit --verbose diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e73161f9..00000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -os: linux -dist: xenial -language: php - -php: - - 7.2 - - 7.3 - - 7.4 - -env: - jobs: - - COMPOSER_FLAGS="--prefer-lowest" - - COMPOSER_FLAGS="" - -before_install: - - travis_retry composer self-update - -install: - - travis_retry composer update --prefer-source $COMPOSER_FLAGS - -script: - - phpunit - -#branches: -# only: -# - master From bbc7bcdf00d52a96165fb61b374fb7adf725069b Mon Sep 17 00:00:00 2001 From: Claudio Dekker Date: Sat, 3 Oct 2020 21:28:12 +0200 Subject: [PATCH 17/17] Fix identation --- .github/workflows/tests.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dd5ccf52..266f3212 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -21,21 +21,21 @@ jobs: - '' name: PHP ${{ matrix.php }} w/ Composer ${{ matrix.composerFlags }} - steps: - - name: Checkout code - uses: actions/checkout@v2 + steps: + - name: Checkout code + uses: actions/checkout@v2 - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip - tools: composer:v2 - coverage: none + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip + tools: composer:v2 + coverage: none - - name: Install dependencies - run: | - composer update --prefer-dist --no-interaction --no-progress ${{ matrix.composerFlags }} + - name: Install dependencies + run: | + composer update --prefer-dist --no-interaction --no-progress ${{ matrix.composerFlags }} - - name: Execute tests - run: vendor/bin/phpunit --verbose + - name: Execute tests + run: vendor/bin/phpunit --verbose