$dice = (new Dice())->addRules(require($path));
- return static::fromDice($dice);
+ return new self($dice);
}
private Dice $container;
$this->container = $container;
}
- /**
- * Creates an instance with Dice
- *
- * @param Dice $container
- *
- * @return self
- */
- public static function fromDice(Dice $container): self
- {
- return new self($container);
- }
-
/**
* Initialize the container with the given parameters
*
$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']]);
- }
}