]> git.mxchange.org Git - friendica.git/commitdiff
Add UnitTest for Container
authorPhilipp <admin@philipp.info>
Sun, 5 Jan 2025 21:48:24 +0000 (22:48 +0100)
committerPhilipp <admin@philipp.info>
Sun, 5 Jan 2025 22:13:44 +0000 (23:13 +0100)
src/Console/AbstractConsole.php
src/Core/Container.php
tests/Unit/AppTest.php
tests/Unit/Core/ContainerTest.php [new file with mode: 0644]

index 9c4a53bdaf769e669e80d8d4a74c0013504026d6..bce4a462681de8f5384bb405c6787120a1113ffe 100644 (file)
@@ -5,6 +5,8 @@
 //
 // SPDX-License-Identifier: AGPL-3.0-or-later
 
+declare(strict_types = 1);
+
 namespace Friendica\Console;
 
 use Asika\SimpleConsole\Console;
index 64a05150c0ace31785e12ecb514c9ac991a40471..c77a2a127ec552612bade775fc39ba62c2c850e7 100644 (file)
@@ -5,6 +5,8 @@
 //
 // SPDX-License-Identifier: AGPL-3.0-or-later
 
+declare(strict_types = 1);
+
 namespace Friendica\Core;
 
 use Dice\Dice;
index 937e2a867a81d176da66671a12dfd7a3c042bc6c..1854c993e4b15f18ff851db55c869054c624a712 100644 (file)
@@ -15,7 +15,7 @@ use PHPUnit\Framework\TestCase;
 
 class AppTest extends TestCase
 {
-       public function testFromDiceReturnsApp(): void
+       public function testFromContainerReturnsApp(): void
        {
                $container = $this->createMock(Container::class);
                $container->expects($this->never())->method('create');
diff --git a/tests/Unit/Core/ContainerTest.php b/tests/Unit/Core/ContainerTest.php
new file mode 100644 (file)
index 0000000..6111a72
--- /dev/null
@@ -0,0 +1,48 @@
+<?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 Core;
+
+use Dice\Dice;
+use Friendica\Core\Container;
+use PHPUnit\Framework\TestCase;
+use Psr\Log\LoggerInterface;
+use Psr\Log\NullLogger;
+
+class ContainerTest extends TestCase
+{
+       public function testFromDiceReturnsContainer(): void
+       {
+               $dice = $this->createMock(Dice::class);
+               $dice->expects($this->never())->method('create');
+
+               $container = Container::fromDice($dice);
+
+               $this->assertInstanceOf(Container::class, $container);
+       }
+
+       public function testCreateFromContainer(): void
+       {
+               $dice = $this->createMock(Dice::class);
+               $dice->expects($this->once())->method('create')->with(LoggerInterface::class)->willReturn(new NullLogger());
+
+               $container = Container::fromDice($dice);
+
+               $this->assertInstanceOf(NullLogger::class, $container->create(LoggerInterface::class));
+       }
+
+       public function testAddRuleFromContainer(): void
+       {
+               $dice = $this->createMock(Dice::class);
+               $dice->expects($this->once())->method('addRule')->with(LoggerInterface::class, ['constructParams' => ['console']])->willReturn($dice);
+
+               $container = Container::fromDice($dice);
+               $container->addRule(LoggerInterface::class, ['constructParams' => ['console']]);
+       }
+}