- Issue created by @tr
- Merge request !11Issue #3478389 by tr: Add declare(strict_types=1) to all tests β (Merged) created by tr
- πΊπΈUnited States tr Cascadia
Test results show that using strict typing results in one additional test failure. But that's good - that's why we turn on strict typing, to find potential problems with the code:
Drupal\Tests\views_aggregator\Kernel\Plugin\ViewsAggregatorStyleTableUnitTest::testViewsAggregatorTable TypeError: strpos(): Argument #1 ($haystack) must be of type string, Drupal\Core\Render\Markup given
- πΊπΈUnited States tr Cascadia
Oh, and another reason to change the test ... this is a really screwy assert, with a double negative.
$this->assertFalse(strpos($output, 'views-field-name') !== FALSE)
- πΊπΈUnited States tr Cascadia
This is one of the three asserts that throws an error with strict typing turned on:
$this->assertFalse(strpos($output, 'views-field-name') !== FALSE)
What this does is search for the string
'views-field-name'
(the needle) somewhere inside the$output
text (the haystack).A return value from
strpos()
that is both boolean and FALSE means the needle was NOT found in the haystack. So a return value !== FALSE means that the needle IS found in the haystack.But we're using
assertFalse()
, which means that we're testing if it's FALSE that "the needle IS found in the haystack".So in other words, we expect the needle to not be found?
A more appropriate assert is then:
assertStringNotContainsString('views-field-name', (string) $output)
This is not only more readable but also expresses better exactly what we're trying to test.
- πΊπΈUnited States tr Cascadia
And that solved the problem described in #3. Merged.
Automatically closed - issue fixed for 2 weeks with no activity.