mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-09 21:54:27 +02:00
Addon::initAddon() should call bootstrap only once
This commit is contained in:
parent
b47fc318a5
commit
a85343dbed
2 changed files with 21 additions and 0 deletions
|
@ -20,6 +20,8 @@ final class AddonProxy implements Addon
|
|||
{
|
||||
private AddonBootstrap $bootstrap;
|
||||
|
||||
private bool $isInit = false;
|
||||
|
||||
public function __construct(AddonBootstrap $bootstrap)
|
||||
{
|
||||
$this->bootstrap = $bootstrap;
|
||||
|
@ -41,6 +43,12 @@ final class AddonProxy implements Addon
|
|||
|
||||
public function initAddon(array $dependencies): void
|
||||
{
|
||||
if ($this->isInit) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->isInit = true;
|
||||
|
||||
$event = new AddonStartEvent($dependencies);
|
||||
|
||||
$this->bootstrap->initAddon($event);
|
||||
|
|
|
@ -67,6 +67,19 @@ class AddonProxyTest extends TestCase
|
|||
$addon->initAddon([]);
|
||||
}
|
||||
|
||||
public function testInitAddonMultipleTimesWillCallBootstrapOnce(): void
|
||||
{
|
||||
$bootstrap = $this->createMock(AddonBootstrap::class);
|
||||
$bootstrap->expects($this->once())->method('initAddon')->willReturnCallback(function ($event) {
|
||||
$this->assertInstanceOf(AddonStartEvent::class, $event);
|
||||
});
|
||||
|
||||
$addon = new AddonProxy($bootstrap);
|
||||
|
||||
$addon->initAddon([]);
|
||||
$addon->initAddon([]);
|
||||
}
|
||||
|
||||
public function testInitAddonCallsBootstrapWithDependencies(): void
|
||||
{
|
||||
$bootstrap = $this->createMock(AddonBootstrap::class);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue