Skip to content

Commit

Permalink
Drop Laravel 6 and 7 support, add support for new Laravel Console (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Nov 9, 2022
2 parents 10bbbad + dac6ce1 commit 4339e28
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 71 deletions.
17 changes: 7 additions & 10 deletions .github/workflows/tests.yml
Expand Up @@ -22,14 +22,7 @@ jobs:
matrix:
include:
- deps: 'low'
php: 7.2
experimental: false
composer: v2

- deps: 'stable'
php: 8.1
symfony: '5.x'
laravel: '7.x'
php: 7.3
experimental: false
composer: v2

Expand All @@ -49,6 +42,7 @@ jobs:

- deps: 'dev'
php: 8.2
laravel: '10.x'
experimental: true
composer: preview

Expand All @@ -74,7 +68,7 @@ jobs:
;;
"dev")
echo "COMPOSER_FLAGS=--ignore-platform-req=php" >> $GITHUB_ENV
echo "COMPOSER_FLAGS=--ignore-platform-req=php+" >> $GITHUB_ENV
composer config minimum-stability dev
Expand Down Expand Up @@ -107,8 +101,11 @@ jobs:

- name: Install dependencies
run: |
composer global config --no-plugins allow-plugins.symfony/flex true
composer global require --no-progress --no-scripts --no-plugins symfony/flex
if [ "$LARAVEL_REQUIRE" != "" ]; then composer require --no-update illuminate/database:$LARAVEL_REQUIRE; fi
if [ "$LARAVEL_REQUIRE" != "" ]; then
composer require --no-update illuminate/database:$LARAVEL_REQUIRE illuminate/events:$LARAVEL_REQUIRE illuminate/console:$LARAVEL_REQUIRE
fi
composer update --prefer-dist --no-progress $COMPOSER_FLAGS
./vendor/bin/simple-phpunit install
Expand Down
11 changes: 7 additions & 4 deletions composer.json
Expand Up @@ -6,10 +6,10 @@
"type": "symfony-bundle",

"require": {
"php": "^7.2 || ^8.0",
"illuminate/database": "^6.18 || ^7.30.4 || ^8.40 || ^9.0",
"illuminate/events": "^6.18 || ^7.15 || ^8.12 || ^9.0",
"illuminate/console": "^6.18 || ^7.15 || ^8.12 || ^9.0",
"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",
"jdorn/sql-formatter": "^1.2.17"
Expand Down Expand Up @@ -37,6 +37,9 @@
"vimeo/psalm": "^3.18.2 || ^4.0",
"psalm/plugin-symfony": "^1.5.0 || ^2.0 || ^3.0"
},
"conflict": {
"illuminate/console": ">=9.21,<9.39"
},

