Task #103880
closedEnable PHPStan ruleset for PHPunit tests - Missing call to parent::tearDown; use assertCount instead of assertSame
100%
Description
We can enable vendor/phpstan/phpstan-phpunit/rules.neon
for PHPunit tests:
rules:
- PHPStan\Rules\PHPUnit\AssertSameBooleanExpectedRule
- PHPStan\Rules\PHPUnit\AssertSameNullExpectedRule
- PHPStan\Rules\PHPUnit\AssertSameWithCountRule
- PHPStan\Rules\PHPUnit\MockMethodCallRule
- PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule
ShouldCallParentMethodsRule¶
Missing call to parent::tearDown() method.
This is especially nice to fix.
AssertSameWithCountRule¶
You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)).
This is easily fixable.
MockMethodCallRule¶
Trying to mock an undefined method executeUpdate() on class TYPO3\CMS\Core\Database\Connection.
This is just temporary --> add to phpstan-baseline.neon
See core/Tests/Unit/Database/ConnectionTest.php
:
// @todo drop else branch and condition once doctrine/dbal is requried in version 2.11.0 minimum
PHPStan ruleset for PHPunit: without fixes¶
$ Build/Scripts/runTests.sh -s phpstan ------ ---------------------------------------------------------------------------------------------------------------- Line core/Tests/Functional/Cache/Backend/ApcuBackendTest.php ------ ---------------------------------------------------------------------------------------------------------------- 273 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)). ------ ---------------------------------------------------------------------------------------------------------------- ------ ---------------------------------------------------------------------------------------------------------------- Line core/Tests/Functional/Database/Query/QueryBuilder/PositionPlaceholderPreparedStatementTest.php ------ ---------------------------------------------------------------------------------------------------------------- 79 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)). 87 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)). 123 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)). 134 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)). ------ ---------------------------------------------------------------------------------------------------------------- ------ --------------------------------------------------------------------------- Line core/Tests/Functional/Security/ContentSecurityPolicy/ModelServiceTest.php ------ --------------------------------------------------------------------------- 42 Missing call to parent::tearDown() method. ------ --------------------------------------------------------------------------- ------ ------------------------------------------------------------------------------------------------- Line core/Tests/Unit/Database/ConnectionTest.php ------ ------------------------------------------------------------------------------------------------- 246 Trying to mock an undefined method executeUpdate() on class TYPO3\CMS\Core\Database\Connection. 296 Trying to mock an undefined method executeUpdate() on class TYPO3\CMS\Core\Database\Connection. ------ ------------------------------------------------------------------------------------------------- ------ ---------------------------------------------------------------------------------------------------------------- Line core/Tests/Unit/Utility/String/StringFragmentCollectionTest.php ------ ---------------------------------------------------------------------------------------------------------------- 34 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)). ------ ---------------------------------------------------------------------------------------------------------------- ------ ------------------------------------------------------------------------------------------------------------------ Line extbase/Tests/Functional/Persistence/CountTest.php ------ ------------------------------------------------------------------------------------------------------------------ 141 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()). ------ ------------------------------------------------------------------------------------------------------------------ ------ ------------------------------------------------------------------------------------------------------------------ Line extbase/Tests/Functional/Persistence/WorkspaceTest.php ------ ------------------------------------------------------------------------------------------------------------------ 132 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()). ------ ------------------------------------------------------------------------------------------------------------------ ------ ------------------------------------------------------------------------------------------------------------------ Line extensionmanager/Tests/Unit/Domain/Model/ExtensionTest.php ------ ------------------------------------------------------------------------------------------------------------------ 197 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()). ------ ------------------------------------------------------------------------------------------------------------------ ------ ------------------------------------------------------------------------------------------------------------------ Line form/Tests/Functional/Domain/Model/Renderable/AbstractRenderableTest.php ------ ------------------------------------------------------------------------------------------------------------------ 54 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()). 58 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()). ------ ------------------------------------------------------------------------------------------------------------------ ------ ---------------------------------------------------------------------------------------------------------------- Line frontend/Tests/Functional/SiteHandling/SlugLinkGeneratorTest.php ------ ---------------------------------------------------------------------------------------------------------------- 918 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)). ------ ---------------------------------------------------------------------------------------------------------------- ------ ------------------------------------------------------------------------------------------------------------------ Line redirects/Tests/Functional/EventListener/AddPageTypeZeroSourceTest.php ------ ------------------------------------------------------------------------------------------------------------------ 65 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()). 112 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()). 218 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()). ------ ------------------------------------------------------------------------------------------------------------------ ------ ------------------------------------------------------------------------------------------------------------------ Line redirects/Tests/Unit/RedirectUpdate/RedirectSourceCollectionTest.php ------ ------------------------------------------------------------------------------------------------------------------ 39 You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()). ------ ------------------------------------------------------------------------------------------------------------------ [ERROR] Found 19 errors ########################################################################### Result of phpstan Container runtime: docker PHP: 8.2 FAILURE ###########################################################################
Updated by Gerrit Code Review 6 months ago
- Status changed from New to Under Review
Patch set 1 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84351
Updated by Ayke Halder 6 months ago
- Blocked by Task #103929: Remove `doctrine/dbal` version aware method mocking in tests added
Updated by Gerrit Code Review 6 months ago
Patch set 2 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84351
Updated by Gerrit Code Review 6 months ago
Patch set 3 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84351
Updated by Gerrit Code Review 6 months ago
Patch set 4 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84351
Updated by Gerrit Code Review 6 months ago
Patch set 5 for branch main of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/84351
Updated by Ayke Halder 6 months ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 5d53d7cf8f15aba4edf651f15a31843ace0fdd25.