[BUGFIX] Unit tests call parent::tearDown() 62/55762/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 16 Feb 2018 18:25:12 +0000 (19:25 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 16 Feb 2018 19:05:29 +0000 (20:05 +0100)
For the memory garbage collection of UnitTestCase to kick in,
it is important that unit tests which implement tearDown()
call parent after their own job.

Fix some missing parent calls, refactor some other tests
slightly to live without tearDown() and activate two tests
that come with an invalid @depends annotation.

Change-Id: I51c7534ea3220ec63fd8c3efa94e8bf295590e68
Resolves: #83944
Releases: master, 8.7
Reviewed-on: https://review.typo3.org/55762
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/TcaRecordTitleTest.php
typo3/sysext/core/Tests/Unit/Database/RelationHandlerTest.php
typo3/sysext/core/Tests/Unit/Http/ServerRequestTest.php
typo3/sysext/core/Tests/Unit/Http/UploadedFileTest.php
typo3/sysext/core/Tests/Unit/Imaging/IconProvider/SvgIconProviderTest.php
typo3/sysext/extbase/Tests/Unit/Utility/LocalizationUtilityTest.php
typo3/sysext/form/Tests/Unit/Mvc/Property/PropertyMappingConfigurationTest.php

index 9023cb2..8ded176 100644 (file)
@@ -44,6 +44,7 @@ class TcaRecordTitleTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     protected function tearDown()
     {
         date_default_timezone_set($this->timeZone);
+        parent::tearDown();
     }
 
     /**
index c7377d0..08701cb 100644 (file)
@@ -34,13 +34,6 @@ class RelationHandlerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     }
 
     /**
-     */
-    protected function tearDown()
-    {
-        unset($this->subject);
-    }
-
-    /**
      * @test
      */
     public function purgeItemArrayReturnsFalseIfVersioningForTableIsDisabled()
index e1deada..980162a 100644 (file)
@@ -117,7 +117,6 @@ class ServerRequestTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     }
 
     /**
-     * @depends testAttributesAreEmptyByDefault
      * @test
      */
     public function withAttributeMutatorReturnsCloneWithChanges()
@@ -130,11 +129,11 @@ class ServerRequestTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     }
 
     /**
-     * @depends testAttributeMutatorReturnsCloneWithChanges
      * @test
      */
-    public function withoutAttributeReturnsCloneWithoutAttribute($request)
+    public function withoutAttributeReturnsCloneWithoutAttribute()
     {
+        $request = $this->request;
         $new = $request->withoutAttribute('foo');
         $this->assertNotSame($request, $new);
         $this->assertNull($new->getAttribute('foo', null));
index 1fa0312..bf5794b 100644 (file)
@@ -37,6 +37,7 @@ class UploadedFileTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         if (is_scalar($this->tmpFile) && file_exists($this->tmpFile)) {
             unlink($this->tmpFile);
         }
+        parent::tearDown();
     }
 
     /**
index 101b320..cb2930b 100644 (file)
@@ -34,11 +34,6 @@ class SvgIconProviderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
     protected $icon = null;
 
     /**
-     * @var string
-     */
-    protected $testFileName;
-
-    /**
      * Set up
      */
     protected function setUp()
@@ -47,18 +42,6 @@ class SvgIconProviderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
         $this->icon = GeneralUtility::makeInstance(Icon::class);
         $this->icon->setIdentifier('foo');
         $this->icon->setSize(Icon::SIZE_SMALL);
-
-        $svgTestFileContent = '<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="#CD201F" d="M11 12l3-2v6H2v-6l3 2 3-2 3 2z"></path><script><![CDATA[ function alertMe() {} ]]></script></svg>';
-        $this->testFileName = GeneralUtility::tempnam(uniqid('svg_') . '.svg');
-        file_put_contents($this->testFileName, $svgTestFileContent);
-    }
-
-    /**
-     * Tear down
-     */
-    protected function tearDown()
-    {
-        unlink($this->testFileName);
     }
 
     /**
@@ -93,7 +76,12 @@ class SvgIconProviderTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      */
     public function getIconWithInlineOptionReturnsCleanSvgMarkup()
     {
-        $this->subject->prepareIconMarkup($this->icon, ['source' => $this->testFileName]);
+        $testFile = GeneralUtility::tempnam(uniqid('svg_') . '.svg');
+        $this->testFilesToDelete[] = $testFile;
+        $svgTestFileContent = '<?xml version="1.0" encoding="ISO-8859-1" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="#CD201F" d="M11 12l3-2v6H2v-6l3 2 3-2 3 2z"></path><script><![CDATA[ function alertMe() {} ]]></script></svg>';
+        file_put_contents($testFile, $svgTestFileContent);
+        $this->testFilesToDelete[] = GeneralUtility::tempnam(uniqid('svg_') . '.svg');
+        $this->subject->prepareIconMarkup($this->icon, ['source' => $testFile]);
         $this->assertEquals('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="#CD201F" d="M11 12l3-2v6H2v-6l3 2 3-2 3 2z"/></svg>', $this->icon->getMarkup(SvgIconProvider::MARKUP_IDENTIFIER_INLINE));
     }
 }
index f1719e8..cd38091 100644 (file)
@@ -181,6 +181,8 @@ class LocalizationUtilityTest extends \TYPO3\TestingFramework\Core\Unit\UnitTest
         $property = $reflectionClass->getProperty('alternativeLanguageKeys');
         $property->setAccessible(true);
         $property->setValue([]);
+
+        parent::tearDown();
     }
 
     /**
index d1174e3..9db47d3 100644 (file)
@@ -88,6 +88,7 @@ class PropertyMappingConfigurationTest extends UnitTestCase
     {
         // Remove all singleton instances
         GeneralUtility::resetSingletonInstances($this->singletons);
+        parent::tearDown();
     }
 
     /**