Add UnitTest for Container

This commit is contained in:
Philipp 2025-01-05 22:48:24 +01:00
parent 2238ea8d52
commit 560bf345da
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
4 changed files with 53 additions and 1 deletions

View file

@ -5,6 +5,8 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types = 1);
namespace Friendica\Console;
use Asika\SimpleConsole\Console;

View file

@ -5,6 +5,8 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
declare(strict_types = 1);
namespace Friendica\Core;
use Dice\Dice;

View 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');

View file

@ -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']]);
}
}