Page MenuHomeDevCentral

D453.diff
No OneTemporary

D453.diff

diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php
--- a/app/Providers/EventServiceProvider.php
+++ b/app/Providers/EventServiceProvider.php
@@ -1,32 +1,29 @@
-<?php namespace AuthGrove\Providers;
+<?php
+
+namespace AuthGrove\Providers;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
-class EventServiceProvider extends ServiceProvider {
-
- /**
- * The event handler mappings for the application.
- *
- * @var array
- */
- protected $listen = [
- 'event.name' => [
- 'EventListener',
- ],
- ];
+use Config;
- /**
- * Register any other events for your application.
- *
- * @param \Illuminate\Contracts\Events\Dispatcher $events
- * @return void
- */
- public function boot(DispatcherContract $events)
- {
- parent::boot($events);
+class EventServiceProvider extends ServiceProvider {
- //
- }
+ /**
+ * Registers all our listeners as subscriber classes.
+ */
+ private function subscribeListeners () {
+ $this->subscribe += Config::get('app.listeners');
+ }
+ /**
+ * Registers any other events for your application.
+ *
+ * @param \Illuminate\Contracts\Events\Dispatcher $events
+ * @return void
+ */
+ public function boot(DispatcherContract $events) {
+ $this->subscribeListeners();
+ parent::boot($events);
+ }
}
diff --git a/config/app.php b/config/app.php
--- a/config/app.php
+++ b/config/app.php
@@ -184,6 +184,19 @@
],
+ /*
+ |--------------------------------------------------------------------------
+ | Events listeners
+ |--------------------------------------------------------------------------
+ |
+ | The events listeners listed here will be automatically loaded on the
+ | request to your application.
+ |
+ */
+
+ 'listeners' => [
+ ],
+
/*
|--------------------------------------------------------------------------
| Class Aliases
diff --git a/tests/Providers/EventServiceProviderTest.php b/tests/Providers/EventServiceProviderTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Providers/EventServiceProviderTest.php
@@ -0,0 +1,36 @@
+<?php
+
+use Nasqueron\Notifications\Providers\EventServiceProvider;
+
+class EventServiceProviderTest extends TestCase {
+
+ public function testType () {
+ $this->assertServiceInstanceOf(
+ 'Illuminate\Contracts\Events\Dispatcher',
+ 'events'
+ );
+ }
+
+ ///
+ /// Tests specific to this service provider
+ ///
+
+ public function testOmittedFiles () {
+ $subscribe = [];
+
+ $namespace = $this->app->getInstance()->getNamespace() . 'Listeners\\';
+ $files = File::allFiles(app_path('Listeners'));
+ foreach ($files as $file) {
+ $class = $namespace . $file->getBasename('.php');
+ $subscribe[] = $class;
+ }
+
+ $this->assertEquals(
+ $subscribe, Config::get('app.listeners'),
+ 'The files in the app/Listeners folder and the array of classes ' .
+ 'defined in config/app.php at listeners key diverge.',
+ 0.0, 10, true // delta, maxDepth, canonicalize
+ );
+ }
+
+}
diff --git a/tests/TestCase.php b/tests/TestCase.php
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -22,4 +22,20 @@
return $app;
}
+
+ ///
+ /// Service providers
+ ///
+
+ /**
+ * Asserts a service in the application container is from the expected type.
+ *
+ * @param $expectedType The type to check
+ * @param $serviceName The service name to use as application container key
+ */
+ public function assertServiceInstanceOf ($expectedType, $serviceName) {
+ $service = $this->app->make($serviceName);
+ $this->assertInstanceOf($expectedType, $service);
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Mon, Oct 7, 21:30 (20 h, 5 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2181081
Default Alt Text
D453.diff (3 KB)

Event Timeline