"autoload": { "psr-4": { "WouterJ\\EloquentBundle\\": "src" } },
"autoload-dev": {
Expand Down
8 changes: 1 addition & 7 deletions src/Maker/MakeSeeder.php
Expand Up @@ -73,13 +73,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
$stub = str_replace(IlluminateSeeder::class, Seeder::class, $stub);

if ($namespace = Str::getNamespace($seederClassDetails->getFullName())) {
if (class_exists(DumpCommand::class)) {
// Laravel 8
$stub = str_replace('namespace Database\Seeders;', 'namespace '.$namespace.';', $stub);
} else {
// Laravel 6 & 7
$stub = str_replace('<?php', "<?php\n\nnamespace ".$namespace.';', $stub);
}
$stub = str_replace('namespace Database\Seeders;', 'namespace '.$namespace.';', $stub);
$stub = str_replace('{{ namespace }}', $namespace, $stub);
}

Expand Down
15 changes: 4 additions & 11 deletions src/Migrations/Creator.php
Expand Up @@ -40,6 +40,7 @@ public function create($name, $path, $table = null, $create = false): string
$stub = $this->getStub($table, $create);

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

protected function getStub($table, $create): string
{
$eloquent7 = file_exists($this->stubPath().'/migration.stub');
if ($eloquent7) {
$file = 'migration.stub';
if (null !== $table) {
$file = $create ? 'migration.create.stub' : 'migration.update.stub';
}
} else {
$file = 'blank.stub';
if (null !== $table) {
$file = $create ? 'create.stub' : 'update.stub';
}
$file = 'migration.stub';
if (null !== $table) {
$file = $create ? 'migration.create.stub' : 'migration.update.stub';
}

// TODO add support to overwrite stub templates (ref https://github.com/illuminate/database/commit/b0300976c7a496bcaef5917b9efe72039b3d947a)
Expand Down
16 changes: 12 additions & 4 deletions src/Security/EloquentUserProvider.php
Expand Up @@ -56,12 +56,16 @@ public function loadUserByIdentifier(string $identifier): UserInterface
$e = new UserNotFoundException();
$e->setUserIdentifier($identifier);
} else {
// BC with symfony/security-core <5.3
/** @psalm-suppress UndefinedClass BC with symfony/security-core <5.3 */
$e = new UsernameNotFoundException();
/** @psalm-suppress UndefinedMethod https://github.com/vimeo/psalm/issues/5750 */
/**
* @psalm-suppress UndefinedMethod https://github.com/vimeo/psalm/issues/5750
* @psalm-suppress UndefinedClass
*/
$e->setUsername($identifier);
}

/** @psalm-suppress InvalidThrow */
throw $e;
}

Expand All @@ -83,12 +87,16 @@ public function refreshUser(UserInterface $user): UserInterface
$e = new UserNotFoundException();
$e->setUserIdentifier($userIdentifier);
} else {
// BC with symfony/security-core <5.3
/** @psalm-suppress UndefinedClass BC with symfony/security-core <5.3 */
$e = new UsernameNotFoundException();
/** @psalm-suppress UndefinedMethod https://github.com/vimeo/psalm/issues/5750 */
/**
* @psalm-suppress UndefinedMethod https://github.com/vimeo/psalm/issues/5750
* @psalm-suppress UndefinedClass
*/
$e->setUsername($userIdentifier);
}

/** @psalm-suppress InvalidThrow */
throw $e;
}

Expand Down
31 changes: 0 additions & 31 deletions tests/Fixtures/migrations/create-6.php

This file was deleted.

8 changes: 7 additions & 1 deletion tests/Functional/MigrationsTest.php
Expand Up @@ -11,6 +11,7 @@

namespace WouterJ\EloquentBundle\Functional;

use Illuminate\Console\View\Components\Task;
use PHPUnit\Runner\Version;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
Expand Down Expand Up @@ -39,8 +40,13 @@ public function testRunningMigrations()

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

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

$result = Db::select('select * from users');
$this->assertCount(1, $result);
Expand Down
9 changes: 8 additions & 1 deletion tests/Maker/SeederMakeCommandTest.php
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\MakerBundle\DependencyBuilder;
use Symfony\Bundle\MakerBundle\FileManager;
use Symfony\Bundle\MakerBundle\Generator;
use Symfony\Bundle\MakerBundle\Util\PhpCompatUtil;
Expand All @@ -22,7 +23,13 @@ protected function setUp(): void
{
$this->fileManager = \Mockery::spy(FileManager::class);
$this->maker = new MakeSeeder($this->fileManager);
$this->generator = new Generator($this->fileManager, 'App', class_exists(PhpCompatUtil::class) ? new PhpCompatUtil($this->fileManager) : null);

$phpCompatUtil = null;
if (class_exists(PhpCompatUtil::class) && method_exists(DependencyBuilder::class, 'isPhpVersionSatisfied')) {
// 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
$phpCompatUtil = new PhpCompatUtil($this->fileManager);
}
$this->generator = new Generator($this->fileManager, 'App', $phpCompatUtil);
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/Migrations/CreatorTest.php
Expand Up @@ -58,8 +58,6 @@ private function expectMigration(string $type, string $name)

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

Expand Down

0 comments on commit 4339e28

Please sign in to comment.