Skip to content

Commit 52372c7

Browse files
committed
Replace mockwebserver lib with custom implemention for Windows support
1 parent 2d58a22 commit 52372c7

File tree

3 files changed

+107
-56
lines changed

3 files changed

+107
-56
lines changed

tests/data/issue/236/base.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
openapi: 3.0.0
3+
info:
4+
title: Link Example
5+
version: 1.0.0
6+
components:
7+
schemas:
8+
Pet:
9+
$ref: definitions.yaml#/Pet
10+
Dog:
11+
$ref: ##ABSOLUTEPATH##/definitions.yaml#/Dog
12+
paths:
13+
'/pet':
14+
get:
15+
responses:
16+
200:
17+
description: return a pet
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
Pet:
3+
type: object
4+
properties:
5+
id:
6+
type: integer
7+
format: int64
8+
Dog:
9+
type: object
10+
properties:
11+
name:
12+
type: string

tests/spec/ReferenceTest.php

Lines changed: 78 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ class ReferenceTest extends \PHPUnit\Framework\TestCase
1919
/** @var MockWebServer */
2020
private $server;
2121

22-
protected function setUp(): void
23-
{
24-
$this->server = new MockWebServer();
25-
$this->server->stop();
26-
$this->server->start();
27-
28-
if (stripos(PHP_OS_FAMILY, 'Windows') !== false) {
29-
// echo "Running on Windows\n";
30-
exec('ssh-keyscan -H '.$this->server->getHost().' | Out-File -Append -Encoding ASCII $env:USERPROFILE\.ssh\known_hosts');
31-
}
32-
}
33-
34-
protected function tearDown(): void
35-
{
36-
$this->server->stop();
37-
}
22+
// protected function setUp(): void
23+
// {
24+
// $this->server = new MockWebServer();
25+
// $this->server->stop();
26+
// $this->server->start();
27+
//
28+
// if (stripos(PHP_OS_FAMILY, 'Windows') !== false) {
29+
//// echo "Running on Windows\n";
30+
// exec('ssh-keyscan -H '.$this->server->getHost().' | Out-File -Append -Encoding ASCII $env:USERPROFILE\.ssh\known_hosts');
31+
// }
32+
// }
33+
//
34+
// protected function tearDown(): void
35+
// {
36+
// $this->server->stop();
37+
// }
3838

3939
public function testResolveInDocument()
4040
{
@@ -255,49 +255,21 @@ public function testResolveFileInSubdirWithMultipleRelativePaths()
255255

256256
public function testResolveFileHttp()
257257
{
258-
$this->server->setResponseOfPath(
259-
'/cebe/php-openapi/290389bbd337cf4d70ecedfd3a3d886715e19552/tests/spec/data/reference/definitions.yaml',
260-
'
261-
Pet:
262-
type: object
263-
properties:
264-
id:
265-
type: integer
266-
format: int64
267-
Dog:
268-
type: object
269-
properties:
270-
name:
271-
type: string
272-
'
273-
);
258+
$this->handleMockServer();
259+
// return;
260+
261+
262+
263+
264+
274265

275-
$this->server->setResponseOfPath(
276-
'/cebe/php-openapi/290389bbd337cf4d70ecedfd3a3d886715e19552/tests/spec/data/reference/base.yaml',
277-
'
278-
openapi: 3.0.0
279-
info:
280-
title: Link Example
281-
version: 1.0.0
282-
components:
283-
schemas:
284-
Pet:
285-
$ref: definitions.yaml#/Pet
286-
Dog:
287-
$ref: ##ABSOLUTEPATH##/definitions.yaml#/Dog
288-
paths:
289-
\'/pet\':
290-
get:
291-
responses:
292-
200:
293-
description: return a pet
294-
'
295-
);
296266

297267
// $file = 'https://raw.githubusercontent.com/cebe/php-openapi/290389bbd337cf4d70ecedfd3a3d886715e19552/tests/spec/data/reference/base.yaml';
298268

299-
$host = $this->server->getHost() . ':' . $this->server->getPort();
300-
$path = '/cebe/php-openapi/290389bbd337cf4d70ecedfd3a3d886715e19552/tests/spec/data/reference/base.yaml';
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';
301273
$file = 'http://' . $host . $path;
302274
/** @var $openapi OpenApi */
303275
$openapi = Reader::readFromYaml(str_replace('##ABSOLUTEPATH##', dirname($file), file_get_contents($file)));
@@ -722,5 +694,55 @@ public function testResolveRelativePathAll()
722694
}
723695
}
724696

725-
}
697+
private function handleMockServer()
698+
{
699+
// $cmd = 'php -S localhost:8787';
700+
//// $cmd = 'pwd';
701+
// exec($cmd, $output);
702+
// $this->assertSame(0, $output);
703+
// return;
704+
705+
706+
// exec('cd tests/spec');
707+
// exec('pwd', $op);
708+
// $this->assertNull($op);
709+
// return;
710+
711+
712+
// file_put_contents(__DIR__.'/definitions.yaml', '
713+
//Pet:
714+
// type: object
715+
// properties:
716+
// id:
717+
// type: integer
718+
// format: int64
719+
//Dog:
720+
// type: object
721+
// properties:
722+
// name:
723+
// type: string
724+
//');
725+
//
726+
//
727+
//
728+
// file_put_contents(__DIR__.'/base.yaml', '
729+
//openapi: 3.0.0
730+
//info:
731+
// title: Link Example
732+
// version: 1.0.0
733+
//components:
734+
// schemas:
735+
// Pet:
736+
// $ref: definitions.yaml#/Pet
737+
// Dog:
738+
// $ref: ##ABSOLUTEPATH##/definitions.yaml#/Dog
739+
//paths:
740+
// \'/pet\':
741+
// get:
742+
// responses:
743+
// 200:
744+
// description: return a pet
745+
//');
726746

747+
}
748+
}

0 commit comments

Comments
 (0)