1717class ReferenceTest extends \PHPUnit \Framework \TestCase
1818{
1919 /** @var MockWebServer */
20- private $ server ;
20+ protected static $ server ;
21+
22+
23+ public static function setUpBeforeClass (): void
24+ {
25+ self ::$ server = new MockWebServer ;
26+ self ::$ server ->start ();
2127
22- // protected function setUp(): void
23- // {
2428// $this->server = new MockWebServer();
2529// $this->server->stop();
2630// $this->server->start();
2731//
2832// if (stripos(PHP_OS_FAMILY, 'Windows') !== false) {
2933//// echo "Running on Windows\n";
30- // exec('ssh-keyscan -H '.$this->server->getHost().' | Out-File -Append -Encoding ASCII $env:USERPROFILE\.ssh\known_hosts');
34+ //// exec('ssh-keyscan -H '.$this->server->getHost().' | Out-File -Append -Encoding ASCII $env:USERPROFILE\.ssh\known_hosts');
3135// }
32- // }
33- //
34- // protected function tearDown (): void
35- // {
36+ }
37+
38+ public static function tearDownAfterClass (): void
39+ {
3640// $this->server->stop();
37- // }
41+ self ::$ server ->stop ();
42+
43+ }
3844
3945 public function testResolveInDocument ()
4046 {
@@ -255,7 +261,8 @@ public function testResolveFileInSubdirWithMultipleRelativePaths()
255261
256262 public function testResolveFileHttp ()
257263 {
258- $ this ->handleMockServer ();
264+ $ this ->registerPaths ();
265+ // $this->handleMockServer();
259266// return;
260267
261268
@@ -266,10 +273,10 @@ public function testResolveFileHttp()
266273
267274 // $file = 'https://raw.githubusercontent.com/cebe/php-openapi/290389bbd337cf4d70ecedfd3a3d886715e19552/tests/spec/data/reference/base.yaml';
268275
269- // $host = $this-> server->getHost() . ':' . $this-> server->getPort();
270- $ host = 'localhost:8787 ' ;
271- // $path = '/cebe/php-openapi/290389bbd337cf4d70ecedfd3a3d886715e19552/tests/spec/data/reference/base.yaml';
272- $ path = '/tests/data/issue/236/base.yaml ' ;
276+ $ host = static :: $ server ->getHost () . ': ' . static :: $ server ->getPort ();
277+ // $host = 'localhost:8787';
278+ $ path = '/cebe/php-openapi/290389bbd337cf4d70ecedfd3a3d886715e19552/tests/spec/data/reference/base.yaml ' ;
279+ // $path = '/tests/data/issue/236/base.yaml';
273280 $ file = 'http:// ' . $ host . $ path ;
274281 /** @var $openapi OpenApi */
275282 $ openapi = Reader::readFromYaml (str_replace ('##ABSOLUTEPATH## ' , dirname ($ file ), file_get_contents ($ file )));
@@ -745,4 +752,47 @@ private function handleMockServer()
745752//');
746753
747754 }
755+
756+ private function registerPaths ()
757+ {
758+ static ::$ server ->setResponseOfPath (
759+ '/cebe/php-openapi/290389bbd337cf4d70ecedfd3a3d886715e19552/tests/spec/data/reference/definitions.yaml ' ,
760+ '
761+ Pet:
762+ type: object
763+ properties:
764+ id:
765+ type: integer
766+ format: int64
767+ Dog:
768+ type: object
769+ properties:
770+ name:
771+ type: string
772+ '
773+ );
774+
775+ static ::$ server ->setResponseOfPath (
776+ '/cebe/php-openapi/290389bbd337cf4d70ecedfd3a3d886715e19552/tests/spec/data/reference/base.yaml ' ,
777+ '
778+ openapi: 3.0.0
779+ info:
780+ title: Link Example
781+ version: 1.0.0
782+ components:
783+ schemas:
784+ Pet:
785+ $ref: definitions.yaml#/Pet
786+ Dog:
787+ $ref: ##ABSOLUTEPATH##/definitions.yaml#/Dog
788+ paths:
789+ \'/pet \':
790+ get:
791+ responses:
792+ 200:
793+ description: return a pet
794+ '
795+ );
796+
797+ }
748798}
0 commit comments