Skip to content

Commit 5ec42b4

Browse files
committed
move mocks to test-config
1 parent c2122cb commit 5ec42b4

File tree

4 files changed

+70
-96
lines changed

4 files changed

+70
-96
lines changed

tests/phpunit/MiddlewareTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<?php
22
namespace Pdsinterop\PhpSolid;
33

4-
use Pdsinterop\PhpSolid\Middleware;
4+
require_once(__DIR__ . "/test-config.php");
55

6-
const PUBSUB_SERVER = "https://localhost:1234";
7-
function header($header) {
8-
MiddleWareTest::$headers[] = $header;
9-
}
6+
use Pdsinterop\PhpSolid\Middleware;
107

118
class MiddlewareTest extends \PHPUnit\Framework\TestCase
129
{

tests/phpunit/ServerTest.php

Lines changed: 10 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,10 @@
11
<?php
22
namespace Pdsinterop\PhpSolid;
33

4-
use Pdsinterop\PhpSolid\Server;
5-
6-
const PUBSUB_SERVER = "https://localhost:1234";
7-
const KEYDIR = "php://memory/";
8-
const BASEURL = "https://example.com";
9-
const DBPATH = ":memory:";
4+
require_once(__DIR__ . "/test-config.php");
105

11-
function header($header) {
12-
ServerTest::$headers[] = $header;
13-
}
14-
15-
function file_get_contents($file) {
16-
if(!isset(ServerTest::$keys)) {
17-
ServerTest::$keys = Server::generateKeySet();
18-
}
19-
if (preg_match("/encryption/", $file)) {
20-
return ServerTest::$keys['encryptionKey'];
21-
}
22-
if (preg_match("/public/", $file)) {
23-
return ServerTest::$keys['publicKey'];
24-
}
25-
if (preg_match("/private/", $file)) {
26-
return ServerTest::$keys['privateKey'];
27-
}
28-
}
6+
use Pdsinterop\PhpSolid\Server;
297

30-
class MockBody {
31-
public function rewind() {
32-
return true;
33-
}
34-
public function getContents() {
35-
return json_encode(["Hello" => "world"]);
36-
}
37-
}
38-
39-
class MockResponse {
40-
public function getStatusCode() {
41-
return 200;
42-
}
43-
public function getBody() {
44-
return new MockBody();
45-
}
46-
public function getHeaders() {
47-
return [
48-
"Foo" => ["Bar", "Blah"]
49-
];
50-
}
51-
}
52-
538
class ServerTest extends \PHPUnit\Framework\TestCase
549
{
5510
public static $headers = [];
@@ -130,14 +85,14 @@ public function testGetBearer() {
13085
}
13186
public function testGetEndpoints() {
13287
$endpoints = Server::getEndpoints();
133-
$this->assertEquals($endpoints["issuer"], "https://example.com");
134-
$this->assertEquals($endpoints["jwks_uri"], "https://example.com/jwks/");
135-
$this->assertEquals($endpoints["check_session_iframe"], "https://example.com/session/");
136-
$this->assertEquals($endpoints["end_session_endpoint"], "https://example.com/logout/");
137-
$this->assertEquals($endpoints["authorization_endpoint"], "https://example.com/authorize/");
138-
$this->assertEquals($endpoints["token_endpoint"], "https://example.com/token/");
139-
$this->assertEquals($endpoints["userinfo_endpoint"], "https://example.com/userinfo/");
140-
$this->assertEquals($endpoints["registration_endpoint"], "https://example.com/register/");
88+
$this->assertEquals($endpoints["issuer"], "https://solid.example.com");
89+
$this->assertEquals($endpoints["jwks_uri"], "https://solid.example.com/jwks/");
90+
$this->assertEquals($endpoints["check_session_iframe"], "https://solid.example.com/session/");
91+
$this->assertEquals($endpoints["end_session_endpoint"], "https://solid.example.com/logout/");
92+
$this->assertEquals($endpoints["authorization_endpoint"], "https://solid.example.com/authorize/");
93+
$this->assertEquals($endpoints["token_endpoint"], "https://solid.example.com/token/");
94+
$this->assertEquals($endpoints["userinfo_endpoint"], "https://solid.example.com/userinfo/");
95+
$this->assertEquals($endpoints["registration_endpoint"], "https://solid.example.com/register/");
14196
}
14297

14398
public function testGetKeys() {

tests/phpunit/StorageServerTest.php

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,9 @@
11
<?php
22
namespace Pdsinterop\PhpSolid;
33

4-
use Pdsinterop\PhpSolid\StorageServer;
5-
6-
const STORAGEBASE = ".";
7-
const DBPATH = ":memory:";
8-
const BANNED_PASSWORDS = [];
9-
const MINIMUM_PASSWORD_ENTROPY = 0;
10-
const BASEDOMAIN = "example.com";
11-
const BASEURL = "https://example.com";
12-
13-
14-
function header($header) {
15-
StorageServerTest::$headers[] = $header;
16-
}
4+
require_once(__DIR__ . "/test-config.php");
175

18-
class MockBody {
19-
public function rewind() {
20-
return true;
21-
}
22-
public function getContents() {
23-
return json_encode(["Hello" => "world"]);
24-
}
25-
}
26-
27-
class MockResponse {
28-
public function getStatusCode() {
29-
return 200;
30-
}
31-
public function getBody() {
32-
return new MockBody();
33-
}
34-
public function getHeaders() {
35-
return [
36-
"Foo" => ["Bar", "Blah"]
37-
];
38-
}
39-
}
6+
use Pdsinterop\PhpSolid\StorageServer;
407

418
class StorageServerTest extends \PHPUnit\Framework\TestCase
429
{

tests/phpunit/test-config.php

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,59 @@
66
const BANNED_PASSWORDS = [];
77
const MINIMUM_PASSWORD_ENTROPY = 10;
88
const BASEDOMAIN = "solid.example.com";
9-
const BASEURL = "https://solid.example.com";
9+
const BASEURL = "https://solid.example.com";
10+
const PUBSUB_SERVER = "https://localhost:1234";
11+
const KEYDIR = "php://memory/";
12+
const STORAGEBASE = ".";
13+
14+
function header($header) {
15+
if (class_exists('Pdsinterop\PhpSolid\MiddleWareTest')) {
16+
MiddleWareTest::$headers[] = $header;
17+
}
18+
if (class_exists('Pdsinterop\PhpSolid\ServerTest')) {
19+
ServerTest::$headers[] = $header;
20+
}
21+
if (class_exists('Pdsinterop\PhpSolid\StorageServerTest')) {
22+
StorageServerTest::$headers[] = $header;
23+
}
24+
}
25+
26+
function file_get_contents($file) {
27+
if (class_exists('Pdsinterop\PhpSolid\ServerTest')) {
28+
if(!isset(ServerTest::$keys)) {
29+
ServerTest::$keys = Server::generateKeySet();
30+
}
31+
if (preg_match("/encryption/", $file)) {
32+
return ServerTest::$keys['encryptionKey'];
33+
}
34+
if (preg_match("/public/", $file)) {
35+
return ServerTest::$keys['publicKey'];
36+
}
37+
if (preg_match("/private/", $file)) {
38+
return ServerTest::$keys['privateKey'];
39+
}
40+
}
41+
}
42+
43+
class MockBody {
44+
public function rewind() {
45+
return true;
46+
}
47+
public function getContents() {
48+
return json_encode(["Hello" => "world"]);
49+
}
50+
}
51+
52+
class MockResponse {
53+
public function getStatusCode() {
54+
return 200;
55+
}
56+
public function getBody() {
57+
return new MockBody();
58+
}
59+
public function getHeaders() {
60+
return [
61+
"Foo" => ["Bar", "Blah"]
62+
];
63+
}
64+
}

0 commit comments

Comments
 (0)