|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace phpweb\Test\EndToEnd; |
| 6 | + |
| 7 | +use PHPUnit\Framework; |
| 8 | + |
| 9 | +#[Framework\Attributes\CoversNothing] |
| 10 | +final class SmokeTest extends Framework\TestCase |
| 11 | +{ |
| 12 | + #[Framework\Attributes\DataProvider('provideUrl')] |
| 13 | + public function testUrlReturnsSuccessfulHttpResponseStatusCode(string $url): void |
| 14 | + { |
| 15 | + $successfulHttpStatusCodes = [200, 301, 302]; |
| 16 | + |
| 17 | + $handle = curl_init(); |
| 18 | + |
| 19 | + $options = [ |
| 20 | + CURLOPT_RETURNTRANSFER => true, |
| 21 | + CURLOPT_URL => $url, |
| 22 | + ]; |
| 23 | + |
| 24 | + curl_setopt_array($handle, $options); |
| 25 | + |
| 26 | + curl_exec($handle); |
| 27 | + |
| 28 | + $httpStatusCode = curl_getinfo($handle, CURLINFO_HTTP_CODE); |
| 29 | + |
| 30 | + self::assertTrue(in_array($httpStatusCode, $successfulHttpStatusCodes, true), sprintf( |
| 31 | + 'Failed asserting that the URL "%s" returns a successful HTTP response status code, got "%d" instead.', |
| 32 | + $url, |
| 33 | + $httpStatusCode, |
| 34 | + )); |
| 35 | + } |
| 36 | + |
| 37 | + /** |
| 38 | + * @return \Generator<string, array{0: string}> |
| 39 | + */ |
| 40 | + public static function provideUrl(): \Generator |
| 41 | + { |
| 42 | + $httpHost = getenv('HTTP_HOST'); |
| 43 | + |
| 44 | + if (!is_string($httpHost)) { |
| 45 | + throw new \RuntimeException('Environment variable "HTTP_HOST" is not set.'); |
| 46 | + } |
| 47 | + |
| 48 | + $pathToRoot = realpath(__DIR__ . '/../..'); |
| 49 | + |
| 50 | + $patterns = [ |
| 51 | + $pathToRoot . '/*.php', |
| 52 | + $pathToRoot . '/archive/*.php', |
| 53 | + $pathToRoot . '/conferences/*.php', |
| 54 | + $pathToRoot . '/license/*.php', |
| 55 | + $pathToRoot . '/manual/*.php', |
| 56 | + $pathToRoot . '/manual/en/*.php', |
| 57 | + $pathToRoot . '/releases/*.php', |
| 58 | + $pathToRoot . '/releases/*/*.php', |
| 59 | + $pathToRoot . '/releases/*/*/*.php', |
| 60 | + ]; |
| 61 | + |
| 62 | + foreach ($patterns as $pattern) { |
| 63 | + $pathsToFiles = glob($pattern); |
| 64 | + |
| 65 | + $paths = str_replace($pathToRoot, '', $pathsToFiles); |
| 66 | + |
| 67 | + foreach ($paths as $path) { |
| 68 | + $url = sprintf( |
| 69 | + 'http://%s%s', |
| 70 | + $httpHost, |
| 71 | + $path, |
| 72 | + ); |
| 73 | + |
| 74 | + yield $url => [ |
| 75 | + $url, |
| 76 | + ]; |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | +} |
0 commit comments