mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-11 01:24:27 +02:00
Create Container interface, add DiceContainer as implementation
This commit is contained in:
parent
316fac0161
commit
320fe18654
9 changed files with 147 additions and 97 deletions
82
tests/Unit/Core/DiceContainerTest.php
Normal file
82
tests/Unit/Core/DiceContainerTest.php
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?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 Friendica\Core\DiceContainer;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
class DiceContainerTest extends TestCase
|
||||
{
|
||||
public function testFromBasePathReturnsContainer(): void
|
||||
{
|
||||
$root = vfsStream::setup('friendica', null, [
|
||||
'static' => [
|
||||
'dependencies.config.php' => '<?php return [];',
|
||||
],
|
||||
]);
|
||||
|
||||
$container = DiceContainer::fromBasePath($root->url());
|
||||
|
||||
$this->assertInstanceOf(Container::class, $container);
|
||||
}
|
||||
|
||||
public function testCreateReturnsObject(): void
|
||||
{
|
||||
$root = vfsStream::setup('friendica', null, [
|
||||
'static' => [
|
||||
'dependencies.config.php' => <<< PHP
|
||||
<?php return [
|
||||
\Psr\Log\LoggerInterface::class => [
|
||||
'instanceOf' => \Psr\Log\NullLogger::class,
|
||||
],
|
||||
];
|
||||
PHP,
|
||||
],
|
||||
]);
|
||||
|
||||
$container = DiceContainer::fromBasePath($root->url());
|
||||
|
||||
$this->assertInstanceOf(NullLogger::class, $container->create(LoggerInterface::class));
|
||||
}
|
||||
|
||||
public function testFromDiceReturnsContainer(): void
|
||||
{
|
||||
$dice = $this->createMock(Dice::class);
|
||||
$dice->expects($this->never())->method('create');
|
||||
|
||||
$container = DiceContainer::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 = DiceContainer::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 = DiceContainer::fromDice($dice);
|
||||
$container->addRule(LoggerInterface::class, ['constructParams' => ['console']]);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue