1313
1414namespace CodeIgniter \Publisher ;
1515
16+ use CodeIgniter \HTTP \CURLRequest ;
17+ use CodeIgniter \HTTP \ResponseInterface ;
1618use CodeIgniter \Test \CIUnitTestCase ;
19+ use Config \Services ;
1720use PHPUnit \Framework \Attributes \Group ;
1821
1922/**
@@ -136,16 +139,37 @@ public function testAddPathsRecursive(): void
136139
137140 public function testAddUri (): void
138141 {
142+ $ mockCurl = $ this ->getMockBuilder (CURLRequest::class)
143+ ->disableOriginalConstructor ()
144+ ->onlyMethods (['get ' ])
145+ ->getMock ();
146+ $ mockResponse = $ this ->createStub (ResponseInterface::class);
147+
148+ $ mockResponse ->method ('getBody ' )->willReturn ('' );
149+ $ mockCurl ->method ('get ' )->willReturn ($ mockResponse );
150+ Services::injectMock ('curlrequest ' , $ mockCurl );
151+
139152 $ publisher = new Publisher ();
140153 $ publisher ->addUri ('https://raw.githubusercontent.com/codeigniter4/CodeIgniter4/develop/composer.json ' );
141154
142155 $ scratch = $ this ->getPrivateProperty ($ publisher , 'scratch ' );
143156
144157 $ this ->assertSame ([$ scratch . 'composer.json ' ], $ publisher ->get ());
158+ Services::resetSingle ('curlrequest ' );
145159 }
146160
147161 public function testAddUris (): void
148162 {
163+ $ mockCurl = $ this ->getMockBuilder (CURLRequest::class)
164+ ->disableOriginalConstructor ()
165+ ->onlyMethods (['get ' ])
166+ ->getMock ();
167+ $ mockResponse = $ this ->createStub (ResponseInterface::class);
168+
169+ $ mockResponse ->method ('getBody ' )->willReturn ('' );
170+ $ mockCurl ->method ('get ' )->willReturn ($ mockResponse );
171+ Services::injectMock ('curlrequest ' , $ mockCurl );
172+
149173 $ publisher = new Publisher ();
150174 $ publisher ->addUris ([
151175 'https://raw.githubusercontent.com/codeigniter4/CodeIgniter4/develop/LICENSE ' ,
@@ -155,5 +179,6 @@ public function testAddUris(): void
155179 $ scratch = $ this ->getPrivateProperty ($ publisher , 'scratch ' );
156180
157181 $ this ->assertSame ([$ scratch . 'LICENSE ' , $ scratch . 'composer.json ' ], $ publisher ->get ());
182+ Services::resetSingle ('curlrequest ' );
158183 }
159184}
0 commit comments