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

Support for Laravel 5.6 #279

Merged
merged 6 commits into from Mar 13, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
@@ -1,7 +1,6 @@
language: php

php:
- 7.0
- 7.1

services:
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Expand Up @@ -16,12 +16,12 @@
}
],
"require": {
"php": ">=7.0.0",
"illuminate/support": "5.5.*",
"illuminate/database": "5.5.*",
"illuminate/pagination": "5.5.*",
"illuminate/events": "5.5.*",
"illuminate/console": "5.5.*",
"php": ">=7.1.3",
"illuminate/support": "5.6.*",
"illuminate/database": "5.6.*",
"illuminate/pagination": "5.6.*",
"illuminate/events": "5.6.*",
"illuminate/console": "5.6.*",
"heydavid713/neo4jphp": "0.1.*",
"nesbot/carbon": "~1.0"
},
Expand Down
113 changes: 113 additions & 0 deletions src/Console/Migrations/MigrateStatusCommand.php
@@ -0,0 +1,113 @@
<?php

namespace Vinelab\NeoEloquent\Console\Migrations;

use Illuminate\Support\Collection;
use Illuminate\Database\Migrations\Migrator;
use Symfony\Component\Console\Input\InputOption;

class MigrateStatusCommand extends BaseCommand
{
/**
* The console command name.
*
* @var string
*/
protected $name = 'neo4j:migrate:status';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Show the status of each migration';

/**
* The migrator instance.
*
* @var \Illuminate\Database\Migrations\Migrator
*/
protected $migrator;

/**
* Create a new migration rollback command instance.
*
* @param \Illuminate\Database\Migrations\Migrator $migrator
* @return void
*/
public function __construct(Migrator $migrator)
{
parent::__construct();

$this->migrator = $migrator;
}

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
$this->migrator->setConnection($this->option('database'));

if (! $this->migrator->repositoryExists()) {
return $this->error('No migrations found.');
}

$ran = $this->migrator->getRepository()->getRan();

$batches = $this->migrator->getRepository()->getMigrationBatches();

if (count($migrations = $this->getStatusFor($ran, $batches)) > 0) {
$this->table(['Ran?', 'Migration', 'Batch'], $migrations);
} else {
$this->error('No migrations found');
}
}

/**
* Get the status for the given ran migrations.
*
* @param array $ran
* @param array $batches
* @return \Illuminate\Support\Collection
*/
protected function getStatusFor(array $ran, array $batches)
{
return Collection::make($this->getAllMigrationFiles())
->map(function ($migration) use ($ran, $batches) {
$migrationName = $this->migrator->getMigrationName($migration);

return in_array($migrationName, $ran)
? ['<info>Y</info>', $migrationName, $batches[$migrationName]]
: ['<fg=red>N</fg=red>', $migrationName];
});
}

/**
* Get an array of all of the migration files.
*
* @return array
*/
protected function getAllMigrationFiles()
{
return $this->migrator->getMigrationFiles($this->getMigrationPaths());
}

/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return [
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'],

['path', null, InputOption::VALUE_OPTIONAL, 'The path to the migrations files to use.'],

['realpath', null, InputOption::VALUE_NONE, 'Indicate any provided migration file paths are pre-resolved absolute paths.'],
];
}
}
5 changes: 3 additions & 2 deletions src/Eloquent/Model.php
Expand Up @@ -81,7 +81,7 @@ protected function newBaseQueryBuilder()
*
* @return string
*/
protected function getDateFormat()
public function getDateFormat()
{
return 'Y-m-d H:i:s';
}
Expand Down Expand Up @@ -445,9 +445,10 @@ public function morphedByOne($related, $type, $key = null, $relation = null)
* @param string $name
* @param string $type
* @param string $id
* @param string $ownerKey
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function morphTo($name = null, $type = null, $id = null)
public function morphTo($name = null, $type = null, $id = null, $ownerKey = null)
{

// When the name and the type are specified we'll return a MorphedByOne
Expand Down
21 changes: 19 additions & 2 deletions src/MigrationServiceProvider.php
Expand Up @@ -2,6 +2,7 @@

use Illuminate\Support\ServiceProvider;
use Illuminate\Database\Migrations\Migrator;
use Vinelab\NeoEloquent\Console\Migrations\MigrateStatusCommand;
use Vinelab\NeoEloquent\Migrations\MigrationModel;
use Vinelab\NeoEloquent\Migrations\MigrationCreator;
use Vinelab\NeoEloquent\Console\Migrations\MigrateCommand;
Expand Down Expand Up @@ -95,7 +96,8 @@ protected function registerCommands()
'MigrateRollback',
'MigrateReset',
'MigrateRefresh',
'MigrateMake'
'MigrateMake',
'MigrateStatus'
);

// We'll simply spin through the list of commands that are migration related
Expand All @@ -114,7 +116,8 @@ protected function registerCommands()
'command.neoeloquent.migrate.make',
'command.neoeloquent.migrate.rollback',
'command.neoeloquent.migrate.reset',
'command.neoeloquent.migrate.refresh'
'command.neoeloquent.migrate.refresh',
'command.neoeloquent.migrate.status'
);
}

