From b3bc5981ea73e990b25b3aeffd3ffd1f0dffbe0b Mon Sep 17 00:00:00 2001 From: Art4 Date: Thu, 2 Jan 2025 08:43:45 +0000 Subject: [PATCH] Create Addon class, that calls Addon Bootstrap --- src/Addon/Addon.php | 32 ++++++++++++++++++++ src/Addon/AddonBootstrap.php | 2 +- tests/Unit/Addon/AddonTest.php | 38 ++++++++++++++++++++++++ tests/Util/helloaddon/src/HelloAddon.php | 5 ++-- 4 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 src/Addon/Addon.php create mode 100644 tests/Unit/Addon/AddonTest.php diff --git a/src/Addon/Addon.php b/src/Addon/Addon.php new file mode 100644 index 0000000000..84aabd5bd7 --- /dev/null +++ b/src/Addon/Addon.php @@ -0,0 +1,32 @@ +bootstrap = $bootstrap; + } + + public function initAddon(): void + { + $event = new AddonStartEvent(); + + $this->bootstrap->initAddon($event); + } +} diff --git a/src/Addon/AddonBootstrap.php b/src/Addon/AddonBootstrap.php index 2dbde05173..f889d4e218 100644 --- a/src/Addon/AddonBootstrap.php +++ b/src/Addon/AddonBootstrap.php @@ -25,5 +25,5 @@ interface AddonBootstrap extends StaticEventSubscriber /** * Init of the addon. */ - public static function initAddon(AddonStartEvent $event): void; + public function initAddon(AddonStartEvent $event): void; } diff --git a/tests/Unit/Addon/AddonTest.php b/tests/Unit/Addon/AddonTest.php new file mode 100644 index 0000000000..0086c2bbe4 --- /dev/null +++ b/tests/Unit/Addon/AddonTest.php @@ -0,0 +1,38 @@ +createMock(AddonBootstrap::class); + + $addon = new Addon($bootstrap); + + $this->assertInstanceOf(Addon::class, $addon); + } + + public function testInitAddonCallsBootstrap(): void + { + $bootstrap = $this->createMock(AddonBootstrap::class); + $bootstrap->expects($this->once())->method('initAddon')->willReturnCallback(function($event) { + $this->assertInstanceOf(AddonStartEvent::class, $event); + }); + + $addon = new Addon($bootstrap); + $addon->initAddon(); + } +} diff --git a/tests/Util/helloaddon/src/HelloAddon.php b/tests/Util/helloaddon/src/HelloAddon.php index ef82b698c2..ef2b77aa3c 100644 --- a/tests/Util/helloaddon/src/HelloAddon.php +++ b/tests/Util/helloaddon/src/HelloAddon.php @@ -15,6 +15,7 @@ declare(strict_types=1); namespace FriendicaAddons\HelloAddon; +use Friendica\Addon\AddonBootstrap; use Friendica\Addon\Event\AddonInstallEvent; use Friendica\Addon\Event\AddonStartEvent; use Friendica\Addon\Event\AddonUninstallEvent; @@ -23,7 +24,7 @@ use Friendica\Event\ProvideLoggerEvent; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; -class HelloAddon implements \Friendica\Addon\AddonBootstrap +class HelloAddon implements AddonBootstrap { /** @var LoggerInterface */ private static $logger; @@ -50,7 +51,7 @@ class HelloAddon implements \Friendica\Addon\AddonBootstrap ]; } - public static function initAddon(AddonStartEvent $event): void + public function initAddon(AddonStartEvent $event): void { // $dependencies containts an array of services defined in getRequiredDependencies(). // The keys are the FQCN of the services.