28use PHPUnit\Framework\MockObject\MockObject;
30use Psr\Http\Message\ResponseInterface;
31use Psr\Http\Message\ServerRequestInterface;
43#[\PHPUnit\Framework\Attributes\BackupGlobals(false)]
44#[\PHPUnit\Framework\Attributes\BackupStaticProperties(false)]
45#[\PHPUnit\Framework\Attributes\PreserveGlobalState(false)]
46#[\PHPUnit\Framework\Attributes\RunClassInSeparateProcess]
72 protected function setUp(): void
75 $this->mockRequestFactory = $this->getMockBuilder(RequestFactory::class)->getMock();
77 $this->mockResponseFactory = $this->getMockBuilder(ResponseFactory::class)->getMock();
79 $this->mockSenderStrategy = $this->getMockBuilder(ResponseSenderStrategy::class)->getMock();
81 $this->mockCookieJarFactory = $this->getMockBuilder(CookieJarFactory::class)->getMock();
83 $this->mockDurationFactory = $this->createMock(DurationFactory::class);
85 $this->httpState =
new RawHTTPServices($this->mockSenderStrategy, $this->mockCookieJarFactory, $this->mockRequestFactory, $this->mockResponseFactory, $this->mockDurationFactory, $this->createMock(CookieFactory::class), $this->createMock(MessageFactory::class));
89 #[\PHPUnit\Framework\Attributes\Test]
92 $expectedRequest = $this->getMockBuilder(ServerRequestInterface::class)->getMock();
93 $wrongRequest = $this->getMockBuilder(ServerRequestInterface::class)->getMock();
95 $this->mockRequestFactory->expects($this->once())
97 ->willReturn($expectedRequest, $wrongRequest);
102 $request1 = $this->httpState->request();
105 $request2 = $this->httpState->request();
108 $this->assertEquals($expectedRequest, $request1);
109 $this->assertEquals($expectedRequest, $request2);
113 #[\PHPUnit\Framework\Attributes\Test]
116 $expectedResponse = $this->getMockBuilder(ResponseInterface::class)->getMock();
117 $wrongResponse = $this->getMockBuilder(ResponseInterface::class)->getMock();
119 $this->mockResponseFactory->expects($this->once())
121 ->willReturn($expectedResponse, $wrongResponse);
126 $response1 = $this->httpState->response();
129 $response2 = $this->httpState->response();
132 $this->assertEquals($expectedResponse, $response1);
133 $this->assertEquals($expectedResponse, $response2);
GlobalHttpState $httpState
RequestFactory $mockRequestFactory
ResponseSenderStrategy $mockSenderStrategy
testResponseWhichShouldGenerateANewResponseOnce()
ResponseFactory $mockResponseFactory
DurationFactory $mockDurationFactory
testRequestWhichShouldGenerateANewRequestOnce()
CookieJarFactory $mockCookieJarFactory
Provides an interface to the ILIAS HTTP services.
Interface GlobalHttpState.
Creates psr-7 messages without binding components to the underlying library.
Interface ResponseSenderStrategy.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...