forceFill(['id' => 1, 'name' => 'admin']); /** @var LogEntry|MockObject $logEntry */ $logEntry = $this->getMockBuilder(LogEntry::class) ->addMethods(['create']) ->getMock(); $logEntry->expects($this->exactly(2)) ->method('create') ->withConsecutive( [['level' => LogLevel::INFO, 'message' => 'Some more informational foo']], [['level' => LogLevel::INFO, 'message' => 'admin (1): Some even more informational bar']] ); /** @var Authenticator|MockObject $auth */ $auth = $this->createMock(Authenticator::class); $auth->expects($this->exactly(2)) ->method('user') ->willReturnOnConsecutiveCalls( null, $user ); $logger = new UserAwareLogger($logEntry); $logger->setAuth($auth); $logger->log(LogLevel::INFO, 'Some more informational foo'); $logger->log(LogLevel::INFO, 'Some even more informational bar'); } }