[BUGFIX] Better mocking in FAL FileTest 95/24695/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 13 Oct 2013 12:47:48 +0000 (14:47 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 13 Oct 2013 13:23:40 +0000 (15:23 +0200)
Another test is changed to full mocking and testing only the concern.

Change-Id: I90001650246a6856a07539a4b05f7e926d9329b8
Resolves: #52750
Releases: 6.2
Reviewed-on: https://review.typo3.org/24695
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Tests/Unit/Resource/FileTest.php

index 42d1c24..e12bede 100644 (file)
@@ -47,8 +47,6 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->singletonInstances = \TYPO3\CMS\Core\Utility\GeneralUtility::getSingletonInstances();
                $this->storageMock = $this->getMock('TYPO3\CMS\Core\Resource\ResourceStorage', array(), array(), '', FALSE);
                $this->storageMock->expects($this->any())->method('getUid')->will($this->returnValue(5));
-
-               \TYPO3\CMS\Core\Utility\GeneralUtility::purgeInstances();
        }
 
        public function tearDown() {
@@ -186,15 +184,25 @@ class FileTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function updatePropertiesReloadsStorageObjectIfStorageChanges() {
+               $fileProperties = array(
+                       'uid' => 1,
+                       'storage' => 'first',
+               );
+               $sut = $this->getMock(
+                       'TYPO3\\CMS\\Core\\Resource\\File',
+                       array('loadStorage'),
+                       array($fileProperties, $this->storageMock)
+               );
                $mockedNewStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
-               $mockedOldStorage = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE);
-               $mockedOldStorage->expects($this->any())->method('getUid')->will($this->returnValue(1));
-               $fixture = new \TYPO3\CMS\Core\Resource\File(array('uid' => 1, 'foo' => 'asdf', 'baz' => 'fdsw', 'identifier' => '/test', 'storage' => 1), $mockedOldStorage);
                $mockedResourceFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
-               $mockedResourceFactory->expects($this->once())->method('getStorageObject')->with(2)->will($this->returnValue($mockedNewStorage));
+               $mockedResourceFactory
+                       ->expects($this->once())
+                       ->method('getStorageObject')
+                       ->will($this->returnValue($mockedNewStorage));
                \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', $mockedResourceFactory);
-               $fixture->updateProperties(array('storage' => 2));
-               $this->assertSame($mockedNewStorage, $fixture->getStorage());
+
+               $sut->updateProperties(array('storage' => 'different'));
+               $this->assertSame($mockedNewStorage, $sut->getStorage());
        }
 
        /**