Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 11.x Upgrade, PHPUnit 11.x, CI Matrix and PHPUnit Upgrades #64

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ clover.xml

auth.json

.phpunit.cache
.phpunit.result.cache
.phpunit.result/
.php_cs.cache
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
38 changes: 16 additions & 22 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<report>
<clover outputFile="clover.xml" />
</report>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<coverage>
<report>
<clover outputFile="clover.xml"/>
</report>
</coverage>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
21 changes: 18 additions & 3 deletions src/Actions/MockActionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
);
Expand Down Expand Up @@ -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);
}

/**
Expand Down
18 changes: 12 additions & 6 deletions src/Constraints/IsActionResponseType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/Filters/MockFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
),
Expand Down
2 changes: 1 addition & 1 deletion src/Lenses/MockLensRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function withFilters($query)
return $query;
}

public function withOrdering($query)
public function withOrdering($query, $defaultCallback = null)
{
$this->withOrdering = true;

Expand Down
17 changes: 16 additions & 1 deletion tests/Feature/Actions/MockActionResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down