Skip to content

Commit

Permalink
Added support for Laravel 7
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed Jun 15, 2020
1 parent f0fc978 commit 10ea743
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 81 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ matrix:
- php: 7.4
env: SYMFONY_REQUIRE="4.*"

- php: 7.4
env: SYMFONY_REQUIRE="5.*"

allow_failures:
- php: nightly

Expand Down
6 changes: 2 additions & 4 deletions Resources/config/migrations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

<parameters>
<parameter key="wouterj_eloquent.migrations.table">migrations</parameter>
<parameter key="wouterj_eloquent.migration_path">%kernel.root_dir%/migrations</parameter>
<parameter key="wouterj_eloquent.app_seeder_path">%kernel.project_dir%/src</parameter>
<parameter key="wouterj_eloquent.project_path">%kernel.project_dir%</parameter>
<parameter key="wouterj_eloquent.migration_path">%kernel.project_dir%/migrations</parameter>
</parameters>

<services>
Expand Down Expand Up @@ -95,7 +93,7 @@
</service>

<service id="wouterj_eloquent.commands.seed_make" class="WouterJ\EloquentBundle\Command\SeederMakeCommand">
<argument>%wouterj_eloquent.project_path%</argument>
<argument>%kernel.project_dir%/src</argument>
<argument>%kernel.bundles%</argument>

<tag name="console.command" command="eloquent:make:seeder"/>
Expand Down
2 changes: 1 addition & 1 deletion Resources/docs/migrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Generating Migrations
$ php bin/console eloquent:migrate:make create_flights_table
This will generate a migration file in ``app/migrations``.
This will generate a migration file in ``src/migrations``.

By specifying the ``--create`` and ``-table`` options, the generator
will also generate some bootstrap code for you. The ``--table`` option
Expand Down
41 changes: 20 additions & 21 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,40 @@

, "require": {
"php": "^7.2"
, "illuminate/database": "^6.18"
, "illuminate/events": "^6.18"
, "illuminate/console": "^6.18"
, "symfony/dependency-injection": "^4.4"
, "illuminate/database": "^6.18 || ^7.15"
, "illuminate/events": "^6.18 || ^7.15"
, "illuminate/console": "^6.18 || ^7.15"
, "symfony/dependency-injection": "^4.4 || ^5.0"
, "jdorn/sql-formatter": "^1.2"
}
, "require-dev": {
"symfony/console": "^4.4"
, "symfony/event-dispatcher": "^4.4"
, "symfony/framework-bundle": "^4.4"
, "symfony/http-kernel": "^4.4"
, "symfony/finder": "^4.4"
, "symfony/debug": "^4.4"
, "symfony/yaml": "^4.4"
, "symfony/form": "^4.4"
, "symfony/phpunit-bridge": "^4.4"
, "symfony/browser-kit": "^4.4"
, "symfony/dom-crawler": "^4.4"
, "symfony/validator": "^4.4"
, "symfony/twig-bundle": "^4.4"
, "symfony/twig-bridge": "^4.4"
, "symfony/var-dumper": "^4.4"
"symfony/console": "^4.4 || ^5.0"
, "symfony/event-dispatcher": "^4.4 || ^5.0"
, "symfony/framework-bundle": "^4.4 || ^5.0"
, "symfony/http-kernel": "^4.4 || ^5.0"
, "symfony/finder": "^4.4 || ^5.0"
, "symfony/debug": "^4.4 || ^5.0"
, "symfony/yaml": "^4.4 || ^5.0"
, "symfony/form": "^4.4 || ^5.0"
, "symfony/phpunit-bridge": "^4.4 || ^5.0"
, "symfony/browser-kit": "^4.4 || ^5.0"
, "symfony/dom-crawler": "^4.4 || ^5.0"
, "symfony/validator": "^4.4 || ^5.0"
, "symfony/twig-bundle": "^4.4 || ^5.0"
, "symfony/twig-bridge": "^4.4 || ^5.0"
, "symfony/var-dumper": "^4.4 || ^5.0"
, "twig/twig": "^1.26 || ^2.0"
, "doctrine/annotations": "1.*"
}
, "conflict": { "hhvm": "*" }
, "suggests": {
"symfony/event-dispatcher": "To auto initialize the Eloquent ORM. (^4.4)"
"symfony/event-dispatcher": "To auto initialize the Eloquent ORM. (^4.4|^5.0)"
}

