[TASK] Use dedicated PHPUnit assertion methods 97/62097/4
authorAlexander Schnitzler <git@alexanderschnitzler.de>
Thu, 24 Oct 2019 13:23:32 +0000 (15:23 +0200)
committerDaniel Goerz <daniel.goerz@posteo.de>
Fri, 25 Oct 2019 08:08:41 +0000 (10:08 +0200)
PHPUnit assertion method calls like ::assertSame(true, $foo)
should be written with dedicated method like ::assertTrue($foo).

Releases: master
Resolves: #89501
Change-Id: I3d66794ea333ea114c64712c86a769e853a85dea
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62097
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Daniel Goerz <daniel.goerz@posteo.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Build/.php_cs
typo3/sysext/core/Tests/Unit/Imaging/IconRegistryTest.php
typo3/sysext/core/Tests/Unit/Site/Entity/SiteTest.php
typo3/sysext/core/Tests/Unit/Utility/RootlineUtilityTest.php
typo3/sysext/extbase/Tests/Unit/Mvc/Web/Routing/UriBuilderTest.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapperTest.php
typo3/sysext/frontend/Tests/Unit/ContentObject/ContentObjectRendererTest.php
typo3/sysext/linkvalidator/Tests/Unit/Linktype/ExternalLinktypeTest.php
typo3/sysext/redirects/Tests/Unit/Service/RedirectServiceTest.php

index 3edf1cf..717749f 100644 (file)
@@ -82,6 +82,7 @@ return PhpCsFixer\Config::create()
         'no_useless_else' => true,
         'no_whitespace_in_blank_line' => true,
         'ordered_imports' => true,
+        'php_unit_construct' => ['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame'],
         'php_unit_mock_short_will_return' => true,
         'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
         'phpdoc_no_access' => true,
index e825688..91dcc20 100644 (file)
@@ -224,6 +224,6 @@ class IconRegistryTest extends UnitTestCase
     public function getIconIdentifierForMimeTypeWithUnknowMimeTypeReturnNull()
     {
         $result = (new IconRegistry)->getIconIdentifierForMimeType('bar/foo');
-        self::assertEquals(null, $result);
+        self::assertNull($result);
     }
 }
index 8c2efe3..8a4548d 100644 (file)
@@ -152,9 +152,9 @@ class SiteTest extends UnitTestCase
         $fluidProphecy = $this->prophesize(FluidPageErrorHandler::class);
         GeneralUtility::addInstance(FluidPageErrorHandler::class, $fluidProphecy->reveal());
 
