Tweak service container
This commit is contained in:
parent
625cc08b81
commit
17c267ea55
|
|
@ -9,7 +9,8 @@ class PluginServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
$this->app->singleton('plugins', PluginManager::class);
|
$this->app->singleton(PluginManager::class);
|
||||||
|
$this->app->alias(PluginManager::class, 'plugins');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(PluginManager $plugins)
|
public function boot(PluginManager $plugins)
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,9 @@ class PluginManagerTest extends TestCase
|
||||||
$mock->shouldReceive('get')->with('plugins_enabled', '[]')->andReturn('[]');
|
$mock->shouldReceive('get')->with('plugins_enabled', '[]')->andReturn('[]');
|
||||||
});
|
});
|
||||||
$this->mock(Filesystem::class, function ($mock) {
|
$this->mock(Filesystem::class, function ($mock) {
|
||||||
$mock->shouldReceive('directories')->times(1);
|
$mock->shouldReceive('directories')->times(0);
|
||||||
});
|
});
|
||||||
app('plugins')->boot();
|
resolve(PluginManager::class)->boot();
|
||||||
app('plugins')->boot();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNotLoadDisabled()
|
public function testNotLoadDisabled()
|
||||||
|
|
@ -41,7 +40,8 @@ class PluginManagerTest extends TestCase
|
||||||
$dir = config('plugins.directory');
|
$dir = config('plugins.directory');
|
||||||
config(['plugins.directory' => storage_path('mocks')]);
|
config(['plugins.directory' => storage_path('mocks')]);
|
||||||
|
|
||||||
$manager = $this->rebootPluginManager(app('plugins'));
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
resolve(PluginManager::class)->boot();
|
||||||
$this->assertFalse(class_exists('Fake\Faker'));
|
$this->assertFalse(class_exists('Fake\Faker'));
|
||||||
|
|
||||||
config(['plugins.directory' => $dir]);
|
config(['plugins.directory' => $dir]);
|
||||||
|
|
@ -75,7 +75,8 @@ class PluginManagerTest extends TestCase
|
||||||
$mock->shouldNotReceive('getRequire');
|
$mock->shouldNotReceive('getRequire');
|
||||||
});
|
});
|
||||||
|
|
||||||
$manager = $this->rebootPluginManager(app('plugins'));
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
resolve(PluginManager::class)->boot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReportDuplicatedPlugins()
|
public function testReportDuplicatedPlugins()
|
||||||
|
|
@ -120,7 +121,8 @@ class PluginManagerTest extends TestCase
|
||||||
'dir1' => '/nano',
|
'dir1' => '/nano',
|
||||||
'dir2' => '/yuko',
|
'dir2' => '/yuko',
|
||||||
]));
|
]));
|
||||||
$manager = $this->rebootPluginManager(app('plugins'));
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
resolve(PluginManager::class)->boot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDetectVersionChanged()
|
public function testDetectVersionChanged()
|
||||||
|
|
@ -160,7 +162,8 @@ class PluginManagerTest extends TestCase
|
||||||
->andReturn(false);
|
->andReturn(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
$manager = $this->rebootPluginManager(app('plugins'));
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
resolve(PluginManager::class)->boot();
|
||||||
Event::assertDispatched(\App\Events\PluginVersionChanged::class, function ($event) {
|
Event::assertDispatched(\App\Events\PluginVersionChanged::class, function ($event) {
|
||||||
$this->assertEquals('0.1.0', $event->plugin->version);
|
$this->assertEquals('0.1.0', $event->plugin->version);
|
||||||
|
|
||||||
|
|
@ -209,7 +212,8 @@ class PluginManagerTest extends TestCase
|
||||||
->andReturn(false);
|
->andReturn(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
$manager = $this->rebootPluginManager(app('plugins'));
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
resolve(PluginManager::class)->boot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadViewsAndTranslations()
|
public function testLoadViewsAndTranslations()
|
||||||
|
|
@ -259,7 +263,8 @@ class PluginManagerTest extends TestCase
|
||||||
->once();
|
->once();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
$manager = $this->rebootPluginManager(app('plugins'));
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
resolve(PluginManager::class)->boot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoadBootstrapper()
|
public function testLoadBootstrapper()
|
||||||
|
|
@ -306,7 +311,8 @@ class PluginManagerTest extends TestCase
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$manager = $this->rebootPluginManager(app('plugins'));
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
resolve(PluginManager::class)->boot();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLifecycleHooks()
|
public function testLifecycleHooks()
|
||||||
|
|
@ -350,7 +356,8 @@ class PluginManagerTest extends TestCase
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
$manager = $this->rebootPluginManager(app('plugins'));
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
resolve(PluginManager::class)->boot();
|
||||||
event(new \App\Events\PluginWasDeleted(new Plugin('/mayaka', ['name' => 'mayaka'])));
|
event(new \App\Events\PluginWasDeleted(new Plugin('/mayaka', ['name' => 'mayaka'])));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -365,7 +372,8 @@ class PluginManagerTest extends TestCase
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertFalse(class_exists('Fake\Faker'));
|
$this->assertFalse(class_exists('Fake\Faker'));
|
||||||
$manager = $this->rebootPluginManager(app('plugins'));
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
resolve(PluginManager::class)->boot();
|
||||||
$this->assertTrue(class_exists('Fake\FakeServiceProvider'));
|
$this->assertTrue(class_exists('Fake\FakeServiceProvider'));
|
||||||
|
|
||||||
config(['plugins.directory' => $dir]);
|
config(['plugins.directory' => $dir]);
|
||||||
|
|
@ -383,7 +391,8 @@ class PluginManagerTest extends TestCase
|
||||||
->andReturn(json_encode([['name' => 'fake', 'version' => '0.0.0']]));
|
->andReturn(json_encode([['name' => 'fake', 'version' => '0.0.0']]));
|
||||||
});
|
});
|
||||||
|
|
||||||
$manager = $this->rebootPluginManager(app('plugins'));
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
resolve(PluginManager::class)->boot();
|
||||||
Event::assertDispatched('provider.loaded');
|
Event::assertDispatched('provider.loaded');
|
||||||
|
|
||||||
config(['plugins.directory' => $dir]);
|
config(['plugins.directory' => $dir]);
|
||||||
|
|
@ -391,7 +400,7 @@ class PluginManagerTest extends TestCase
|
||||||
|
|
||||||
public function testGetUnsatisfied()
|
public function testGetUnsatisfied()
|
||||||
{
|
{
|
||||||
$manager = app('plugins');
|
$manager = resolve(PluginManager::class);
|
||||||
|
|
||||||
$plugin = new Plugin('', ['require' => ['blessing-skin-server' => '^0.0.0']]);
|
$plugin = new Plugin('', ['require' => ['blessing-skin-server' => '^0.0.0']]);
|
||||||
$info = $manager->getUnsatisfied($plugin)->get('blessing-skin-server');
|
$info = $manager->getUnsatisfied($plugin)->get('blessing-skin-server');
|
||||||
|
|
@ -444,7 +453,8 @@ class PluginManagerTest extends TestCase
|
||||||
{
|
{
|
||||||
Event::fake();
|
Event::fake();
|
||||||
|
|
||||||
$manager = app('plugins');
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
$manager = resolve(PluginManager::class);
|
||||||
$reflection = new ReflectionClass($manager);
|
$reflection = new ReflectionClass($manager);
|
||||||
$property = $reflection->getProperty('plugins');
|
$property = $reflection->getProperty('plugins');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
|
|
@ -474,7 +484,8 @@ class PluginManagerTest extends TestCase
|
||||||
{
|
{
|
||||||
Event::fake();
|
Event::fake();
|
||||||
|
|
||||||
$manager = app('plugins');
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
$manager = resolve(PluginManager::class);
|
||||||
$reflection = new ReflectionClass($manager);
|
$reflection = new ReflectionClass($manager);
|
||||||
$property = $reflection->getProperty('plugins');
|
$property = $reflection->getProperty('plugins');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
|
|
@ -507,7 +518,8 @@ class PluginManagerTest extends TestCase
|
||||||
$mock->shouldReceive('deleteDirectory')->with('/fake')->once();
|
$mock->shouldReceive('deleteDirectory')->with('/fake')->once();
|
||||||
});
|
});
|
||||||
|
|
||||||
$manager = app('plugins');
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
$manager = resolve(PluginManager::class);
|
||||||
$reflection = new ReflectionClass($manager);
|
$reflection = new ReflectionClass($manager);
|
||||||
$property = $reflection->getProperty('plugins');
|
$property = $reflection->getProperty('plugins');
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
|
|
@ -593,7 +605,8 @@ class PluginManagerTest extends TestCase
|
||||||
->once()
|
->once()
|
||||||
->andReturn(false);
|
->andReturn(false);
|
||||||
});
|
});
|
||||||
app('plugins')->all();
|
app()->forgetInstance(PluginManager::class);
|
||||||
|
resolve(PluginManager::class)->all();
|
||||||
|
|
||||||
config(['plugins.directory' => $old]);
|
config(['plugins.directory' => $old]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user