Skip to content

Commit

Permalink
Merge pull request #31 from sourcetoad/laravel-11
Browse files Browse the repository at this point in the history
PHP 8.3 & Laravel 11 support
  • Loading branch information
Jasonej authored Mar 13, 2024
2 parents 764c5d8 + b293f4b commit 97c65cf
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 81 deletions.
45 changes: 18 additions & 27 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,35 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.1, 8.2]
laravel: [9.0, 10.0]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 9.0
testbench: 7.0
- laravel: 10.0
testbench: 8.0
name: PHP ${{ matrix.php }} - Laravel v${{ matrix.laravel }} - ${{ matrix.stability }}
php: [8.1, 8.2, 8.3]
stability: ["--prefer-lowest", "--prefer-stable"]
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, gd
coverage: none

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- name: Cache Dependencies
uses: actions/cache@v2
- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-php-${{ matrix.php }}-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-${{ matrix.php }}-${{ matrix.stability }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, gd
coverage: none
${{ runner.os }}-${{ matrix.php }}-${{ matrix.stability }}-composer-
- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-suggest

- name: Require specific versions of packages
run: composer update laravel/framework:^${{ matrix.laravel }} orchestra/testbench:^${{ matrix.testbench }} -W
run: composer update ${{ matrix.stability }} --prefer-dist --no-interaction --no-suggest

- name: Execute tests
run: vendor/bin/phpunit
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
}
},
"require": {
"php": "^8.0",
"laravel/framework": "^9.0|^10.0"
"php": "^8.1",
"laravel/framework": "^10.0|^11.0"
},
"require-dev": {
"orchestra/testbench": "^7.0|^8.0",
"phpunit/phpunit": "^9.5|^10.0"
"orchestra/testbench": "^8.0|^9.0",
"phpunit/phpunit": "^10.0|^11.0"
}
}
16 changes: 8 additions & 8 deletions tests/Unit/AnonymousResourceCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace Sourcetoad\EnhancedResources\Tests\Unit;

use PHPUnit\Framework\Attributes\DataProvider;
use Sourcetoad\EnhancedResources\AnonymousResourceCollection;
use Sourcetoad\EnhancedResources\ResourceCollection;
use Sourcetoad\EnhancedResources\Tests\ExplicitDefaultResource;
use Sourcetoad\EnhancedResources\Tests\ImplicitDefaultCollection;
use Sourcetoad\EnhancedResources\Tests\ImplicitDefaultResource;
use Sourcetoad\EnhancedResources\Tests\TestCase;
use stdClass;