, "autoload": { "psr-4": { "WouterJ\\EloquentBundle\\": "src" } }
, "autoload-dev": {
"psr-4": { "WouterJ\\EloquentBundle\\": "tests", "": "tests/Functional/app/src" }
, "classmap": ["tests/Functional/app/migrations", "tests/Functional/app/TestKernel.php"]
, "files": ["tests/phpunit6.php"]
}
, "extra": {
"branch-alias": { "dev-master": "1.2-dev" }
Expand Down
5 changes: 3 additions & 2 deletions src/Command/ConfirmationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;

/**
* @method mixed getHelper(string $name)
*/
trait ConfirmationTrait
{
private $kernelEnv;
Expand All @@ -19,6 +22,4 @@ protected function askConfirmationInProd(InputInterface $i, OutputInterface $o):
return $this->getHelper('question')
->ask($i, $o, new ConfirmationQuestion('Are you sure you want to execute the migrations in production?', false));
}

abstract public function getHelper(/*string */$name);
}
2 changes: 1 addition & 1 deletion src/Command/SeederMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private function buildClass($name): string
$class = $lastPos ? substr($name, $lastPos + 1) : $name;

$stub = file_get_contents($this->stubPath.'/seeder.stub');
$stub = str_replace('DummyClass', $class, $stub);
$stub = str_replace(['DummyClass', '{{ class }}', '{{class}}'], $class, $stub);
$stub = str_replace(IlluminateSeeder::class, Seeder::class, $stub);

if ($namespace) {
Expand Down
2 changes: 1 addition & 1 deletion src/DataCollector/EloquentDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(Manager $capsule, QueryListener $queryListener)
$this->symfonyVersion = floatval(\Symfony\Component\HttpKernel\Kernel::VERSION);
}

public function collect(Request $request, Response $response, \Exception $exception = null)
public function collect(Request $request, Response $response, ?\Throwable $exception = null)
{
$connections = array_map(function ($config) {
return ($this->symfonyVersion < 3.2) ? $this->varToString($config) : $this->cloneVar($config);
Expand Down

This file was deleted.

16 changes: 13 additions & 3 deletions src/Migrations/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,21 @@ public function create($name, $path, $table = null, $create = false)
/** {@inheritdoc} */
protected function getStub($table, $create)
{
$file = 'blank.stub';
if (null !== $table) {
$file = $create ? 'create.stub' : 'update.stub';
$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';
}
}

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

$stubContents = file_get_contents($this->stubPath().'/'.$file);
$stubContents = str_replace('Illuminate\Support\Facades', 'WouterJ\EloquentBundle\Facade', $stubContents);

Expand Down
2 changes: 0 additions & 2 deletions src/WouterJEloquentBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Symfony\Component\HttpKernel\Bundle\Bundle;
use WouterJ\EloquentBundle\DependencyInjection\Compiler\AddCasterPass;
use WouterJ\EloquentBundle\DependencyInjection\Compiler\ObserverPass;
use WouterJ\EloquentBundle\DependencyInjection\Compiler\SymfonyBackwardsCompatibilityPass;
use Doctrine\Common\Annotations\AnnotationReader;

/**
Expand All @@ -35,7 +34,6 @@ public function build(ContainerBuilder $container)
parent::build($container);

$container->addCompilerPass(new ObserverPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION, 80);
$container->addCompilerPass(new SymfonyBackwardsCompatibilityPass());
$container->addCompilerPass(new AddCasterPass());
}

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/Fixtures/migrations/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CreateMigration extends Migration
public function up()
{
Schema::create('SomeTable', function (Blueprint $table) {
$table->increments('id');
$table->id();
$table->timestamps();
});
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/app/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public function registerContainerConfiguration(LoaderInterface $loader)
'connections' => [
'default' => [
'driver' => 'sqlite',
'database' => '%kernel.root_dir%/test.sqlite',
'database' => '%kernel.project_dir%/test.sqlite',
],
'conn2' => [
'driver' => 'sqlite',
'database' => '%kernel.root_dir%/test1.sqlite'
'database' => '%kernel.project_dir%/test1.sqlite'
],
],
'aliases' => true,
Expand Down
5 changes: 3 additions & 2 deletions tests/Migrations/CreatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ private function assertMigrationEquals($name, $actual)

switch ($name) {
case 'create':
if (method_exists(Blueprint::class, 'integerIncrements')) {
$name .= '-5.8';
$eloquent7 = file_exists($this->subject->stubPath().'/migration.stub');
if (!$eloquent7) {
$name .= '-6';
}

$expected = $normalize(file_get_contents(__DIR__.'/../Fixtures/migrations/'.$name.'.php'));
Expand Down
9 changes: 0 additions & 9 deletions tests/phpunit6.php

This file was deleted.

0 comments on commit 10ea743

Please sign in to comment.