Skip to content

Commit

Permalink
Fix tests for Laravel 10 (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj authored May 20, 2023
2 parents d17ccbe + e1ef42d commit 81f4d0b
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 27 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ jobs:
experimental: false
composer: v2

- deps: 'dev'
- deps: 'stable'
php: 8.2
symfony: '6.x'
laravel: '10.x'
experimental: false
composer: v2

- deps: 'dev'
php: 8.3
symfony: '6.x'
laravel: '11.x'
experimental: true
composer: preview

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

2.4.0
-----

* Added Laravel 10 support
* Dropped Symfony <5.4 support

2.0.0
-----

Expand Down
39 changes: 19 additions & 20 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,31 @@

"require": {
"php": "^7.3 || ^8.0",
"illuminate/database": "^8.40 || ^9.0",
"illuminate/events": "^8.12 || ^9.0",
"illuminate/console": "^8.12 || ^9.0",
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
"illuminate/database": "^8.40 || ^9.0 || ^10.0",
"illuminate/events": "^8.12 || ^9.0 || ^10.0",
"illuminate/console": "^8.12 || ^9.0 || ^10.0",
"symfony/framework-bundle": "^5.4 || ^6.0",
"symfony/dependency-injection": "^5.4 || ^6.0",
"jdorn/sql-formatter": "^1.2.17"
},
"require-dev": {
"doctrine/annotations": "1.*",
"symfony/maker-bundle": "^1.20",
"mockery/mockery": "^1.3",
"symfony/console": "^4.4 || ^5.0 || ^6.0",
"symfony/event-dispatcher": "^4.4 || ^5.0 || ^6.0",
"symfony/http-kernel": "^4.4 || ^5.0 || ^6.0",
"symfony/finder": "^4.4 || ^5.0 || ^6.0",
"symfony/debug": "^4.4 || ^5.0 || ^6.0",
"symfony/yaml": "^4.4 || ^5.0 || ^6.0",
"symfony/form": "^4.4 || ^5.0 || ^6.0",
"symfony/phpunit-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/browser-kit": "^4.4 || ^5.0 || ^6.0",
"symfony/dom-crawler": "^4.4 || ^5.0 || ^6.0",
"symfony/validator": "^4.4 || ^5.0 || ^6.0",
"symfony/security-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/twig-bundle": "^4.4 || ^5.0 || ^6.0",
"symfony/twig-bridge": "^4.4 || ^5.0 || ^6.0",
"symfony/var-dumper": "^4.4 || ^5.0 || ^6.0",
"symfony/console": "^5.4 || ^6.0",
"symfony/event-dispatcher": "^5.4 || ^6.0",
"symfony/http-kernel": "^5.4 || ^6.0",
"symfony/finder": "^5.4 || ^6.0",
"symfony/yaml": "^5.4 || ^6.0",
"symfony/form": "^5.4 || ^6.0",
"symfony/phpunit-bridge": "^5.4 || ^6.0",
"symfony/browser-kit": "^5.4 || ^6.0",
"symfony/dom-crawler": "^5.4 || ^6.0",
"symfony/validator": "^5.4 || ^6.0",
"symfony/security-bundle": "^5.4 || ^6.0",
"symfony/twig-bundle": "^5.4 || ^6.0",
"symfony/twig-bridge": "^5.4 || ^6.0",
"symfony/var-dumper": "^5.4 || ^6.0",
"twig/twig": "^1.26 || ^2.0 || ^3.0",
"vimeo/psalm": "^3.18.2 || ^4.0",
"psalm/plugin-symfony": "^1.5.0 || ^2.0 || ^3.0"
Expand Down
24 changes: 24 additions & 0 deletions tests/Fixtures/migrations/blank-10.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use WouterJ\EloquentBundle\Facade\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
//
}

/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};
27 changes: 27 additions & 0 deletions tests/Fixtures/migrations/create-10.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use WouterJ\EloquentBundle\Facade\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('SomeTable', function (Blueprint $table) {
$table->id();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('SomeTable');
}
};
28 changes: 28 additions & 0 deletions tests/Fixtures/migrations/update-10.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use WouterJ\EloquentBundle\Facade\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('SomeTable', function (Blueprint $table) {
//
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('SomeTable', function (Blueprint $table) {
//
});
}
};
17 changes: 17 additions & 0 deletions tests/Fixtures/seeds/PostSeeder.laravel10.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Seed;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use WouterJ\EloquentBundle\Seeder;

class PostSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
}
}
2 changes: 1 addition & 1 deletion tests/Functional/app/src/AppBundle/AppBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
class AppBundle extends Bundle
{
public function boot()
public function boot(): void
{
User::observe(UserObserver::class);
SoftDeleteUser::observe(UserObserver::class);
Expand Down
11 changes: 7 additions & 4 deletions tests/Maker/SeederMakeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WouterJ\EloquentBundle\Maker;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Eloquent\Casts\Json;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\FileManager;
Expand Down Expand Up @@ -52,11 +53,13 @@ public function provideSeederNames()

private function expectSeeder(string $name)
{
$fixturePath = file_get_contents(__DIR__.'/../Fixtures/seeds/'.$name.'.php');
if (trait_exists(WithoutModelEvents::class)) {
$fixturePath = file_get_contents(__DIR__.'/../Fixtures/seeds/'.$name.'.laravel9.php');
$fixturePath = __DIR__.'/../Fixtures/seeds/'.$name.'.php';
if (class_exists(Json::class)) {
$fixturePath = __DIR__.'/../Fixtures/seeds/'.$name.'.laravel10.php';
} elseif (trait_exists(WithoutModelEvents::class)) {
$fixturePath = __DIR__.'/../Fixtures/seeds/'.$name.'.laravel9.php';
}
$normalizedExpected = preg_replace('/\R/', "\n", $fixturePath);
$normalizedExpected = preg_replace('/\R/', "\n", file_get_contents($fixturePath));

$path = '/app/src/Seed/'.$name.'.php';
$this->fileManager->allows()->getRelativePathForFutureClass()->with('App\\Seed\\'.$name)->andReturn($path);
Expand Down
5 changes: 4 additions & 1 deletion tests/Migrations/CreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace WouterJ\EloquentBundle\Migrations;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Eloquent\Casts\Json;
use Illuminate\Database\Schema\Blueprint;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\MakerBundle\FileManager;
Expand Down Expand Up @@ -56,7 +57,9 @@ private function expectMigration(string $type, string $name)
{
$normalize = function ($str) { return preg_replace('/\R/', "\n", $str); };

if (trait_exists(WithoutModelEvents::class)) {
if (class_exists(Json::class)) {
$type .= '-10';
} elseif (trait_exists(WithoutModelEvents::class)) {
$type .= '-9';
}
$expected = $normalize(file_get_contents(__DIR__.'/../Fixtures/migrations/'.$type.'.php'));
Expand Down

0 comments on commit 81f4d0b

Please sign in to comment.