Repository navigation
Expand file tree
/
Copy pathbehat.php
More file actions
70 lines (66 loc) · 2.44 KB
/
Copy pathbehat.php
File metadata and controls
70 lines (66 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
use Behat\Config\Config;
use Behat\Config\Extension;
use Behat\Config\Formatter\JUnitFormatter;
use Behat\Config\Formatter\PrettyFormatter;
use Behat\Config\Profile;
use Behat\Config\Suite;
use LibreSign\Behat\MailpitExtension\Context\MailpitContext;
use LibreSign\Behat\MailpitExtension\ServiceContainer\MailpitExtension;
use LibreSign\Behat\Sharding\FeatureShardSelector;
use LibreSign\Behat\TsaExtension\ServiceContainer\TsaExtension;
use PhpBuiltin\Server;
// When the CI matrix defines a shard, select whole features using Behat's own suite API.
// Local runs without SHARD_* continue to execute the complete feature suite.
$featurePaths = ['%paths.base%/tests/integration/features'];
$index = getenv('SHARD_INDEX');
$total = getenv('SHARD_TOTAL');
if ($index !== false || $total !== false) {
require_once __DIR__ . '/tests/integration/sharding/FeatureShardSelector.php';
$selector = FeatureShardSelector::fromEnvironment([
'SHARD_INDEX' => $index,
'SHARD_TOTAL' => $total,
]);
$featureDirectory = __DIR__ . '/tests/integration/features';
$features = FeatureShardSelector::discover($featureDirectory);
$weights = [];
foreach ($features as $feature) {
$weights[$feature] = FeatureShardSelector::countScenarios($featureDirectory . '/' . $feature);
}
$selected = $selector->select($features, $weights);
if ($selected === []) {
throw new RuntimeException('Behat shard is empty; refusing to run the full suite.');
}
$featurePaths = array_map(
static fn (string $path): string => '%paths.base%/tests/integration/features/' . $path,
$selected,
);
}
return (new Config())
->withProfile((new Profile('default', [
'autoload' => [
'' => '%paths.base%/tests/integration/features/bootstrap',
],
]))
->withSuite((new Suite('default'))
->withContexts(MailpitContext::class, FeatureContext::class)
->withPaths(...$featurePaths))
->withExtension(new Extension(MailpitExtension::class, [
'base_url' => 'http://mailpit:8025',
]))
->withExtension(new Extension(Server::class, [
'rootDir' => dirname(__DIR__, 2),
'runAs' => 'www-data',
'workers' => 2,
]))
->withExtension(new Extension(TsaExtension::class)))
->withProfile((new Profile('ci'))
->withFormatter(new PrettyFormatter())
->withFormatter((new JUnitFormatter())->withOutputPath(
getenv('BEHAT_JUNIT_OUTPUT_DIR') ?: 'tests/integration/output',
)))
;