Let Addon class provide dependencies into addon

This commit is contained in:
Art4 2025-01-02 09:03:17 +00:00
parent b3bc5981ea
commit f2a26fde4e
3 changed files with 33 additions and 3 deletions

View file

@ -13,6 +13,7 @@ use Friendica\Addon\Addon;
use Friendica\Addon\AddonBootstrap;
use Friendica\Addon\Event\AddonStartEvent;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
class AddonTest extends TestCase
{
@ -35,4 +36,23 @@ class AddonTest extends TestCase
$addon = new Addon($bootstrap);
$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();
}
}