Browse Source

Fix issues found by PHPStan in tests/

mscherer 4 years ago
parent
commit
dd82270bee

+ 2 - 0
tests/TestCase/Database/QueryTest.php

@@ -4917,6 +4917,7 @@ class QueryTest extends TestCase
     public function testStringExpression(): void
     {
         $driver = $this->connection->getDriver();
+        $collation = null;
         if ($driver instanceof Mysql) {
             if (version_compare($this->connection->getDriver()->version(), '5.7.0', '<')) {
                 $collation = 'utf8_general_ci';
@@ -4953,6 +4954,7 @@ class QueryTest extends TestCase
     public function testIdentifierCollation(): void
     {
         $driver = $this->connection->getDriver();
+        $collation = null;
         if ($driver instanceof Mysql) {
             if (version_compare($this->connection->getDriver()->version(), '5.7.0', '<')) {
                 $collation = 'utf8_general_ci';

+ 10 - 0
tests/TestCase/ORM/Association/BelongsToManyTest.php

@@ -55,6 +55,16 @@ class BelongsToManyTest extends TestCase
     ];
 
     /**
+     * @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject
+     */
+    protected $tag;
+
+    /**
+     * @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject
+     */
+    protected $article;
+
+    /**
      * Set up
      */
     public function setUp(): void

+ 15 - 0
tests/TestCase/ORM/Association/BelongsToTest.php

@@ -41,6 +41,21 @@ class BelongsToTest extends TestCase
     protected $fixtures = ['core.Articles', 'core.Authors', 'core.Comments'];
 
     /**
+     * @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject
+     */
+    protected $company;
+
+    /**
+     * @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject
+     */
+    protected $client;
+
+    /**
+     * @var \Cake\Database\TypeMap
+     */
+    protected $companiesTypeMap;
+
+    /**
      * Set up
      */
     public function setUp(): void

+ 20 - 0
tests/TestCase/ORM/Association/HasManyTest.php

@@ -51,6 +51,26 @@ class HasManyTest extends TestCase
     ];
 
     /**
+     * @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject
+     */
+    protected $author;
+
+    /**
+     * @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject
+     */
+    protected $article;
+
+    /**
+     * @var \Cake\Database\TypeMap
+     */
+    protected $articlesTypeMap;
+
+    /**
+     * @var bool
+     */
+    protected $autoQuote;
+
+    /**
      * Set up
      */
     public function setUp(): void

+ 10 - 0
tests/TestCase/ORM/Association/HasOneTest.php

@@ -38,6 +38,16 @@ class HasOneTest extends TestCase
     protected $fixtures = ['core.Users', 'core.Profiles'];
 
     /**
+     * @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject
+     */
+    protected $user;
+
+    /**
+     * @var \Cake\ORM\Table|\PHPUnit\Framework\MockObject\MockObject
+     */
+    protected $profile;
+
+    /**
      * @var bool
      */
     protected $listenerCalled = false;

+ 25 - 0
tests/TestCase/ORM/Behavior/CounterCacheBehaviorTest.php

@@ -37,6 +37,31 @@ class CounterCacheBehaviorTest extends TestCase
     protected $post;
 
     /**
+     * @var \TestApp\Model\Table\PublishedPostsTable
+     */
+    protected $user;
+
+    /**
+     * @var \TestApp\Model\Table\PublishedPostsTable
+     */
+    protected $category;
+
+    /**
+     * @var \TestApp\Model\Table\PublishedPostsTable
+     */
+    protected $comment;
+
+    /**
+     * @var \TestApp\Model\Table\PublishedPostsTable
+     */
+    protected $userCategoryPosts;
+
+    /**
+     * @var \Cake\Datasource\ConnectionInterface
+     */
+    protected $connection;
+
+    /**
      * Fixture
      *
      * @var array<string>

+ 10 - 0
tests/TestCase/ORM/BehaviorRegistryTest.php

@@ -35,6 +35,16 @@ class BehaviorRegistryTest extends TestCase
     protected $Behaviors;
 
     /**
+     * @var \Cake\ORM\Table
+     */
+    protected $Table;
+
+    /**
+     * @var \Cake\Event\EventManagerInterface
+     */
+    protected $EventManager;
+
+    /**
      * setup method.
      */
     public function setUp(): void

+ 45 - 0
tests/TestCase/ORM/EagerLoaderTest.php

@@ -31,6 +31,51 @@ use InvalidArgumentException;
 class EagerLoaderTest extends TestCase
 {
     /**
+     * @var \Cake\Datasource\ConnectionInterface
+     */
+    protected $connection;
+
+    /**
+     * @var \Cake\ORM\Table
+     */
+    protected $table;
+
+    /**
+     * @var \Cake\Database\TypeMap
+     */
+    protected $clientsTypeMap;
+
+    /**
+     * @var \Cake\Database\TypeMap
+     */
+    protected $ordersTypeMap;
+
+    /**
+     * @var \Cake\Database\TypeMap
+     */
+    protected $orderTypesTypeMap;
+
+    /**
+     * @var \Cake\Database\TypeMap
+     */
+    protected $stuffTypeMap;
+
+    /**
+     * @var \Cake\Database\TypeMap
+     */
+    protected $stuffTypesTypeMap;
+
+    /**
+     * @var \Cake\Database\TypeMap
+     */
+    protected $companiesTypeMap;
+
+    /**
+     * @var \Cake\Database\TypeMap
+     */
+    protected $categoriesTypeMap;
+
+    /**
      * setUp method
      */
     public function setUp(): void

+ 5 - 0
tests/TestCase/ORM/ResultSetTest.php

@@ -46,6 +46,11 @@ class ResultSetTest extends TestCase
     protected $fixtureData;
 
     /**
+     * @var \Cake\Datasource\ConnectionInterface
+     */
+    protected $connection;
+
+    /**
      * setup
      */
     public function setUp(): void

+ 2 - 2
tests/TestCase/ORM/SaveOptionsBuilderTest.php

@@ -48,10 +48,10 @@ class SaveOptionsBuilderTest extends TestCase
     public function setUp(): void
     {
         parent::setUp();
-        $this->connection = ConnectionManager::get('test');
+        $connection = ConnectionManager::get('test');
         $this->table = new Table([
             'table' => 'articles',
-            'connection' => $this->connection,
+            'connection' => $connection,
         ]);
 
         $this->table->belongsTo('Authors');

+ 0 - 1
tests/TestCase/ORM/TableComplexIdTest.php

@@ -41,7 +41,6 @@ class TableComplexIdTest extends TestCase
     public function setUp(): void
     {
         parent::setUp();
-        $this->connection = ConnectionManager::get('test');
         static::setAppNamespace();
     }
 

+ 7 - 2
tests/TestCase/Utility/XmlTest.php

@@ -35,12 +35,17 @@ use TypeError;
 class XmlTest extends TestCase
 {
     /**
+     * @var string
+     */
+    protected $appEncoding;
+
+    /**
      * setUp method
      */
     public function setUp(): void
     {
         parent::setUp();
-        $this->_appEncoding = Configure::read('App.encoding');
+        $this->appEncoding = Configure::read('App.encoding');
         Configure::write('App.encoding', 'UTF-8');
     }
 
@@ -50,7 +55,7 @@ class XmlTest extends TestCase
     public function tearDown(): void
     {
         parent::tearDown();
-        Configure::write('App.encoding', $this->_appEncoding);
+        Configure::write('App.encoding', $this->appEncoding);
     }
 
     public function testExceptionChainingForInvalidInput(): void

+ 9 - 1
tests/phpstan.neon

@@ -4,7 +4,15 @@ parameters:
 	bootstrapFiles:
 		- bootstrap.php
 	paths:
-		- TestCase/
+		- TestCase/Collection/
+		- TestCase/Core/
+		- TestCase/Database/
+		- TestCase/Datasource/
+		- TestCase/Event/
+		- TestCase/ORM/
+		- TestCase/Utility/
+		- TestCase/Validation/
+
 	earlyTerminatingMethodCalls:
 		Cake\Console\Shell:
 			- abort