Skip to content

Commit f31a26f

Browse files
authored
[TASK] Trigger assertion in assertCSVDataSet() on empty table (#653)
When comparing with a csv fixture that contains a table with no rows, which is a legit case, no assertion is raised. This makes phpunit emit a risky test: "This test did not perform any assertions". The patch adds an assertion in this case as well. Note phpunit nowadays has attribute #[DoesNotPerformAssertions] to mark tests that do not assert anything. This can be used for tests that for instance just call a subject method to verify no exception is raised. It is good to follow this path, the patch removes "beStrictAboutTestsThatDoNotTestAnything=false" from the example phpunit xml files, which makes this setting implicitly true. Releases: main Resolves: #647
1 parent ae48808 commit f31a26f

File tree

4 files changed

+4
-3
lines changed

4 files changed

+4
-3
lines changed

Build/phpunit/UnitTests.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd"
4-
beStrictAboutTestsThatDoNotTestAnything="false"
54
cacheDirectory=".phpunit.cache"
65
cacheResult="false"
76
colors="true"

Classes/Core/Functional/FunctionalTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ protected function assertCSVDataSet(string $fileName): void
615615
$hasHashField = ($dataSet->getHashIndex($tableName) !== null);
616616
$records = $this->getAllRecords($tableName, $hasUidField, $hasHashField);
617617
$assertions = $dataSet->getElements($tableName);
618+
if (count($assertions) === 0) {
619+
// Increase assertion counter to avoid "test did not perform any assertions" if testing for an empty table
620+
self::assertThat(true, self::isTrue());
621+
}
618622
foreach ($assertions as $assertion) {
619623
$result = $this->assertInRecords($assertion, $records);
620624
if ($result === false) {

Resources/Core/Build/FunctionalTests.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1717
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd"
1818
backupGlobals="true"
19-
beStrictAboutTestsThatDoNotTestAnything="false"
2019
bootstrap="FunctionalTestsBootstrap.php"
2120
cacheDirectory=".phpunit.cache"
2221
cacheResult="false"

Resources/Core/Build/UnitTests.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1717
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd"
1818
backupGlobals="true"
19-
beStrictAboutTestsThatDoNotTestAnything="false"
2019
bootstrap="UnitTestsBootstrap.php"
2120
cacheDirectory=".phpunit.cache"
2221
cacheResult="false"

0 commit comments

Comments
 (0)