Expand Down Expand Up @@ -197,6 +200,19 @@ protected function registerMigrateMakeCommand()
});
}

/**
* Register the "refresh" migration command.
*
* @return void
*/
protected function registerMigrateStatusCommand()
{
$this->app->singleton('command.neoeloquent.migrate.status', function($app)
{
return new MigrateStatusCommand($app['neoeloquent.migrator']);
});
}

/**
* {@inheritDoc}
*/
Expand All @@ -211,6 +227,7 @@ public function provides()
'command.neoeloquent.migrate.refresh',
'migration.neoeloquent.creator',
'command.neoeloquent.migrate.make',
'command.neoeloquent.migrate.status',
);
}

Expand Down
13 changes: 13 additions & 0 deletions src/Migrations/DatabaseMigrationRepository.php
Expand Up @@ -218,4 +218,17 @@ public function getMigrations($steps)
return $results;
}

/**
* Get the completed migrations with their batch numbers.
*
* @return array
*/
public function getMigrationBatches()
{
return $this->model
->orderBy('batch', 'asc')
->orderBy('migration', 'asc')
->get()
->pluck('batch', 'migration')->all();
}
}
11 changes: 6 additions & 5 deletions src/Query/Builder.php
Expand Up @@ -61,12 +61,13 @@ class Builder extends IlluminateQueryBuilder {
* @var array
*/
public $operators = array(
'+', '-', '*', '/', '%', '^', // Mathematical
'=', '<>', '<', '>', '<=', '>=', // Comparison
'+', '-', '*', '/', '%', '^', // Mathematical
'=', '<>', '<', '>', '<=', '>=', // Comparison
'is null', 'is not null',
'and', 'or', 'xor', 'not', // Boolean
'in', '[x]', '[x .. y]', // Collection
'=~' // Regular Expression
'and', 'or', 'xor', 'not', // Boolean
'in', '[x]', '[x .. y]', // Collection
'=~', // Regular Expression
'starts with', 'ends with', 'contains' // String matching
);

/**
Expand Down
13 changes: 9 additions & 4 deletions tests/functional/QueryingRelationsTest.php
Expand Up @@ -617,16 +617,21 @@ public function testSavingCreateWithRelationWithDateTimeAndCarbonInstances()
['colleagues' => ['name' => 'Protectron', 'dob' => $dt]
]);

$format = $user->getDateFormat();

$houwe = User::first();
$colleague = $houwe->colleagues()->first();

$this->assertEquals($yesterday->format(User::getDateFormat()), $houwe->dob);
$this->assertEquals($dt->format(User::getDateFormat()), $colleague->dob);
$this->assertEquals($yesterday->format($format), $houwe->dob);
$this->assertEquals($dt->format($format), $colleague->dob);
}

public function testSavingRelationWithDateTimeAndCarbonInstances()
{
$user = User::create(['name' => 'Andrew Hale']);

$format = $user->getDateFormat();

$yesterday = Carbon::now()->subDay();
$brother = new User(['name' => 'Simon Hale', 'dob' => $yesterday]);

Expand All @@ -639,8 +644,8 @@ public function testSavingRelationWithDateTimeAndCarbonInstances()
$andrew = User::where('name', 'Andrew Hale')->first();

$colleagues = $andrew->colleagues()->orderBy('dob', 'DESC')->get();
$this->assertEquals($dt->format(User::getDateFormat()), $colleagues[0]->dob);
$this->assertEquals($yesterday->format(User::getDateFormat()), $colleagues[1]->dob);
$this->assertEquals($dt->format($format), $colleagues[0]->dob);
$this->assertEquals($yesterday->format($format), $colleagues[1]->dob);
}

public function testCreateWithReturnsRelatedModelsAsRelations()
Expand Down
10 changes: 5 additions & 5 deletions tests/functional/SimpleCRUDTest.php
Expand Up @@ -361,11 +361,11 @@ public function testSavningDateTimeAndCarbonInstances()
$dt = new DateTime();
$w = Wiz::create(['fiz' => $now, 'biz' => $dt]);

$format = Wiz::getDateFormat();
$format = $w->getDateFormat();

$fetched = Wiz::first();
$this->assertEquals($now->format(Wiz::getDateFormat()), $fetched->fiz);
$this->assertEquals($now->format(Wiz::getDateFormat()), $fetched->biz);
$this->assertEquals($now->format($format), $fetched->fiz);
$this->assertEquals($now->format($format), $fetched->biz);

$tomorrow = Carbon::now()->addDay();
$after = Carbon::now()->addDays(2);
Expand All @@ -375,8 +375,8 @@ public function testSavningDateTimeAndCarbonInstances()
$fetched->save();

$updated = Wiz::first();
$this->assertEquals($tomorrow->format(Wiz::getDateFormat()), $updated->fiz);
$this->assertEquals($after->format(Wiz::getDateFormat()), $updated->biz);
$this->assertEquals($tomorrow->format($format), $updated->fiz);
$this->assertEquals($after->format($format), $updated->biz);
}

}