Skip to content

Commit

Permalink
Add artisan tools
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenmaguire committed Oct 22, 2015
1 parent 4cc5de9 commit c9910ba
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![Build Status](https://img.shields.io/travis/stevenmaguire/laravel-uuid-model/master.svg?style=flat-square)](https://travis-ci.org/stevenmaguire/laravel-uuid-model)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/stevenmaguire/laravel-uuid-model.svg?style=flat-square)](https://scrutinizer-ci.com/g/stevenmaguire/laravel-uuid-model/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/stevenmaguire/laravel-uuid-model.svg?style=flat-square)](https://scrutinizer-ci.com/g/stevenmaguire/laravel-uuid-model)
[![Total Downloads](https://img.shields.io/packagist/dt/stevenmaguire/laravel-uuid-model.svg?style=flat-square)](https://packagist.org/packages/league/laravel-uuid-model)
[![Total Downloads](https://img.shields.io/packagist/dt/stevenmaguire/laravel-uuid-model.svg?style=flat-square)](https://packagist.org/packages/stevenmaguire/laravel-uuid-model)

Create non-incrementing models whose primary key is a UUID.

Expand All @@ -19,7 +19,7 @@ $ composer require stevenmaguire/laravel-uuid-model

## Usage

Extend the `UuidModel`.
### Extend the `UuidModel`

```php
class User extends Stevenmaguire\Laravel\UuidModel
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"require-dev": {
"phpunit/phpunit": "~4.0",
"mockery/mockery": "~0.9",
"squizlabs/php_codesniffer": "~2.0"
"squizlabs/php_codesniffer": "~2.0",
"laravel/framework": "^5.0"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 16 additions & 0 deletions src/Console/ModelMakeCommand.php
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
}
}
10 changes: 10 additions & 0 deletions src/Console/stubs/model.stub
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
{
//
}
16 changes: 16 additions & 0 deletions src/Database/MigrationCreator.php
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
}
}
27 changes: 27 additions & 0 deletions src/Database/stubs/blank.stub
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()
{
//
}
}
31 changes: 31 additions & 0 deletions src/Database/stubs/create.stub
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');
}
}
31 changes: 31 additions & 0 deletions src/Database/stubs/update.stub
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) {
//
});
}
}
97 changes: 97 additions & 0 deletions src/Providers/UuidArtisanProvider.php
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);
}
}
54 changes: 54 additions & 0 deletions tests/src/UuidArtisanProviderTest.php
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');
}
}

0 comments on commit c9910ba

Please sign in to comment.