-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathphpunit.php
More file actions
34 lines (26 loc) · 1000 Bytes
/
phpunit.php
File metadata and controls
34 lines (26 loc) · 1000 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
use donatj\MockWebServer\MockWebServer;
use donatj\MockWebServer\Response;
class ExampleTest extends PHPUnit\Framework\TestCase {
/** @var MockWebServer */
protected static $server;
public static function setUpBeforeClass() : void {
self::$server = new MockWebServer;
self::$server->start();
}
public function testGetParams() : void {
$result = file_get_contents(self::$server->getServerRoot() . '/autoEndpoint?foo=bar');
$decoded = json_decode($result, true);
$this->assertSame('bar', $decoded['_GET']['foo']);
}
public function testGetSetPath() : void {
// $url = http://127.0.0.1:8123/definedEndPoint
$url = self::$server->setResponseOfPath('/definedEndPoint', new Response('foo bar content'));
$result = file_get_contents($url);
$this->assertSame('foo bar content', $result);
}
public static function tearDownAfterClass() : void {
// stopping the web server during tear down allows us to reuse the port for later tests
self::$server->stop();
}
}