Skip to content

Commit 4339e28

Browse files
authored
Drop Laravel 6 and 7 support, add support for new Laravel Console (#132)
2 parents 10bbbad + dac6ce1 commit 4339e28

File tree

9 files changed

+46
-71
lines changed

9 files changed

+46
-71
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@ jobs:
2222
matrix:
2323
include:
2424
- deps: 'low'
25-
php: 7.2
26-
experimental: false
27-
composer: v2
28-
29-
- deps: 'stable'
30-
php: 8.1
31-
symfony: '5.x'
32-
laravel: '7.x'
25+
php: 7.3
3326
experimental: false
3427
composer: v2
3528

@@ -49,6 +42,7 @@ jobs:
4942

5043
- deps: 'dev'
5144
php: 8.2
45+
laravel: '10.x'
5246
experimental: true
5347
composer: preview
5448

@@ -74,7 +68,7 @@ jobs:
7468
7569
;;
7670
"dev")
77-
echo "COMPOSER_FLAGS=--ignore-platform-req=php" >> $GITHUB_ENV
71+
echo "COMPOSER_FLAGS=--ignore-platform-req=php+" >> $GITHUB_ENV
7872
7973
composer config minimum-stability dev
8074
@@ -107,8 +101,11 @@ jobs:
107101

108102
- name: Install dependencies
109103
run: |
104+
composer global config --no-plugins allow-plugins.symfony/flex true
110105
composer global require --no-progress --no-scripts --no-plugins symfony/flex
111-
if [ "$LARAVEL_REQUIRE" != "" ]; then composer require --no-update illuminate/database:$LARAVEL_REQUIRE; fi
106+
if [ "$LARAVEL_REQUIRE" != "" ]; then
107+
composer require --no-update illuminate/database:$LARAVEL_REQUIRE illuminate/events:$LARAVEL_REQUIRE illuminate/console:$LARAVEL_REQUIRE
108+
fi
112109
composer update --prefer-dist --no-progress $COMPOSER_FLAGS
113110
./vendor/bin/simple-phpunit install
114111

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"type": "symfony-bundle",
77

88
"require": {
9-
"php": "^7.2 || ^8.0",
10-
"illuminate/database": "^6.18 || ^7.30.4 || ^8.40 || ^9.0",
11-
"illuminate/events": "^6.18 || ^7.15 || ^8.12 || ^9.0",
12-
"illuminate/console": "^6.18 || ^7.15 || ^8.12 || ^9.0",
9+
"php": "^7.3 || ^8.0",
10+
"illuminate/database": "^8.40 || ^9.0",
11+
"illuminate/events": "^8.12 || ^9.0",
12+
"illuminate/console": "^8.12 || ^9.0",
1313
"symfony/framework-bundle": "^4.4 || ^5.0 || ^6.0",
1414
"symfony/dependency-injection": "^4.4 || ^5.0 || ^6.0",
1515
"jdorn/sql-formatter": "^1.2.17"
@@ -37,6 +37,9 @@
3737
"vimeo/psalm": "^3.18.2 || ^4.0",
3838
"psalm/plugin-symfony": "^1.5.0 || ^2.0 || ^3.0"
3939
},
40+
"conflict": {
41+
"illuminate/console": ">=9.21,<9.39"
42+
},
4043