-        self::assertEquals(true, $subject->getErrorHandler(123) instanceof PageErrorHandlerInterface);
-        self::assertEquals(true, $subject->getErrorHandler(124) instanceof PageErrorHandlerInterface);
-        self::assertEquals(true, $subject->getErrorHandler(125) instanceof PageErrorHandlerInterface);
+        self::assertTrue($subject->getErrorHandler(123) instanceof PageErrorHandlerInterface);
+        self::assertTrue($subject->getErrorHandler(124) instanceof PageErrorHandlerInterface);
+        self::assertTrue($subject->getErrorHandler(125) instanceof PageErrorHandlerInterface);
     }
 
     /**
index 99d2a7a..a01f1f5 100644 (file)
@@ -177,7 +177,7 @@ class RootlineUtilityTest extends UnitTestCase
             ['uid' => 99, 'doktype' => PageRepository::DOKTYPE_MOUNTPOINT, 'mount_pid' => 1, 'mount_pid_ol' => 1]
         );
         self::assertTrue(isset($result['_MOUNT_OL']));
-        self::assertSame(true, $result['_MOUNT_OL']);
+        self::assertTrue($result['_MOUNT_OL']);
     }
 
     /**
index ddbf94d..ab06787 100644 (file)
@@ -116,16 +116,16 @@ class UriBuilderTest extends UnitTestCase
         self::assertEquals(['test' => 'arguments'], $this->uriBuilder->getArguments());
         self::assertEquals('testSection', $this->uriBuilder->getSection());
         self::assertEquals('testFormat', $this->uriBuilder->getFormat());
-        self::assertEquals(true, $this->uriBuilder->getCreateAbsoluteUri());
+        self::assertTrue($this->uriBuilder->getCreateAbsoluteUri());
         self::assertEquals('https', $this->uriBuilder->getAbsoluteUriScheme());
-        self::assertEquals(true, $this->uriBuilder->getAddQueryString());
+        self::assertTrue($this->uriBuilder->getAddQueryString());
         self::assertEquals(['test' => 'addQueryStringExcludeArguments'], $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
         self::assertEquals('GET', $this->uriBuilder->getAddQueryStringMethod());
         self::assertEquals('testArgumentPrefix', $this->uriBuilder->getArgumentPrefix());
-        self::assertEquals(true, $this->uriBuilder->getLinkAccessRestrictedPages());
+        self::assertTrue($this->uriBuilder->getLinkAccessRestrictedPages());
         self::assertEquals(123, $this->uriBuilder->getTargetPageUid());
         self::assertEquals(321, $this->uriBuilder->getTargetPageType());
-        self::assertEquals(true, $this->uriBuilder->getNoCache());
+        self::assertTrue($this->uriBuilder->getNoCache());
     }
 
     /**
@@ -543,17 +543,17 @@ class UriBuilderTest extends UnitTestCase
         self::assertEquals([], $this->uriBuilder->getArguments());
         self::assertEquals('', $this->uriBuilder->getSection());
         self::assertEquals('', $this->uriBuilder->getFormat());
-        self::assertEquals(false, $this->uriBuilder->getCreateAbsoluteUri());
-        self::assertEquals(false, $this->uriBuilder->getAddQueryString());
+        self::assertFalse($this->uriBuilder->getCreateAbsoluteUri());
+        self::assertFalse($this->uriBuilder->getAddQueryString());
         self::assertEquals([], $this->uriBuilder->getArgumentsToBeExcludedFromQueryString());
         self::assertEquals('', $this->uriBuilder->getAddQueryStringMethod());
         self::assertEquals('', $this->uriBuilder->getArgumentPrefix());
-        self::assertEquals(false, $this->uriBuilder->getLinkAccessRestrictedPages());
-        self::assertEquals(null, $this->uriBuilder->getTargetPageUid());
+        self::assertFalse($this->uriBuilder->getLinkAccessRestrictedPages());
+        self::assertNull($this->uriBuilder->getTargetPageUid());
         self::assertEquals(0, $this->uriBuilder->getTargetPageType());
-        self::assertEquals(false, $this->uriBuilder->getNoCache());
-        self::assertEquals(false, $this->uriBuilder->getNoCache());
-        self::assertEquals(null, $this->uriBuilder->getAbsoluteUriScheme());
+        self::assertFalse($this->uriBuilder->getNoCache());
+        self::assertFalse($this->uriBuilder->getNoCache());
+        self::assertNull($this->uriBuilder->getAbsoluteUriScheme());
     }
 
     /**
index a0474a7..8cdbb53 100644 (file)
@@ -116,7 +116,8 @@ class DataMapperTest extends UnitTestCase
             'pid' => new ColumnMap('pid', 'pid'),
             'firstProperty' => new ColumnMap('firstProperty', 'firstProperty'),
             'secondProperty' => new ColumnMap('secondProperty', 'secondProperty'),
-            'thirdProperty' => new ColumnMap('thirdProperty', 'thirdProperty')
+            'thirdProperty' => new ColumnMap('thirdProperty', 'thirdProperty'),
+            'fourthProperty' => new ColumnMap('fourthProperty', 'fourthProperty')
         ];
         $dataMap = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMap::class, ['dummy'], [$className, $className]);
         $dataMap->_set('columnMaps', $columnMaps);
@@ -149,7 +150,7 @@ class DataMapperTest extends UnitTestCase
         self::assertEquals('firstValue', $object->firstProperty);
         self::assertEquals(1234, $object->secondProperty);
         self::assertEquals(1.234, $object->thirdProperty);
-        self::assertEquals(false, $object->fourthProperty);
+        self::assertFalse($object->fourthProperty);
     }
 
     /**
@@ -172,7 +173,7 @@ class DataMapperTest extends UnitTestCase
         $dataMapper = $this->getAccessibleMock(DataMapper::class, ['getDataMap'], [], '', false);
         $dataMapper->expects(self::any())->method('getDataMap')->willReturn($dataMap);
         $result = $dataMapper->_call('fetchRelatedEager', $this->createMock(\TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class), 'SomeName', '');
-        self::assertEquals(null, $result);
+        self::assertNull($result);
     }
 
     /**
@@ -220,7 +221,7 @@ class DataMapperTest extends UnitTestCase
         $dataMapper->expects(self::any())->method('getDataMap')->willReturn($dataMap);
         $dataMapper->expects(self::never())->method('fetchRelated');
         $result = $dataMapper->_call('mapObjectToClassProperty', $this->createMock(\TYPO3\CMS\Extbase\DomainObject\AbstractEntity::class), 'SomeName', '');
-        self::assertEquals(null, $result);
+        self::assertNull($result);
     }
 
     /**
index ed55878..30840be 100644 (file)
@@ -1676,8 +1676,8 @@ class ContentObjectRendererTest extends UnitTestCase
         GeneralUtility::setSingletonInstance(Context::class, $context);
         self::assertEquals(3, $this->subject->getData('context:workspace:id'));
         self::assertEquals('0,-1', $this->subject->getData('context:frontend.user:groupIds'));
-        self::assertEquals(false, $this->subject->getData('context:frontend.user:isLoggedIn'));
-        self::assertEquals(false, $this->subject->getData('context:frontend.user:foozball'));
+        self::assertFalse($this->subject->getData('context:frontend.user:isLoggedIn'));
+        self::assertSame('', $this->subject->getData('context:frontend.user:foozball'));
     }
 
     /**
index 3947e44..7d8ef48 100644 (file)
@@ -70,7 +70,7 @@ class ExternalLinktypeTest extends UnitTestCase
 
         $result = $subject->checkLink($url, null, null);
 
-        self::assertSame(false, $result);
+        self::assertFalse($result);
     }
 
     /**
index 7ed9946..d6e9226 100644 (file)
@@ -239,7 +239,7 @@ class RedirectServiceTest extends UnitTestCase
 
         $result = $this->redirectService->matchRedirect('example.com', 'index.php', 'id=123&a=a');
 
-        self::assertSame(null, $result);
+        self::assertNull($result);
     }
 
     /**