ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
HTTPServicesTest.php
Go to the documentation of this file.
1 <?php
8 namespace ILIAS\DI;
9 
19 
30 class HTTPServicesTest extends MockeryTestCase
31 {
32 
52  private $httpState;
53 
54 
55  protected function setUp()
56  {
57  parent::setUp();
58  $this->mockRequestFactory = \Mockery::mock(RequestFactory::class);
59  $this->mockResponseFactory = \Mockery::mock(ResponseFactory::class);
60  $this->mockSenderStrategy = \Mockery::mock(ResponseSenderStrategy::class);
61  $this->mockCookieJarFactory = \Mockery::mock(CookieJarFactory::class);
62 
63  //setup http state
64  $this->httpState = new HTTPServices($this->mockSenderStrategy, $this->mockCookieJarFactory, $this->mockRequestFactory, $this->mockResponseFactory);
65  }
66 
67 
72  {
73  $expectedRequest = \Mockery::mock(RequestInterface::class);
74  $wrongRequest = \Mockery::mock(RequestInterface::class);
75 
76  $this->mockRequestFactory->shouldReceive("create")->withNoArgs()->once()->andReturnValues([ $expectedRequest, $wrongRequest ]);
77 
78  //test method
79 
80  //this call should call the expectedRequest factory
81  $request1 = $this->httpState->request();
82 
83  //this call should not call the factory
84  $request2 = $this->httpState->request();
85 
86  //make sure that all requests are the same.
87  $this->assertEquals($expectedRequest, $request1);
88  $this->assertEquals($expectedRequest, $request2);
89  }
90 
91 
96  {
97  $expectedResponse = \Mockery::mock(ResponseInterface::class);
98  $wrongResponse = \Mockery::mock(ResponseInterface::class);
99 
100  $this->mockResponseFactory->shouldReceive("create")->withNoArgs()->once()->andReturnValues([ $expectedResponse, $wrongResponse ]);
101 
102  //test method
103 
104  //this call should call the expectedResponse factory
105  $response1 = $this->httpState->response();
106 
107  //this call should not call the factory
108  $response2 = $this->httpState->response();
109 
110  //make sure that all requests are the same.
111  $this->assertEquals($expectedResponse, $response1);
112  $this->assertEquals($expectedResponse, $response2);
113  }
114 }
Class HTTPServicesTest.
Provides an interface to the ILIAS HTTP services.