Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"phpweb\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"phpweb\\Test\\EndToEnd\\": "tests/EndToEnd/"
}
},
"config": {
"platform": {
"php": "8.2.0"
Expand Down
80 changes: 80 additions & 0 deletions tests/EndToEnd/SmokeTest.php
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,
];
}
}
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion tests/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</source>
<testsuites>
<testsuite name="end-to-end">
<directory suffix=".phpt">EndToEnd/</directory>
<directory suffix=".php">EndToEnd/</directory>
</testsuite>
<testsuite name="unit">
<directory suffix=".phpt">Unit/</directory>
Expand Down