Skip to content

Commit

Permalink
Support events.
Browse files Browse the repository at this point in the history
  • Loading branch information
jumilla committed Jan 12, 2017
1 parent a22e9e3 commit e465806
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -14,11 +14,11 @@
"require": {
"laravel/framework": "5.3.*",
"jumilla/laravel-versionia": "^1.3.2",
"jumilla/laravel-addomnipot": "^1.6",
"jumilla/laravel-addomnipot": "^1.7.1",
"jumilla/laravel-source-generator": "^1.2"
},
"require-dev": {
"phpunit/phpunit": "~4.0",
"phpunit/phpunit": "^5.0",
"mockery/mockery": "~0.9"
},
"autoload": {
Expand Down
9 changes: 9 additions & 0 deletions sources/ServiceProvider.php
Expand Up @@ -8,6 +8,9 @@
use Jumilla\Addomnipot\Laravel\Generator as AddonGenerator;
use Jumilla\Addomnipot\Laravel\AliasResolver;
use Jumilla\Addomnipot\Laravel\Repository;
use Jumilla\Addomnipot\Laravel\Events\AddonWorldCreated;
use Jumilla\Addomnipot\Laravel\Events\AddonRegistered;
use Jumilla\Addomnipot\Laravel\Events\AddonBooted;
use LaravelPlus\Extension\Templates\BladeExtension;
use Jumilla\Versionia\Laravel\Migrator;

Expand Down Expand Up @@ -89,7 +92,11 @@ public function register()

$this->setupPackageCommands(static::$commands);

$app['event']->fire(new AddonWorldCreated($this->addonEnvironment));

$this->registerAddons($this->addonEnvironment->addons());

$app['event']->fire(new AddonRegistered($this->addonEnvironment));
}

/**
Expand Down Expand Up @@ -140,6 +147,8 @@ public function boot()

// setup all addons
$this->bootAddons();

$this->app['event']->fire(new AddonBooted($this->addonEnvironment));
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/ServiceProviderTests.php
@@ -1,6 +1,7 @@
<?php

use LaravelPlus\Extension\ServiceProvider;
use Jumilla\Addomnipot\Laravel\Events;
use Illuminate\Support\Facades\Blade;

class ServiceProviderTests extends TestCase
Expand All @@ -13,8 +14,25 @@ public function test_withNoParameter()

$app['config']->set('app.aliases', []);

$created = 0;
$registered = 0;
$booted = 0;
$app['event']->listen(Events\AddonWorldCreated::class, function ($env) use (&$created) {
++$created;
});
$app['event']->listen(Events\AddonWorldCreated::class, function ($env) use (&$registered) {
++$registered;
});
$app['event']->listen(Events\AddonWorldCreated::class, function ($env) use (&$booted) {
++$booted;
});

$command = new ServiceProvider($app);
$command->register();
$command->boot();

Assert::same(1, $created);
Assert::same(1, $registered);
Assert::same(1, $booted);
}
}
3 changes: 1 addition & 2 deletions tests/Specs/SpecsInputModelTests.php
Expand Up @@ -58,8 +58,7 @@ public function test_failsMethod()
$spec->shouldReceive('rules')->andReturn(['qux' => 'required'])->once();
$spec->shouldReceive('ruleMessages')->andReturn([])->once();
$spec->shouldReceive('labels')->andReturn([])->once();
$translator->shouldReceive('trans')->andReturn('failed');
$translator->shouldReceive('get')->andReturn('failed')->once();
$translator->shouldReceive('trans')->andReturn('failed')->times(2);

$inputModel = new InputModel($spec, ['qux' => '']);

Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase.php
Expand Up @@ -3,6 +3,7 @@
use Illuminate\Container\Container;
use Illuminate\Config\Repository as Config;
use Illuminate\Database\DatabaseManager;
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Filesystem\FilesystemManager;
use Jumilla\Addomnipot\Laravel\Generator as AddonGenerator;
Expand Down Expand Up @@ -46,6 +47,7 @@ protected function createApplication()

$this->app[Illuminate\Contracts\Foundation\Application::class] = $this->app;
$this->app['config'] = new Config([]);
$this->app['event'] = new Dispatcher($this->app);
$this->app['files'] = new Filesystem();
$this->app['filesystem'] = new FilesystemManager($this->app);

Expand Down

0 comments on commit e465806

Please sign in to comment.