mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-12 11:04:33 +02:00
Let Addon class provide dependencies into addon
This commit is contained in:
parent
b3bc5981ea
commit
f2a26fde4e
3 changed files with 33 additions and 3 deletions
|
@ -18,14 +18,17 @@ final class Addon
|
||||||
{
|
{
|
||||||
private AddonBootstrap $bootstrap;
|
private AddonBootstrap $bootstrap;
|
||||||
|
|
||||||
public function __construct(AddonBootstrap $bootstrap)
|
private array $dependencies;
|
||||||
|
|
||||||
|
public function __construct(AddonBootstrap $bootstrap, array $dependencies = [])
|
||||||
{
|
{
|
||||||
$this->bootstrap = $bootstrap;
|
$this->bootstrap = $bootstrap;
|
||||||
|
$this->dependencies = $dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initAddon(): void
|
public function initAddon(): void
|
||||||
{
|
{
|
||||||
$event = new AddonStartEvent();
|
$event = new AddonStartEvent($this->dependencies);
|
||||||
|
|
||||||
$this->bootstrap->initAddon($event);
|
$this->bootstrap->initAddon($event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,8 +14,15 @@ namespace Friendica\Addon\Event;
|
||||||
*/
|
*/
|
||||||
final class AddonStartEvent
|
final class AddonStartEvent
|
||||||
{
|
{
|
||||||
|
private array $dependencies;
|
||||||
|
|
||||||
|
public function __construct(array $dependencies)
|
||||||
|
{
|
||||||
|
$this->dependencies = $dependencies;
|
||||||
|
}
|
||||||
|
|
||||||
public function getDependencies(): array
|
public function getDependencies(): array
|
||||||
{
|
{
|
||||||
return [];
|
return $this->dependencies;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ use Friendica\Addon\Addon;
|
||||||
use Friendica\Addon\AddonBootstrap;
|
use Friendica\Addon\AddonBootstrap;
|
||||||
use Friendica\Addon\Event\AddonStartEvent;
|
use Friendica\Addon\Event\AddonStartEvent;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
class AddonTest extends TestCase
|
class AddonTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -35,4 +36,23 @@ class AddonTest extends TestCase
|
||||||
$addon = new Addon($bootstrap);
|
$addon = new Addon($bootstrap);
|
||||||
$addon->initAddon();
|
$addon->initAddon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testInitAddonCallsBootstrapWithDependencies(): void
|
||||||
|
{
|
||||||
|
$bootstrap = $this->createMock(AddonBootstrap::class);
|
||||||
|
|
||||||
|
$bootstrap->expects($this->once())->method('initAddon')->willReturnCallback(function(AddonStartEvent $event) {
|
||||||
|
$dependencies = $event->getDependencies();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey(LoggerInterface::class, $dependencies);
|
||||||
|
$this->assertInstanceOf(LoggerInterface::class, $dependencies[LoggerInterface::class]);
|
||||||
|
});
|
||||||
|
|
||||||
|
$addon = new Addon(
|
||||||
|
$bootstrap,
|
||||||
|
[LoggerInterface::class => $this->createMock(LoggerInterface::class)]
|
||||||
|
);
|
||||||
|
|
||||||
|
$addon->initAddon();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue