Skip to content

Commit

Permalink
Merge pull request #1714 from WPO-Foundation/add-set-client
Browse files Browse the repository at this point in the history
feat(Request): Add CPClient setting
  • Loading branch information
jefflembeck authored Feb 1, 2022
2 parents 7b420af + 5de9ff5 commit b85fbc3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/models/RequestContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
use PHPUnit\Framework\TestCase;
use WebPageTest\RequestContext;
use WebPageTest\User;
use WebPageTest\CPClient;

final class RequestContextTest extends TestCase {
public function testConstructorSetsValues() : void {
$global_req = [];
$request = new RequestContext($global_req);
$this->assertEquals($global_req, $request->getRaw());
$this->assertNull($request->getUser());
$this->assertNull($request->getClient());
}

public function testSetGetUser() : void {
$global_req = [];
$email = 'foo@foo.com';
Expand All @@ -19,6 +23,15 @@ public function testSetGetUser() : void {
$request->setUser($user);
$this->assertEquals($email, $request->getUser()->getEmail());
}

public function testSetGetClient() : void {
$global_req = [];
$host = "https://www.foo.com";
$client = new CPClient($host);
$request = new RequestContext($global_req);
$request->setClient($client);
$this->assertEquals($host, $request->getClient()->host);
}
}

?>
12 changes: 12 additions & 0 deletions www/models/RequestContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
namespace WebPageTest;

use WebPageTest\User;
use WebPageTest\CPClient;

class RequestContext {
private array $raw;
private ?User $user;
private ?CPClient $client;

function __construct (array $global_request) {
$this->raw = $global_request;
$this->user = null;
$this->client = null;
}

function getRaw () : array {
Expand All @@ -27,5 +30,14 @@ function setUser (?User $user) : void {
}
}

function getClient () : ?CPClient {
return $this->client;
}

function setClient (?CPClient $client) : void {
if (isset($client)) {
$this->client = $client;
}
}
}
?>

0 comments on commit b85fbc3

Please sign in to comment.