-
Notifications
You must be signed in to change notification settings - Fork 536
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhancement: Turn PHPT test into PHPUnit test case (#942)
- Loading branch information
1 parent
b506bb8
commit 9705aae
Showing
4 changed files
with
86 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace phpweb\Test\EndToEnd; | ||
|
||
use PHPUnit\Framework; | ||
|
||
#[Framework\Attributes\CoversNothing] | ||
final class SmokeTest extends Framework\TestCase | ||
{ | ||
#[Framework\Attributes\DataProvider('provideUrl')] | ||
public function testUrlReturnsSuccessfulHttpResponseStatusCode(string $url): void | ||
{ | ||
$successfulHttpStatusCodes = [200, 301, 302]; | ||
|
||
$handle = curl_init(); | ||
|
||
$options = [ | ||
CURLOPT_RETURNTRANSFER => true, | ||
CURLOPT_URL => $url, | ||
]; | ||
|
||
curl_setopt_array($handle, $options); | ||
|
||
curl_exec($handle); | ||
|
||
$httpStatusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); | ||
|
||
self::assertTrue(in_array($httpStatusCode, $successfulHttpStatusCodes, true), sprintf( | ||
'Failed asserting that the URL "%s" returns a successful HTTP response status code, got "%d" instead.', | ||
$url, | ||
$httpStatusCode, | ||
)); | ||
} | ||
|
||
/** | ||
* @return \Generator<string, array{0: string}> | ||
*/ | ||
public static function provideUrl(): \Generator | ||
{ | ||
$httpHost = getenv('HTTP_HOST'); | ||
|
||
if (!is_string($httpHost)) { | ||
throw new \RuntimeException('Environment variable "HTTP_HOST" is not set.'); | ||
} | ||
|
||
$pathToRoot = realpath(__DIR__ . '/../..'); | ||
|
||
$patterns = [ | ||
$pathToRoot . '/*.php', | ||
$pathToRoot . '/archive/*.php', | ||
$pathToRoot . '/conferences/*.php', | ||
$pathToRoot . '/license/*.php', | ||
$pathToRoot . '/manual/*.php', | ||
$pathToRoot . '/manual/en/*.php', | ||
$pathToRoot . '/releases/*.php', | ||
$pathToRoot . '/releases/*/*.php', | ||
$pathToRoot . '/releases/*/*/*.php', | ||
]; | ||
|
||
foreach ($patterns as $pattern) { | ||
$pathsToFiles = glob($pattern); | ||
|
||
$paths = str_replace($pathToRoot, '', $pathsToFiles); | ||
|
||
foreach ($paths as $path) { | ||
$url = sprintf( | ||
'http://%s%s', | ||
$httpHost, | ||
$path, | ||
); | ||
|
||
yield $url => [ | ||
$url, | ||
]; | ||
} | ||
} | ||
} | ||
} |
65 changes: 0 additions & 65 deletions
65
tests/EndToEnd/paths-return-http-response-status-code-200-301-or-302.phpt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters