[TASK] Use new instead of makeInstance in unit tests 69/49169/5
authorMinh-Thien Nhan <minh-thien.nhan@dkd.de>
Fri, 22 Jul 2016 12:05:34 +0000 (14:05 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 22 Jul 2016 13:25:43 +0000 (15:25 +0200)
Instantiating test subject in unit tests with makeInstance()
is not a good thing since this may trigger xclass and
singleton patterns. This is not wanted. Use new() instead.

Releases: master
Resolves: #77216
Change-Id: Ibb447aa3318653c1ca4f268937dec8d6f88d93c5
Reviewed-on: https://review.typo3.org/49169
Reviewed-by: Ivan Dharma Kartolo <ivan.kartolo@gmail.com>
Tested-by: Ivan Dharma Kartolo <ivan.kartolo@gmail.com>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/install/Tests/Unit/Service/SqlSchemaMigrationServiceTest.php
typo3/sysext/saltedpasswords/Tests/Unit/Salt/BlowfishSaltTest.php
typo3/sysext/saltedpasswords/Tests/Unit/Salt/Md5SaltTest.php
typo3/sysext/saltedpasswords/Tests/Unit/Salt/Pbkdf2SaltTest.php
typo3/sysext/saltedpasswords/Tests/Unit/Salt/PhpassSaltTest.php
typo3/sysext/saltedpasswords/Tests/Unit/Salt/SaltFactoryTest.php

index 0b069cd..d3b7ff6 100644 (file)
@@ -14,7 +14,6 @@ namespace TYPO3\CMS\Install\Tests\Unit\Service;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Install\Service\SqlSchemaMigrationService;
 
 /**
@@ -45,7 +44,10 @@ class SqlSchemaMigrationServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         /** @var \TYPO3\CMS\Dbal\Database\DatabaseConnection|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $databaseConnection */
         $databaseConnection = $this->getAccessibleMock(\TYPO3\CMS\Dbal\Database\DatabaseConnection::class, array('dummy'), array(), '', false);
-        $databaseConnection->_set('dbmsSpecifics', GeneralUtility::makeInstance(\TYPO3\CMS\Dbal\Database\Specifics\PostgresSpecifics::class));
+        $databaseConnection->_set(
+            'dbmsSpecifics',
+            new \TYPO3\CMS\Dbal\Database\Specifics\PostgresSpecifics()
+        );
 
         $subject = $this->getAccessibleMock(SqlSchemaMigrationService::class, array('isDbalEnabled', 'getDatabaseConnection'), array(), '', false);
         $subject->expects($this->any())->method('isDbalEnabled')->will($this->returnValue(true));
index 30ae4b3..3892b7e 100644 (file)
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Saltedpasswords\Tests\Unit\Salt;
  */
 
 use TYPO3\CMS\Core\Crypto\Random;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Testcase for BlowfishSalt
@@ -112,7 +111,7 @@ class BlowfishSaltTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $this->skipTestIfBlowfishIsNotAvailable();
         $password = 'password';
         // custom salt without setting
-        $randomBytes = GeneralUtility::makeInstance(Random::class)->generateRandomBytes($this->objectInstance->getSaltLength());
+        $randomBytes = (new Random())->generateRandomBytes($this->objectInstance->getSaltLength());
         $salt = $this->objectInstance->base64Encode($randomBytes, $this->objectInstance->getSaltLength());
         $this->assertTrue($this->objectInstance->isValidSalt($salt));
         $saltedHashPassword = $this->objectInstance->getHashedPassword($password, $salt);
index 200c7b9..8f9ca3d 100644 (file)
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Saltedpasswords\Tests\Unit\Salt;
  */
 
 use TYPO3\CMS\Core\Crypto\Random;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Testcases for Md5Salt
@@ -111,7 +110,7 @@ class Md5SaltTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $password = 'password';
         // custom salt without setting
-        $randomBytes = GeneralUtility::makeInstance(Random::class)->generateRandomBytes($this->objectInstance->getSaltLength());
+        $randomBytes = (new Random())->generateRandomBytes($this->objectInstance->getSaltLength());
         $salt = $this->objectInstance->base64Encode($randomBytes, $this->objectInstance->getSaltLength());
         $this->assertTrue($this->objectInstance->isValidSalt($salt), $this->getWarningWhenMethodUnavailable());
         $saltedHashPassword = $this->objectInstance->getHashedPassword($password, $salt);
index 4b16184..d92354c 100644 (file)
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Saltedpasswords\Tests\Unit\Salt;
  */
 
 use TYPO3\CMS\Core\Crypto\Random;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Saltedpasswords\Salt\Pbkdf2Salt;
 
 /**
@@ -100,7 +99,7 @@ class Pbkdf2SaltTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $password = 'password';
         // custom salt without setting
-        $randomBytes = GeneralUtility::makeInstance(Random::class)->generateRandomBytes($this->objectInstance->getSaltLength());
+        $randomBytes = (new Random())->generateRandomBytes($this->objectInstance->getSaltLength());
         $salt = $this->objectInstance->base64Encode($randomBytes, $this->objectInstance->getSaltLength());
         $this->assertTrue($this->objectInstance->isValidSalt($salt));
         $saltedHashPassword = $this->objectInstance->getHashedPassword($password, $salt);
index ae64e24..9262671 100644 (file)
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Saltedpasswords\Tests\Unit\Salt;
  */
 
 use TYPO3\CMS\Core\Crypto\Random;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Testcase for PhpassSalt
@@ -97,7 +96,7 @@ class PhpassSaltTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     {
         $password = 'password';
         // custom salt without setting
-        $randomBytes = GeneralUtility::makeInstance(Random::class)->generateRandomBytes($this->objectInstance->getSaltLength());
+        $randomBytes = (new Random())->generateRandomBytes($this->objectInstance->getSaltLength());
         $salt = $this->objectInstance->base64Encode($randomBytes, $this->objectInstance->getSaltLength());
         $this->assertTrue($this->objectInstance->isValidSalt($salt));
         $saltedHashPassword = $this->objectInstance->getHashedPassword($password, $salt);
index 52f0657..c6c08af 100644 (file)
@@ -15,7 +15,6 @@ namespace TYPO3\CMS\Saltedpasswords\Tests\Unit\Salt;
  */
 
 use TYPO3\CMS\Core\Crypto\Random;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Testcase for SaltFactory
@@ -77,13 +76,13 @@ class SaltFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         // used for MD5 and PHPass salted hashing
         $byteLength = 3;
         $reqLengthBase64 = (int)ceil($byteLength * 8 / 6);
-        $randomBytes = GeneralUtility::makeInstance(Random::class)->generateRandomBytes($byteLength);
+        $randomBytes = (new Random())->generateRandomBytes($byteLength);
         $this->assertTrue(strlen($this->objectInstance->base64Encode($randomBytes, $byteLength)) == $reqLengthBase64);
         // 16 Bytes should result in a 22 char length base64 encoded string
         // used for Blowfish salted hashing
         $byteLength = 16;
         $reqLengthBase64 = (int)ceil($byteLength * 8 / 6);
-        $randomBytes = GeneralUtility::makeInstance(Random::class)->generateRandomBytes($byteLength);
+        $randomBytes = (new Random())->generateRandomBytes($byteLength);
         $this->assertTrue(strlen($this->objectInstance->base64Encode($randomBytes, $byteLength)) == $reqLengthBase64);
     }