|
8 | 8 |
|
9 | 9 | use Behat\Behat\Context\Context; |
10 | 10 | use Behat\Behat\Context\Environment\InitializedContextEnvironment; |
| 11 | +use Behat\Behat\Hook\Scope\AfterScenarioScope; |
11 | 12 | use Behat\Behat\Hook\Scope\BeforeScenarioScope; |
12 | 13 | use Behat\Gherkin\Node\PyStringNode; |
13 | 14 | use Behat\Gherkin\Node\TableNode; |
| 15 | +use Behat\Testwork\Tester\Result\TestResult; |
14 | 16 | use GuzzleHttp\Client; |
15 | 17 | use GuzzleHttp\Cookie\CookieJar; |
16 | 18 | use GuzzleHttp\Exception\GuzzleException; |
@@ -100,6 +102,19 @@ public function setResponse(?ResponseInterface $response): void { |
100 | 102 | $this->response = $response; |
101 | 103 | } |
102 | 104 |
|
| 105 | + /** |
| 106 | + * @return string |
| 107 | + */ |
| 108 | + public function getServerVersion(): string { |
| 109 | + $version = getenv('NEXTCLOUD_VERSION'); |
| 110 | + if (!$version) { |
| 111 | + return ""; |
| 112 | + } |
| 113 | + $version = preg_replace("/^stable/", "", $version); |
| 114 | + $version = explode(".", $version)[0]; |
| 115 | + return "nc{$version}"; |
| 116 | + } |
| 117 | + |
103 | 118 | public function __construct( |
104 | 119 | string $baseUrl, |
105 | 120 | string $adminUsername, |
@@ -944,6 +959,7 @@ public function sendHttpRequest( |
944 | 959 | if ($user !== null && $password !== null) { |
945 | 960 | $options['auth'] = [$user, $password]; |
946 | 961 | } |
| 962 | + $options['verify'] = false; |
947 | 963 | $client = new Client($options); |
948 | 964 | if ($headers === null) { |
949 | 965 | $headers = []; |
@@ -1369,4 +1385,64 @@ public function after():void { |
1369 | 1385 | } |
1370 | 1386 | $this->createdAppPasswords = []; |
1371 | 1387 | } |
| 1388 | + |
| 1389 | + /** |
| 1390 | + * @AfterScenario |
| 1391 | + * |
| 1392 | + * @param AfterScenarioScope $scope |
| 1393 | + * |
| 1394 | + * @return void |
| 1395 | + */ |
| 1396 | + public function checkExpectedFailure(AfterScenarioScope $scope): void { |
| 1397 | + $reportDir = dirname(dirname(__DIR__)) . "/reports"; |
| 1398 | + if (!is_dir($reportDir) && !mkdir($reportDir, 0755, true)) { |
| 1399 | + throw new \RuntimeException("Failed to create report directory: {$reportDir}"); |
| 1400 | + } |
| 1401 | + |
| 1402 | + $serverVersion = $this->getServerVersion(); |
| 1403 | + $tag = "expect-fail-on-{$serverVersion}"; |
| 1404 | + $scenario = $scope->getScenario(); |
| 1405 | + $feature = $scope->getFeature(); |
| 1406 | + $result = $scope->getTestResult(); |
| 1407 | + |
| 1408 | + $featurePath = $feature->getFile(); |
| 1409 | + $featurePath = "tests/" . explode("/tests/", $featurePath)[1]; |
| 1410 | + $title = $scenario->getTitle(); |
| 1411 | + $keyword = $scenario->getKeyword(); |
| 1412 | + $lineNumber = $scenario->getLine(); |
| 1413 | + $scenarioLine = " - $keyword: $title ($featurePath:$lineNumber)"; |
| 1414 | + |
| 1415 | + $hasExpectFailTag = ""; |
| 1416 | + foreach ($scenario->getTags() as $t) { |
| 1417 | + if (str_starts_with($t, $tag)) { |
| 1418 | + $hasExpectFailTag = $t; |
| 1419 | + break; |
| 1420 | + } |
| 1421 | + } |
| 1422 | + |
| 1423 | + $reportFile = null; |
| 1424 | + if ($hasExpectFailTag && !$serverVersion) { |
| 1425 | + echo "[ERROR] Scenario has tag '$hasExpectFailTag' but could not determine server version. Set 'NEXTCLOUD_VERSION' env"; |
| 1426 | + if ($result->isPassed()) { |
| 1427 | + $reportFile = "$reportDir/unexpected-passes.txt"; |
| 1428 | + } |
| 1429 | + } |
| 1430 | + |
| 1431 | + if ($scenario->hasTag($tag) || $scenario->hasTag("expect-fail")) { |
| 1432 | + if ($result->getResultCode() === TestResult::FAILED) { |
| 1433 | + $reportFile = "$reportDir/expected-failures.txt"; |
| 1434 | + } elseif ($result->isPassed()) { |
| 1435 | + $reportFile = "$reportDir/unexpected-passes.txt"; |
| 1436 | + echo "[ERROR] Scenario was expected to fail but it did not."; |
| 1437 | + } else { |
| 1438 | + $reportFile = "$reportDir/failures.txt"; |
| 1439 | + } |
| 1440 | + } elseif (!$result->isPassed()) { |
| 1441 | + $reportFile = "$reportDir/failures.txt"; |
| 1442 | + } |
| 1443 | + |
| 1444 | + if ($reportFile) { |
| 1445 | + file_put_contents($reportFile, $scenarioLine . PHP_EOL, FILE_APPEND); |
| 1446 | + } |
| 1447 | + } |
1372 | 1448 | } |
0 commit comments