Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
usarise committed Jun 6, 2023
1 parent 3c42884 commit 3bf7ff3
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions tests/TurnstileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,87 +183,87 @@ public function testError(): void {
);
}

public function testHostnameValidation(): void {
public function testTimeoutSecondsValidation(): void {
$challengeTs = $this->getChallengeTs('now');

$response = (new Turnstile(
client: $this->getMockHttpClientReturn(
'{"success": true, "hostname": "localhost.test"}',
'{"success": true, "challenge_ts": "' . $challengeTs . '"}',
),
secret: 'secret',
hostname: 'localhost.test',
timeoutSeconds: 15,
))
->verify('response')
;

$this->assertTrue($response->success);
$this->assertEquals(
'localhost.test',
$response->hostname,
$challengeTs,
$response->challengeTs,
);
}

public function testBadHostnameValidation(): void {
public function testBadTimeoutSecondsValidation(): void {
$challengeTs = $this->getChallengeTs('-150 sec');

$response = (new Turnstile(
client: $this->getMockHttpClientReturn(
'{"success": true, "hostname": "localhost.test"}',
'{"success": true, "challenge_ts": "' . $challengeTs . '"}',
),
secret: 'secret',
hostname: 'localhost',
timeoutSeconds: 15,
))
->verify('response')
;

$this->assertFalse($response->success);
$this->assertEquals(
['hostname-mismatch'],
['challenge-timeout'],
$response->errorCodes,
);
$this->assertEquals(
'localhost.test',
$response->hostname,
$challengeTs,
$response->challengeTs,
);
}

public function testTimeoutSecondsValidation(): void {
$challengeTs = $this->getChallengeTs('now');

public function testHostnameValidation(): void {
$response = (new Turnstile(
client: $this->getMockHttpClientReturn(
'{"success": true, "challenge_ts": "' . $challengeTs . '"}',
'{"success": true, "hostname": "localhost.test"}',
),
secret: 'secret',
timeoutSeconds: 15,
hostname: 'localhost.test',
))
->verify('response')
;

$this->assertTrue($response->success);
$this->assertEquals(
$challengeTs,
$response->challengeTs,
'localhost.test',
$response->hostname,
);
}

public function testBadTimeoutSecondsValidation(): void {
$challengeTs = $this->getChallengeTs('-150 sec');

public function testBadHostnameValidation(): void {
$response = (new Turnstile(
client: $this->getMockHttpClientReturn(
'{"success": true, "challenge_ts": "' . $challengeTs . '"}',
'{"success": true, "hostname": "localhost.test"}',
),
secret: 'secret',
timeoutSeconds: 15,
hostname: 'localhost',
))
->verify('response')
;

$this->assertFalse($response->success);
$this->assertEquals(
['challenge-timeout'],
['hostname-mismatch'],
$response->errorCodes,
);
$this->assertEquals(
$challengeTs,
$response->challengeTs,
'localhost.test',
$response->hostname,
);
}

Expand Down

0 comments on commit 3bf7ff3

Please sign in to comment.