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 9.x #77

Merged
merged 5 commits into from
Jan 20, 2022
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs.dist.php --allow-risky=yes
args: --config=.php-cs-fixer.dist.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
8 changes: 2 additions & 6 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Psalm

on:
push:
paths:
- '**.php'
- 'psalm.xml.dist'
on: ['push']

jobs:
psalm:
Expand All @@ -16,7 +12,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

Expand Down
12 changes: 5 additions & 7 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: run-tests

on:
push:
branches: [main]
pull_request:
branches: [main]
on: ['push']

jobs:
test:
Expand All @@ -13,12 +9,14 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.0,8.1]
laravel: [8.*]
php: [8.0, 8.1]
laravel: [8.*, 9.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 8.*
testbench: ^6.6
- laravel: 9.*
testbench: 7.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
File renamed without changes.
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
],
"require": {
"php": "^8.0",
"illuminate/contracts": "^8.71",
"illuminate/contracts": "^8.71|^9.0",
"phpdocumentor/type-resolver": "^1.5",
"spatie/laravel-package-tools": "^1.9.0"
},
"require-dev": {
"brianium/paratest": "^6.2",
"fakerphp/faker": "^1.14",
"friendsofphp/php-cs-fixer": "^3.0",
"nette/php-generator": "^3.5",
"nunomaduro/collision": "^5.3",
"orchestra/testbench": "^6.23",
"nunomaduro/collision": "^5.3|^6.0",
"orchestra/testbench": "^6.23|^7.0",
"phpunit/phpunit": "^9.3",
"spatie/laravel-enum": "^2.5",
"spatie/laravel-typescript-transformer": "^2.0",
"spatie/phpunit-snapshot-assertions": "^4.2",
"spatie/test-time": "^1.2",
Expand All @@ -46,9 +46,10 @@
}
},
"scripts": {
"psalm": "vendor/bin/psalm --no-cache --php-version=8.1",
"test": "./vendor/bin/testbench package:test --parallel --no-coverage",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
"psalm": "vendor/bin/psalm --no-cache",
"test": "./vendor/bin/paratest --no-coverage",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage",
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes"
},
"config": {
"sort-packages": true
Expand Down
1 change: 0 additions & 1 deletion src/Transformers/EnumTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class EnumTransformer implements Transformer
{
public function transform(DataProperty $property, mixed $value): string|int
{
/** @var \BackedEnum $value */
return $value->value;
}
}
5 changes: 0 additions & 5 deletions tests/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use Spatie\LaravelData\Tests\Factories\DataPropertyBlueprintFactory;
use Spatie\LaravelData\Tests\Fakes\DefaultLazyData;
use Spatie\LaravelData\Tests\Fakes\DummyDto;
use Spatie\LaravelData\Tests\Fakes\DummyEnum;
use Spatie\LaravelData\Tests\Fakes\DummyModel;
use Spatie\LaravelData\Tests\Fakes\DummyModelWithCasts;
use Spatie\LaravelData\Tests\Fakes\EmptyData;
Expand Down Expand Up @@ -595,7 +594,6 @@ public function it_can_create_a_data_object_from_a_model()
'boolean' => true,
'date' => CarbonImmutable::create(2020, 05, 16, 12, 00, 00),
'nullable_date' => null,
'enum' => DummyEnum::published(),
]);

$dataClass = new class () extends Data {
Expand All @@ -606,8 +604,6 @@ public function it_can_create_a_data_object_from_a_model()
public Carbon $date;

public ?Carbon $nullable_date;

public DummyEnum $enum;
};

$data = $dataClass::from(DummyModel::findOrFail($model->id));
Expand All @@ -616,7 +612,6 @@ public function it_can_create_a_data_object_from_a_model()
$this->assertTrue($data->boolean);
$this->assertTrue(CarbonImmutable::create(2020, 05, 16, 12, 00, 00)->eq($data->date));
$this->assertNull($data->nullable_date);
$this->assertTrue($data->enum->equals(DummyEnum::published()));
}

/** @test */
Expand Down
2 changes: 0 additions & 2 deletions tests/Fakes/DummyModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class DummyModel extends Model
'date' => 'datetime',
'nullable_date' => 'datetime',
'boolean' => 'boolean',
'enum' => DummyEnum::class,
];

public static function migrate()
Expand All @@ -24,7 +23,6 @@ public static function migrate()
$blueprint->dateTime('date');
$blueprint->dateTime('nullable_date')->nullable();
$blueprint->boolean('boolean');
$blueprint->string('enum');

$blueprint->timestamps();
});
Expand Down
29 changes: 0 additions & 29 deletions tests/Resolvers/DataFromModelResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Spatie\LaravelData\Resolvers\DataFromModelResolver;
use Spatie\LaravelData\Tests\Factories\DataBlueprintFactory;
use Spatie\LaravelData\Tests\Factories\DataPropertyBlueprintFactory;
use Spatie\LaravelData\Tests\Fakes\DummyEnum;
use Spatie\LaravelData\Tests\Fakes\SimpleData;
use Spatie\LaravelData\Tests\TestCase;

Expand Down Expand Up @@ -41,34 +40,6 @@ public function it_can_get_a_data_object_from_model()
$this->assertEquals(new SimpleData('Hello'), $data);
}

/** @test */
public function it_can_get_a_data_object_from_model_with_casts()
{
$fakeModelClass = new class () extends Model {
protected $casts = [
'enum' => DummyEnum::class,
];
};

$model = $fakeModelClass::make([
'enum' => DummyEnum::published(),
]);

$dataClass = DataBlueprintFactory::new('DataFromModelWithCast')
->withProperty(
DataPropertyBlueprintFactory::new('enum')
->withType(DummyEnum::class)
)
->create();

$data = $this->resolver->execute(
$dataClass,
$model
);

$this->assertTrue($data->enum->equals(DummyEnum::published()));
}

/** @test */
public function it_can_get_a_data_object_from_model_with_dates()
{
Expand Down