-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cc5de9
commit c9910ba
Showing
10 changed files
with
286 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php namespace Stevenmaguire\Laravel\Console; | ||
|
||
use Illuminate\Foundation\Console\ModelMakeCommand as BaseModelMakeCommand; | ||
|
||
class ModelMakeCommand extends BaseModelMakeCommand | ||
{ | ||
/** | ||
* Get the stub file for the generator. | ||
* | ||
* @return string | ||
*/ | ||
protected function getStub() | ||
{ | ||
return __DIR__.'/stubs/model.stub'; // @codeCoverageIgnore | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
use Stevenmaguire\Laravel\UuidModel as Model; | ||
|
||
class DummyClass extends Model | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php namespace Stevenmaguire\Laravel\Database; | ||
|
||
use Illuminate\Database\Migrations\MigrationCreator as BaseMigrationCreator; | ||
|
||
class MigrationCreator extends BaseMigrationCreator | ||
{ | ||
/** | ||
* Get the path to the stubs. | ||
* | ||
* @return string | ||
*/ | ||
public function getStubPath() | ||
{ | ||
return __DIR__.'/stubs'; // @codeCoverageIgnore | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class DummyClass extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class DummyClass extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('DummyTable', function (Blueprint $table) { | ||
$table->string('id'); | ||
$table->timestamps(); | ||
$table->primary('id'); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::drop('DummyTable'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class DummyClass extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('DummyTable', function (Blueprint $table) { | ||
// | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::table('DummyTable', function (Blueprint $table) { | ||
// | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
<?php namespace Stevenmaguire\Laravel\Providers; | ||
|
||
use Illuminate\Database\Console\Migrations\MigrateMakeCommand; | ||
use Illuminate\Support\ServiceProvider; | ||
use Stevenmaguire\Laravel\Console\ModelMakeCommand; | ||
use Stevenmaguire\Laravel\Database\MigrationCreator; | ||
|
||
class UuidArtisanProvider extends ServiceProvider | ||
{ | ||
/** | ||
* Indicates if loading of the provider is deferred. | ||
* | ||
* @var bool | ||
*/ | ||
protected $defer = true; | ||
|
||
/** | ||
* The commands to be registered. | ||
* | ||
* @var array | ||
*/ | ||
protected $commands = [ | ||
'MigrationMake' => 'command.migrate.make', | ||
'ModelMake' => 'command.model.make', | ||
]; | ||
|
||
/** | ||
* Register the service provider. | ||
* | ||
* @return void | ||
*/ | ||
public function register() | ||
{ | ||
foreach (array_keys($this->commands) as $command) { | ||
$method = "register{$command}Command"; | ||
|
||
call_user_func_array([$this, $method], []); | ||
} | ||
|
||
$this->commands(array_values($this->commands)); | ||
} | ||
|
||
/** | ||
* Register the "make" migration command. | ||
* | ||
* @return void | ||
*/ | ||
protected function registerMigrationMakeCommand() | ||
{ | ||
$this->registerCreator(); | ||
|
||
$this->app->singleton('command.migrate.make', function ($app) { | ||
// Once we have the migration creator registered, we will create the command | ||
// and inject the creator. The creator is responsible for the actual file | ||
// creation of the migrations, and may be extended by these developers. | ||
$creator = $app['migration.creator']; | ||
|
||
$composer = $app['composer']; | ||
|
||
return new MigrateMakeCommand($creator, $composer); | ||
}); | ||
} | ||
|
||
/** | ||
* Register the command. | ||
* | ||
* @return void | ||
*/ | ||
protected function registerModelMakeCommand() | ||
{ | ||
$this->app->singleton('command.model.make', function ($app) { | ||
return new ModelMakeCommand($app['files']); | ||
}); | ||
} | ||
|
||
/** | ||
* Register the migration creator. | ||
* | ||
* @return void | ||
*/ | ||
protected function registerCreator() | ||
{ | ||
$this->app->singleton('migration.creator', function ($app) { | ||
return new MigrationCreator($app['files']); | ||
}); | ||
} | ||
|
||
/** | ||
* Get the services provided by the provider. | ||
* | ||
* @return array | ||
*/ | ||
public function provides() | ||
{ | ||
return array_values($this->commands); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php namespace Stevenmaguire\Laravel\Test; | ||
|
||
use Mockery as m; | ||
use Illuminate\Config\Repository; | ||
use Illuminate\Events\Dispatcher; | ||
use Illuminate\Filesystem\Filesystem; | ||
use Illuminate\Foundation\Application; | ||
use Illuminate\Foundation\Bootstrap\ConfigureLogging; | ||
use Illuminate\Foundation\Bootstrap\LoadConfiguration; | ||
use Illuminate\Foundation\Bootstrap\RegisterFacades; | ||
use Illuminate\Foundation\Composer; | ||
use Illuminate\Foundation\Console\Kernel; | ||
use Stevenmaguire\Laravel\Providers\UuidArtisanProvider; | ||
|
||
class UuidArtisanProviderTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testServiceProvidersAreCorrectlyRegistered() | ||
{ | ||
$app = m::mock(Application::class)->makePartial(); | ||
$provider = new UuidArtisanProvider($app); | ||
$class = get_class($provider); | ||
$composer = m::mock(Composer::class); | ||
$events = m::mock(Dispatcher::class); | ||
$events->shouldReceive('listen'); | ||
$events->shouldReceive('fire'); | ||
$files = m::mock(Filesystem::class); | ||
$configService = m::mock(LoadConfiguration::class); | ||
$configService->shouldReceive('bootstrap')->with($app); | ||
$configuration = m::mock(Repository::class); | ||
$configuration->shouldReceive('offsetGet'); | ||
$configuration->shouldReceive('get'); | ||
$logService = m::mock(LoadConfiguration::class); | ||
$logService->shouldReceive('bootstrap')->with($app); | ||
$facadeService = m::mock(RegisterFacades::class); | ||
$facadeService->shouldReceive('bootstrap')->with($app); | ||
$app->singleton(ConfigureLogging::class, function () use ($logService) { return $logService; }); | ||
$app->singleton(LoadConfiguration::class, function () use ($configService) { return $configService; }); | ||
$app->singleton(RegisterFacades::class, function () use ($facadeService) { return $facadeService; }); | ||
$app->singleton('composer', function () use ($composer) { return $composer; }); | ||
$app->singleton('config', function () use ($configuration) { return $configuration; }); | ||
$app->singleton('events', function () use ($events) { return $events; }); | ||
$app->singleton('files', function () use ($files) { return $files; }); | ||
$app->register($provider); | ||
$this->assertTrue(in_array($class, $app->getLoadedProviders())); | ||
$this->assertTrue(is_array($provider->provides())); | ||
|
||
$migrationMakeCommand = $app->make('command.migrate.make'); | ||
$modelMakeCommand = $app->make('command.model.make'); | ||
|
||
//$artisan = m::mock(Kernel::class, [$app, $events])->makePartial(); | ||
//$artisan->call('make:migration'); | ||
//$artisan->call('make:model'); | ||
} | ||
} |