ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ILIAS\DI\HTTPServicesTest Class Reference
+ Inheritance diagram for ILIAS\DI\HTTPServicesTest:
+ Collaboration diagram for ILIAS\DI\HTTPServicesTest:

Public Member Functions

 testRequestWhichShouldGenerateANewRequestOnce ()
 
 testResponseWhichShouldGenerateANewResponseOnce ()
 

Protected Member Functions

 setUp ()
 

Private Attributes

 $mockRequestFactory
 
 $mockResponseFactory
 
 $mockCookieJarFactory
 
 $mockSenderStrategy
 
 $httpState
 

Detailed Description

Definition at line 30 of file HTTPServicesTest.php.

Member Function Documentation

◆ setUp()

ILIAS\DI\HTTPServicesTest::setUp ( )
protected

Definition at line 55 of file HTTPServicesTest.php.

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  }

◆ testRequestWhichShouldGenerateANewRequestOnce()

ILIAS\DI\HTTPServicesTest::testRequestWhichShouldGenerateANewRequestOnce ( )

Definition at line 71 of file HTTPServicesTest.php.

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  }

◆ testResponseWhichShouldGenerateANewResponseOnce()

ILIAS\DI\HTTPServicesTest::testResponseWhichShouldGenerateANewResponseOnce ( )

Definition at line 95 of file HTTPServicesTest.php.

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  }

Field Documentation

◆ $httpState

GlobalHttpState ILIAS\DI\HTTPServicesTest::$httpState
private

Definition at line 52 of file HTTPServicesTest.php.

◆ $mockCookieJarFactory

CookieJarFactory MockInterface ILIAS\DI\HTTPServicesTest::$mockCookieJarFactory
private

Definition at line 44 of file HTTPServicesTest.php.

◆ $mockRequestFactory

RequestFactory MockInterface ILIAS\DI\HTTPServicesTest::$mockRequestFactory
private

Definition at line 36 of file HTTPServicesTest.php.

◆ $mockResponseFactory

ResponseFactory MockInterface ILIAS\DI\HTTPServicesTest::$mockResponseFactory
private

Definition at line 40 of file HTTPServicesTest.php.

◆ $mockSenderStrategy

ResponseSenderStrategy MockInterface ILIAS\DI\HTTPServicesTest::$mockSenderStrategy
private

Definition at line 48 of file HTTPServicesTest.php.


The documentation for this class was generated from the following file: