Skip to content

Commit 7274fda

Browse files
committed
Run integration tests via process-compose-flake
1 parent 749fc83 commit 7274fda

File tree

3 files changed

+83
-203
lines changed

3 files changed

+83
-203
lines changed

dev/flake.nix

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
extensions = { enabled, all }:
2828
enabled ++ (with all; [ imagick memcached ]);
2929
};
30-
wp2static = inputs.wp2static.packages.${system}.plugin;
30+
wp2staticPkgs = inputs.wp2static.packages.${system};
31+
wp2static = wp2staticPkgs.plugin;
3132
in {
3233
imports = [ inputs.services-flake.processComposeModules.default ];
3334
services.mysql."mysql1" = {
@@ -104,20 +105,31 @@
104105
success_threshold = 1;
105106
failure_threshold = 5;
106107
};
107-
settings.processes.test = {
108-
command = pkgs.writeShellApplication {
109-
name = "test";
110-
runtimeInputs = [ config.services.mysql.mysql1.package ];
111-
text = ''
112-
echo 'SELECT version();' | mysql -h 127.0.0.1 --port="${
113-
toString dbPort
114-
}" --user="${dbUserName}" --password="${dbUserPass}" "${dbName}"
115-
${pkgs.wp-cli}/bin/wp --path=data/wordpress1 wp2static detect
116-
'';
108+
settings.processes.test =
109+
let php = config.services.phpfpm."phpfpm1".package;
110+
in {
111+
command = pkgs.writeShellApplication {
112+
name = "test";
113+
runtimeInputs =
114+
[ config.services.mysql."mysql1".package php pkgs.wp-cli ];
115+
text = ''
116+
TMPDIR="$(realpath ./tmp)"
117+
mkdir -p "$TMPDIR"
118+
echo 'SELECT version();' | mysql -h 127.0.0.1 --port="${
119+
toString dbPort
120+
}" --user="${dbUserName}" --password="${dbUserPass}" "${dbName}"
121+
${pkgs.rsync}/bin/rsync -a --copy-links ${wp2staticPkgs.composerVendorDev}/. .
122+
${pkgs.rsync}/bin/rsync -a --copy-links ${wp2staticPkgs.wp2staticSrcDev}/. .
123+
WORDPRESS_DIR="$(realpath ./data/wordpress1)"
124+
export WORDPRESS_DIR
125+
${php}/bin/php -d sys_temp_dir="$TMPDIR" vendor/bin/phpunit --do-not-cache-result ./tests/integration/
126+
'';
127+
};
128+
depends_on."mysql1-configure".condition =
129+
"process_completed_successfully";
130+
depends_on."wordpress1".condition =
131+
"process_completed_successfully";
117132
};
118-
depends_on."mysql1-configure".condition = "process_completed_successfully";
119-
depends_on."wordpress1".condition = "process_completed_successfully";
120-
};
121133
settings.processes."wordpress1" = let
122134
WPConfigFormat =
123135
(inputs.wordpress-flake.lib.${system}.WPConfigFormat {

tests/integration/CrawlTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace WP2Static;
4+
5+
use PHPUnit\Framework\TestCase;
6+
7+
final class CrawlTest extends TestCase
8+
{
9+
private string $wordpressDir;
10+
private string $uploadsDir;
11+
private string $robotsFile;
12+
private string $sitemapFile;
13+
14+
protected function setUp(): void
15+
{
16+
$this->wordpressDir = rtrim(getenv('WORDPRESS_DIR'), '/');
17+
$this->uploadsDir = "{$this->wordpressDir}/wp-content/uploads/wp2static-crawled-site";
18+
}
19+
20+
private function runWpCli(array $args, array $expectWarnings = []): array
21+
{
22+
$cmd = implode(' ', array_map('escapeshellarg', array_merge(['wp', '--path=' . $this->wordpressDir], $args)));
23+
$output = [];
24+
$exitCode = 0;
25+
exec($cmd . ' 2>&1', $output, $exitCode);
26+
27+
foreach ($expectWarnings as $pattern => $expectedCount) {
28+
$matches = array_filter($output, fn($line) => preg_match($pattern, $line));
29+
$this->assertCount($expectedCount, $matches, "Expected $expectedCount matches for pattern: $pattern");
30+
}
31+
32+
if ($exitCode !== 0) {
33+
throw new \Exception("WP CLI command failed: $cmd\nOutput: " . implode("\n", $output));
34+
}
35+
36+
return ['exit' => $exitCode, 'output' => $output];
37+
}
38+
39+
private function getCrawledFile(string $path): string
40+
{
41+
$content = file_get_contents("{$this->uploadsDir}/$path");
42+
if ($content === false) {
43+
throw new \Exception("Failed to read file: {$this->uploadsDir}/$path");
44+
}
45+
return $content;
46+
}
47+
48+
public function testIndexCrawl(): void
49+
{
50+
$this->runWpCli(['wp2static', 'detect']);
51+
$this->runWpCli(['wp2static', 'crawl']);
52+
53+
$content = $this->getCrawledFile("index.html");
54+
55+
$this->assertStringContainsString("Welcome to WordPress", $content);
56+
}
57+
}

tests/integration/URLHelperTest.php

Lines changed: 0 additions & 189 deletions
This file was deleted.

0 commit comments

Comments
 (0)