4144
"autoload": { "psr-4": { "WouterJ\\EloquentBundle\\": "src" } },
4245
"autoload-dev": {

src/Maker/MakeSeeder.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
7373
$stub = str_replace(IlluminateSeeder::class, Seeder::class, $stub);
7474

7575
if ($namespace = Str::getNamespace($seederClassDetails->getFullName())) {
76-
if (class_exists(DumpCommand::class)) {
77-
// Laravel 8
78-
$stub = str_replace('namespace Database\Seeders;', 'namespace '.$namespace.';', $stub);
79-
} else {
80-
// Laravel 6 & 7
81-
$stub = str_replace('<?php', "<?php\n\nnamespace ".$namespace.';', $stub);
82-
}
76+
$stub = str_replace('namespace Database\Seeders;', 'namespace '.$namespace.';', $stub);
8377
$stub = str_replace('{{ namespace }}', $namespace, $stub);
8478
}
8579

src/Migrations/Creator.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function create($name, $path, $table = null, $create = false): string
4040
$stub = $this->getStub($table, $create);
4141

4242
if (!trait_exists(WithoutModelEvents::class)) {
43+
// BC for Laravel <9
4344
/** @psalm-suppress TooManyArguments BC with Laravel <9 */
4445
$populatedStub = $this->populateStub($name, $stub, $table);
4546
} else {
@@ -56,17 +57,9 @@ public function create($name, $path, $table = null, $create = false): string
5657

5758
protected function getStub($table, $create): string
5859
{
59-
$eloquent7 = file_exists($this->stubPath().'/migration.stub');
60-
if ($eloquent7) {
61-
$file = 'migration.stub';
62-
if (null !== $table) {
63-
$file = $create ? 'migration.create.stub' : 'migration.update.stub';
64-
}
65-
} else {
66-
$file = 'blank.stub';
67-
if (null !== $table) {
68-
$file = $create ? 'create.stub' : 'update.stub';
69-
}
60+
$file = 'migration.stub';
61+
if (null !== $table) {
62+
$file = $create ? 'migration.create.stub' : 'migration.update.stub';
7063
}
7164

7265
// TODO add support to overwrite stub templates (ref https://github.com/illuminate/database/commit/b0300976c7a496bcaef5917b9efe72039b3d947a)

src/Security/EloquentUserProvider.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,16 @@ public function loadUserByIdentifier(string $identifier): UserInterface
5656
$e = new UserNotFoundException();
5757
$e->setUserIdentifier($identifier);
5858
} else {
59-
// BC with symfony/security-core <5.3
59+
/** @psalm-suppress UndefinedClass BC with symfony/security-core <5.3 */
6060
$e = new UsernameNotFoundException();
61-
/** @psalm-suppress UndefinedMethod https://github.com/vimeo/psalm/issues/5750 */
61+
/**
62+
* @psalm-suppress UndefinedMethod https://github.com/vimeo/psalm/issues/5750
63+
* @psalm-suppress UndefinedClass
64+
*/
6265
$e->setUsername($identifier);
6366
}
6467

68+
/** @psalm-suppress InvalidThrow */
6569
throw $e;
6670
}
6771

@@ -83,12 +87,16 @@ public function refreshUser(UserInterface $user): UserInterface
8387
$e = new UserNotFoundException();
8488
$e->setUserIdentifier($userIdentifier);
8589
} else {
86-
// BC with symfony/security-core <5.3
90+
/** @psalm-suppress UndefinedClass BC with symfony/security-core <5.3 */
8791
$e = new UsernameNotFoundException();
88-
/** @psalm-suppress UndefinedMethod https://github.com/vimeo/psalm/issues/5750 */
92+
/**
93+
* @psalm-suppress UndefinedMethod https://github.com/vimeo/psalm/issues/5750
94+
* @psalm-suppress UndefinedClass
95+
*/
8996
$e->setUsername($userIdentifier);
9097
}
9198

99+
/** @psalm-suppress InvalidThrow */
92100
throw $e;
93101
}
94102

tests/Fixtures/migrations/create-6.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/Functional/MigrationsTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace WouterJ\EloquentBundle\Functional;
1313

14+
use Illuminate\Console\View\Components\Task;
1415
use PHPUnit\Runner\Version;
1516
use Symfony\Bundle\FrameworkBundle\Console\Application;
1617
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
@@ -39,8 +40,13 @@ public function testRunningMigrations()
3940

4041
$app->run(['command' => 'eloquent:migrate', '--seed' => true], ['decorated' => false]);
4142

43+
$regex = '/^\s+2015_02_16_203700_CreateUsersTable \.+ \d+ms DONE/m';
44+
if (!class_exists(Task::class)) {
45+
// BC with Laravel <9.22
46+
$regex = '/^Migrated:\s+2015_02_16_203700_CreateUsersTable\s/m';
47+
}
4248
$assertMethod = version_compare(Version::series(), '9.1', '>=') ? 'assertMatchesRegularExpression' : 'assertRegExp';
43-
$this->{$assertMethod}('/^Migrated:\s+2015_02_16_203700_CreateUsersTable\s/m', $app->getDisplay());
49+
$this->{$assertMethod}($regex, $app->getDisplay());
4450

4551
$result = Db::select('select * from users');
4652
$this->assertCount(1, $result);

tests/Maker/SeederMakeCommandTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
66
use PHPUnit\Framework\TestCase;
7+
use Symfony\Bundle\MakerBundle\DependencyBuilder;
78
use Symfony\Bundle\MakerBundle\FileManager;
89
use Symfony\Bundle\MakerBundle\Generator;
910
use Symfony\Bundle\MakerBundle\Util\PhpCompatUtil;
@@ -22,7 +23,13 @@ protected function setUp(): void
2223
{
2324
$this->fileManager = \Mockery::spy(FileManager::class);
2425
$this->maker = new MakeSeeder($this->fileManager);
25-
$this->generator = new Generator($this->fileManager, 'App', class_exists(PhpCompatUtil::class) ? new PhpCompatUtil($this->fileManager) : null);
26+
27+
$phpCompatUtil = null;
28+
if (class_exists(PhpCompatUtil::class) && method_exists(DependencyBuilder::class, 'isPhpVersionSatisfied')) {
29+
// PHP compat util must be used in SymfonyMakerBundle >=1.22,<1.44 and we need at most 1.43 for PHP <8.0 support testing
30+
$phpCompatUtil = new PhpCompatUtil($this->fileManager);
31+
}
32+
$this->generator = new Generator($this->fileManager, 'App', $phpCompatUtil);
2633
}
2734

2835
/**

tests/Migrations/CreatorTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ private function expectMigration(string $type, string $name)
5858

5959
if (trait_exists(WithoutModelEvents::class)) {
6060
$type .= '-9';
61-
} elseif ('create' === $type && !file_exists($this->subject->stubPath().'/migration.stub')) {
62-
$type .= '-6';
6361
}
6462
$expected = $normalize(file_get_contents(__DIR__.'/../Fixtures/migrations/'.$type.'.php'));
6563

0 commit comments

Comments
 (0)