]> git.mxchange.org Git - friendica.git/commitdiff
Add missing files
authorArt4 <art4@wlabs.de>
Tue, 28 Jan 2025 07:14:01 +0000 (07:14 +0000)
committerHypolite Petovan <hypolite@mrpetovan.com>
Tue, 4 Feb 2025 18:22:53 +0000 (13:22 -0500)
src/Event/ConfigLoadedEvent.php [new file with mode: 0644]
tests/Unit/Event/ConfigLoadedEventTest.php [new file with mode: 0644]

diff --git a/src/Event/ConfigLoadedEvent.php b/src/Event/ConfigLoadedEvent.php
new file mode 100644 (file)
index 0000000..8923c53
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+// Copyright (C) 2010-2024, the Friendica project
+// SPDX-FileCopyrightText: 2010-2024 the Friendica project
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+declare(strict_types=1);
+
+namespace Friendica\Event;
+
+use Friendica\Core\Config\Util\ConfigFileManager;
+
+/**
+ * Notify that the config was loaded
+ *
+ * @internal
+ */
+final class ConfigLoadedEvent implements NamedEvent
+{
+       public const CONFIG_LOADED = 'friendica.config_loaded';
+
+       private string $name;
+
+       private ConfigFileManager $config;
+
+       public function __construct(string $name, ConfigFileManager $config)
+       {
+               $this->name   = $name;
+               $this->config = $config;
+       }
+
+       public function getName(): string
+       {
+               return $this->name;
+       }
+
+       public function getConfig(): ConfigFileManager
+       {
+               return $this->config;
+       }
+}
diff --git a/tests/Unit/Event/ConfigLoadedEventTest.php b/tests/Unit/Event/ConfigLoadedEventTest.php
new file mode 100644 (file)
index 0000000..473b75a
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+
+// Copyright (C) 2010-2024, the Friendica project
+// SPDX-FileCopyrightText: 2010-2024 the Friendica project
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+declare(strict_types=1);
+
+namespace Friendica\Test\Unit\Event;
+
+use Friendica\Core\Config\Util\ConfigFileManager;
+use Friendica\Event\ConfigLoadedEvent;
+use Friendica\Event\NamedEvent;
+use PHPUnit\Framework\TestCase;
+
+class ConfigLoadedEventTest extends TestCase
+{
+       public function testImplementationOfInstances(): void
+       {
+               $event = new ConfigLoadedEvent('test', $this->createStub(ConfigFileManager::class));
+
+               $this->assertInstanceOf(NamedEvent::class, $event);
+       }
+
+       public static function getPublicConstants(): array
+       {
+               return [
+                       [ConfigLoadedEvent::CONFIG_LOADED, 'friendica.config_loaded'],
+               ];
+       }
+
+       /**
+        * @dataProvider getPublicConstants
+        */
+       public function testPublicConstantsAreAvailable($value, $expected): void
+       {
+               $this->assertSame($expected, $value);
+       }
+
+       public function testGetNameReturnsName(): void
+       {
+               $event = new ConfigLoadedEvent('test', $this->createStub(ConfigFileManager::class));
+
+               $this->assertSame('test', $event->getName());
+       }
+
+       public function testGetConfigReturnsCorrectString(): void
+       {
+               $config = $this->createStub(ConfigFileManager::class);
+
+               $event = new ConfigLoadedEvent('test', $config);
+
+               $this->assertSame($config, $event->getConfig());
+       }
+}