class AnonymousResourceCollectionTest extends TestCase
{
/** @dataProvider formatProvider */
#[DataProvider('formatProvider')]
public function test_anonymous_collection_records_are_formatted_correctly(
AnonymousResourceCollection $collection,
array $expectedData
Expand All @@ -26,7 +26,7 @@ public function test_anonymous_collection_records_are_formatted_correctly(
$this->assertSame($expectedData, $actualData);
}

/** @dataProvider modificationProvider */
#[DataProvider('modificationProvider')]
public function test_anonymous_collection_can_be_modified_dynamically(
ResourceCollection $resource,
array $expectedData,
Expand Down Expand Up @@ -62,7 +62,7 @@ public function test_response_status_can_be_set(): void

# region Data Providers

public function formatProvider(): array
public static function formatProvider(): array
{
$john = new stdClass;
$john->id = 1;
Expand All @@ -76,7 +76,7 @@ public function formatProvider(): array

return [
'implicit default is used' => [
'resource' => ImplicitDefaultResource::collection([$john, $jane]),
'collection' => ImplicitDefaultResource::collection([$john, $jane]),
'expectedData' => [
[
'first_name' => 'John',
Expand All @@ -91,7 +91,7 @@ public function formatProvider(): array
],
],
'explicit default is used' => [
'resource' => ExplicitDefaultResource::collection([$john, $jane]),
'collection' => ExplicitDefaultResource::collection([$john, $jane]),
'expectedData' => [
[
'first_name' => 'John',
Expand All @@ -106,7 +106,7 @@ public function formatProvider(): array
],
],
'specified format is used' => [
'resource' => ExplicitDefaultResource::collection([$john, $jane])->format('bar'),
'collection' => ExplicitDefaultResource::collection([$john, $jane])->format('bar'),
'expectedData' => [
[
'id' => 1,
Expand All @@ -127,7 +127,7 @@ public function formatProvider(): array
];
}

public function modificationProvider(): array
public static function modificationProvider(): array
{
$john = new stdClass;
$john->id = 1;
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Enhancements/ExceptTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Sourcetoad\EnhancedResources\Tests\Unit\Enhancements;

use PHPUnit\Framework\Attributes\DataProvider;
use Sourcetoad\EnhancedResources\Enhancements\Except;
use Sourcetoad\EnhancedResources\Enhancements\Traits\HasExceptEnhancement;
use Sourcetoad\EnhancedResources\Formatting\Attributes\Format;
Expand All @@ -12,7 +13,7 @@

class ExceptTest extends TestCase
{
/** @dataProvider resourceProvider */
#[DataProvider('resourceProvider')]
public function test_except_enhancement_can_be_applied_to_resources(
Resource $resource,
array $expectedData,
Expand All @@ -26,7 +27,7 @@ public function test_except_enhancement_can_be_applied_to_resources(

# region Data Providers

public function resourceProvider(): array
public static function resourceProvider(): array
{
return [
'applied manually' => [
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Enhancements/OnlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Sourcetoad\EnhancedResources\Tests\Unit\Enhancements;

use PHPUnit\Framework\Attributes\DataProvider;
use Sourcetoad\EnhancedResources\Enhancements\Only;
use Sourcetoad\EnhancedResources\Enhancements\Traits\HasOnlyEnhancement;
use Sourcetoad\EnhancedResources\Formatting\Attributes\Format;
Expand All @@ -12,7 +13,7 @@

class OnlyTest extends TestCase
{
/** @dataProvider resourceProvider */
#[DataProvider('resourceProvider')]
public function test_only_enhancement_can_be_applied_to_resources(
Resource $resource,
array $expectedData,
Expand All @@ -26,7 +27,7 @@ public function test_only_enhancement_can_be_applied_to_resources(

# region Data Providers

public function resourceProvider(): array
public static function resourceProvider(): array
{
return [
'applied manually' => [
Expand Down
15 changes: 8 additions & 7 deletions tests/Unit/Formatting/FormatDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Sourcetoad\EnhancedResources\Tests\Unit\Formatting;

use Closure;
use PHPUnit\Framework\Attributes\DataProvider;
use ReflectionMethod;
use Sourcetoad\EnhancedResources\Formatting\Attributes\Format;
use Sourcetoad\EnhancedResources\Formatting\Attributes\IsDefault;
Expand All @@ -13,7 +14,7 @@

class FormatDefinitionTest extends TestCase
{
/** @dataProvider nameDetectionProvider */
#[DataProvider('nameDetectionProvider')]
public function test_name_is_properly_detected(ReflectionMethod $method, Closure $assertions): void
{
# Act
Expand All @@ -23,7 +24,7 @@ public function test_name_is_properly_detected(ReflectionMethod $method, Closure
$assertions($definition);
}

/** @dataProvider defaultDetectionProvider */
#[DataProvider('defaultDetectionProvider')]
public function test_explicit_default_is_properly_detected(ReflectionMethod $method, bool $expected): void
{
# Arrange
Expand All @@ -38,7 +39,7 @@ public function test_explicit_default_is_properly_detected(ReflectionMethod $met

# region Data Providers

public function defaultDetectionProvider(): array
public static function defaultDetectionProvider(): array
{
$subject = new class {
#[Format('bar')]
Expand All @@ -60,7 +61,7 @@ public function foo() {}
];
}

public function nameDetectionProvider(): array
public static function nameDetectionProvider(): array
{
$subject = new class {
#[Format('bar')]
Expand All @@ -74,19 +75,19 @@ public function foo() {}
'implicit name' => [
'method' => new ReflectionMethod($subject, 'foo'),
'assertions' => function (FormatDefinition $definition) {
$this->assertSame('foo', $definition->name());
static::assertSame('foo', $definition->name());
},
],
'explicit name' => [
'method' => new ReflectionMethod($subject, 'barFormat'),
'assertions' => function (FormatDefinition $definition) {
$this->assertSame('bar', $definition->name());
static::assertSame('bar', $definition->name());
}
],
'alias' => [
'method' => new ReflectionMethod($subject, 'foo'),
'assertions' => function (FormatDefinition $definition) {
$this->assertContains('fooAlias', $definition->names());
static::assertContains('fooAlias', $definition->names());
}
],
];
Expand Down
Loading

0 comments on commit 97c65cf

Please sign in to comment.