container = $this->prophesize(ContainerInterface::class); $this->delegator = new LoggerAwareDelegatorFactory(); } /** * @test * @dataProvider provideInstances */ public function injectsLoggerOnInstanceWhenImplementingLoggerAware($instance, int $expectedCalls): void { $callback = function () use ($instance) { return $instance; }; $getLogger = $this->container->get(Log\LoggerInterface::class)->willReturn(new Log\NullLogger()); $result = ($this->delegator)($this->container->reveal(), '', $callback); $this->assertSame($instance, $result); $getLogger->shouldHaveBeenCalledTimes($expectedCalls); } public function provideInstances(): iterable { yield 'no logger aware' => [new stdClass(), 0]; yield 'logger aware' => [new class implements Log\LoggerAwareInterface { public function setLogger(LoggerInterface $logger): void { Assert::assertInstanceOf(Log\NullLogger::class, $logger); } }, 1]; } }