Skip to content

Commit

Permalink
Merge pull request #22 from madewithlove/make-status-code-available
Browse files Browse the repository at this point in the history
Make status code available in the HtaccessResult value object
  • Loading branch information
jdrieghe authored Dec 9, 2020
2 parents 45dc54b + 347aacf commit 81d126b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/HtaccessClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ function (array $line) {
);
},
$responseData['lines']
)
),
$responseData['output_status_code']
);
}

Expand Down Expand Up @@ -108,7 +109,8 @@ function (array $line) {
);
},
$responseData['lines']
)
),
$responseData['output_status_code']
);
}

Expand Down
18 changes: 16 additions & 2 deletions src/HtaccessResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ final class HtaccessResult
*/
private $lines = [];

public function __construct(string $outputUrl, array $lines)
{
/**
* @var int?
*/
private $outputStatusCode;

public function __construct(
string $outputUrl,
array $lines,
?int $outputStatusCode
) {
$this->outputUrl = $outputUrl;
$this->outputStatusCode = $outputStatusCode;

foreach ($lines as $line) {
$this->addLine($line);
Expand All @@ -36,6 +45,11 @@ public function getLines(): array
return $this->lines;
}

public function getOutputStatusCode(): ?int
{
return $this->outputStatusCode;
}

private function addLine(ResultLine $line): void
{
$this->lines[] = $line;
Expand Down
11 changes: 8 additions & 3 deletions tests/HtaccessClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@ public function it returns the result from the api(): void

$response = $client->test(
'http://localhost',
'RewriteRule .* /foo [R]'
'RewriteRule .* /foo [R=301]'
);

$this->assertEquals(
'http://localhost/foo',
$response->getOutputUrl()
);

$this->assertEquals(
301,
$response->getOutputStatusCode()
);

$this->assertEquals(
[
new ResultLine(
'RewriteRule .* /foo [R]',
"The new url is http://localhost/foo\nTest are stopped, a redirect will be made with status code 302",
'RewriteRule .* /foo [R=301]',
"The new url is http://localhost/foo\nTest are stopped, a redirect will be made with status code 301",
true,
true,
true,
Expand Down

0 comments on commit 81d126b

Please sign in to comment.