diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9cedc01..ae8b2fe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,35 +15,58 @@ jobs: runs-on: ubuntu-latest strategy: + fail-fast: true matrix: php: ['8.0', '8.1', '8.2'] + laravel: ['8.*', '9.*', '10.*', '11.*'] + dependency-version: [prefer-stable] + include: + - laravel: 10.* + testbench: 8.* + - laravel: 9.* + testbench: 7.* + - laravel: 8.* + testbench: 6.* + - laravel: 11.* + testbench: 9.* + exclude: + - laravel: 10.* + php: 8.0 + - laravel: 11.* + php: 8.1 + - laravel: 11.* + php: 8.0 + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - name: Copy .env.testing run: php -r "file_exists('.env.testing') || copy('.env.testing.example', '.env.testing');" - name: Set Nova credentials - run: echo '${{ secrets.NOVA_4_CREDENTIALS }}' > auth.json + run: composer config http-basic.nova.laravel.com ${{ secrets.NOVA_4_EMAIL }} ${{ secrets.NOVA_4_CREDENTIALS }} - name: Install Dependencies - run: composer update --no-interaction --prefer-source + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Execute tests (Unit and Feature tests) via PHPUnit run: ./vendor/bin/phpunit lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: shivammathur/setup-php@v2 with: php-version: "8.1" - name: Copy .env.testing run: php -r "file_exists('.env.testing') || copy('.env.testing.example', '.env.testing');" - name: Set Nova credentials - run: echo '${{ secrets.NOVA_4_CREDENTIALS }}' > auth.json + run: composer config http-basic.nova.laravel.com ${{ secrets.NOVA_4_EMAIL }} ${{ secrets.NOVA_4_CREDENTIALS }} - name: Install Dependencies - run: composer update --no-interaction --prefer-source + run: composer update --prefer-stable --prefer-dist --no-interaction - name: Execute tests (Unit and Feature tests) via PHPUnit run: ./vendor/bin/php-cs-fixer fix --dry-run diff --git a/.gitignore b/.gitignore index 1c66b12..fc427b1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ clover.xml auth.json +.phpunit.cache .phpunit.result.cache .phpunit.result/ .php_cs.cache diff --git a/README.md b/README.md index 5a48eb8..2ffbbc4 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ composer require --dev joshgaber/novaunit ### Requirements * PHP 7.3 or higher -* [Laravel](https://laravel.com/) 6.x - 10.x +* [Laravel](https://laravel.com/) 6.x - 11.x * [Laravel Nova](https://nova.laravel.com/) 2.x - 4.x -* [PHPUnit](https://github.com/sebastianbergmann/phpunit) 8.5.x - 10.x +* [PHPUnit](https://github.com/sebastianbergmann/phpunit) 8.5.x - 11.x ## Usage diff --git a/composer.json b/composer.json index b9653a6..95c5944 100644 --- a/composer.json +++ b/composer.json @@ -23,13 +23,13 @@ "php": "^8.0", "ext-mbstring": "*", "cakephp/chronos": ">=2.0.0", - "illuminate/support": "^8.83.4|^9.3.1|^10.0", + "illuminate/support": "^8.83.4|^9.3.1|^10.0|^11.0", "laravel/nova": "^4.0", - "phpunit/phpunit": "^9.0|^10.0" + "phpunit/phpunit": "^9.0|^10.0|^11.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.0", - "orchestra/testbench": "^6.0|^8.0" + "orchestra/testbench": "^6.0|^8.0|^9.0" }, "repositories": [ { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d89e8d4..10f058c 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,18 @@ - - - - tests - - - - - src - - - - - + + + + tests + + + + + + + + + + src + + diff --git a/src/Actions/MockActionResponse.php b/src/Actions/MockActionResponse.php index e8688f0..706523d 100644 --- a/src/Actions/MockActionResponse.php +++ b/src/Actions/MockActionResponse.php @@ -3,7 +3,9 @@ namespace JoshGaber\NovaUnit\Actions; use JoshGaber\NovaUnit\Constraints\IsActionResponseType; +use Laravel\Nova\Actions\ActionResponse; use PHPUnit\Framework\Assert as PHPUnit; +use PHPUnit\Framework\Constraint\IsInstanceOf; use PHPUnit\Framework\Constraint\IsType; class MockActionResponse @@ -27,8 +29,10 @@ public function assertResponseType(string $type, string $message = ''): self PHPUnit::assertThat( $this->response, PHPUnit::logicalAnd( - new IsType('array'), - new IsActionResponseType($type) + is_array($this->response) + ? new IsType('array') + : new IsInstanceOf(ActionResponse::class), + new IsActionResponseType($type, $this->response) ), $message ); @@ -88,7 +92,18 @@ public function assertRedirect(string $message = ''): self */ public function assertPush(string $message = ''): self { - return $this->assertResponseType('push', $message); + return $this->assertResponseType('visit', $message); + } + + /** + * Asserts the handle response is of type "visit". + * + * @param string $message + * @return $this + */ + public function assertVisit(string $message = ''): self + { + return $this->assertResponseType('visit', $message); } /** diff --git a/src/Constraints/IsActionResponseType.php b/src/Constraints/IsActionResponseType.php index 356163d..6919a93 100644 --- a/src/Constraints/IsActionResponseType.php +++ b/src/Constraints/IsActionResponseType.php @@ -7,10 +7,12 @@ class IsActionResponseType extends Constraint { + private $actionResponse; private $actionType; - public function __construct($actionType) + public function __construct($actionType, $actionResponse) { + $this->actionResponse = $actionResponse; $this->actionType = $actionType; } @@ -24,12 +26,16 @@ public function toString(): string public function matches($response): bool { - $structure = \array_keys(\call_user_func([Action::class, $this->actionType], 'param 1', 'param 2')); - $responseKeys = \array_keys($response); + if (is_array($this->actionResponse)) { + $structure = \array_keys(\call_user_func([Action::class, $this->actionType], 'param 1', 'param 2')); + $responseKeys = \array_keys($response); - \sort($structure); - \sort($responseKeys); + \sort($structure); + \sort($responseKeys); - return $structure === $responseKeys; + return $structure === $responseKeys; + } + + return $this->actionResponse->offsetExists($this->actionType); } } diff --git a/src/Filters/MockFilter.php b/src/Filters/MockFilter.php index eef99c6..b9f4a84 100644 --- a/src/Filters/MockFilter.php +++ b/src/Filters/MockFilter.php @@ -27,7 +27,7 @@ public function assertSelectFilter(string $message = ''): self PHPUnit::assertThat( $this->component, PHPUnit::logicalAnd( - new isInstanceOf(Filter::class), + new IsInstanceOf(Filter::class), PHPUnit::logicalNot(new IsInstanceOf(BooleanFilter::class)), PHPUnit::logicalNot(new IsInstanceOf(DateFilter::class)) ), diff --git a/src/Lenses/MockLensRequest.php b/src/Lenses/MockLensRequest.php index 9322ce2..b50cbdf 100644 --- a/src/Lenses/MockLensRequest.php +++ b/src/Lenses/MockLensRequest.php @@ -24,7 +24,7 @@ public function withFilters($query) return $query; } - public function withOrdering($query) + public function withOrdering($query, $defaultCallback = null) { $this->withOrdering = true; diff --git a/tests/Feature/Actions/MockActionResponseTest.php b/tests/Feature/Actions/MockActionResponseTest.php index cffc086..de3a106 100644 --- a/tests/Feature/Actions/MockActionResponseTest.php +++ b/tests/Feature/Actions/MockActionResponseTest.php @@ -62,10 +62,25 @@ public function testItFailsOnResponseOtherThanRedirect() public function testItSucceedsOnPushResponse() { - $mockActionResponse = new MockActionResponse(Action::push('test')); + $this->markTestSkipped('Action push has been deprecated.'); + + $mockActionResponse = new MockActionResponse(Action::push('test', '')); $mockActionResponse->assertPush(); } + public function testItSucceedsOnVisitResponse() + { + $mockActionResponse = new MockActionResponse(Action::visit('test')); + $mockActionResponse->assertVisit(); + } + + public function testItFailsOnResponseOtherThanVisit() + { + $this->shouldFail(); + $mockActionResponse = new MockActionResponse(Action::message('test')); + $mockActionResponse->assertVisit(); + } + public function testItFailsOnResponseOtherThanPush() { $this->shouldFail();