createMock(Authenticator::class); /** @var Request|MockObject $request */ $request = $this->createMock(Request::class); $user = User::factory()->make(); $auth->expects($this->exactly(2)) ->method('user') ->willReturnOnConsecutiveCalls( null, $user ); $extension = new Globals($auth, $request); $globals = $extension->getGlobals(); $this->assertGlobalsExists('user', [], $globals); $this->assertGlobalsExists('request', $request, $globals); $globals = $extension->getGlobals(); $this->assertGlobalsExists('user', $user, $globals); } }