Project

General

Profile

Task #103880

Updated by Ayke Halder 6 months ago

We can enable @vendor/phpstan/phpstan-phpunit/rules.neon@ `vendor/phpstan/phpstan-phpunit/rules.neon` for PHPunit tests: 

 <pre><code class="yaml"> 
 rules: 
   - PHPStan\Rules\PHPUnit\AssertSameBooleanExpectedRule 
   - PHPStan\Rules\PHPUnit\AssertSameNullExpectedRule 
   - PHPStan\Rules\PHPUnit\AssertSameWithCountRule 
   - PHPStan\Rules\PHPUnit\MockMethodCallRule 
   - PHPStan\Rules\PHPUnit\ShouldCallParentMethodsRule 
 </code></pre> 

 ---- 


 h3. parent::tearDown 

 @Missing call to parent::tearDown() method.@ 
 This is especially nice to fix. 

 h3. assertCount 

 @You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)).@ 
 This is easily fixable. 

 h3. mock an undefined method 

 @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 

 --- 

 h3. PHPStan ruleset for PHPunit: without fixes 

 <pre> 
 $ 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 
 ########################################################################### 
 </pre> 




Back