[BUGFIX] Incomplete mocking in FAL IndexerServiceTest
authorChristian Kuhn <lolli@schwarzbu.ch>
Wed, 31 Oct 2012 22:19:45 +0000 (23:19 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 31 Oct 2012 22:29:13 +0000 (23:29 +0100)
Incomplete mocking of FileRepository leads to warnings
in unit tests.

Resolves: #42575
Releases: 6.0

Change-Id: Ib0dc85de2575d38b87e482f0ad113aad27d46014
Reviewed-on: http://review.typo3.org/16092
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Tests/Unit/Resource/Service/IndexerServiceTest.php

index eb1eeff..1dcc89f 100644 (file)
@@ -66,19 +66,29 @@ class IndexerServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function indexFileUpdatesFileProperties() {
+               /** @var $fixture \TYPO3\CMS\Core\Resource\Service\IndexerService|\PHPUnit_Framework_MockObject_MockObject */
+               $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', array('gatherFileInformation', 'getRepository'));
+
                $fileInfo = array(
                        'mount' => 1,
                        'identifier' => '/some/filepath/filename.jpg',
                        'size' => 1234,
-                       'uid' => rand(1, 100)
+                       'uid' => rand(1, 100),
+                       'sha1' => '123',
                );
-               /** @var $fixture \TYPO3\CMS\Core\Resource\Service\IndexerService */
-               $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', array('gatherFileInformation'));
+
                $fixture->expects($this->any())->method('gatherFileInformation')->will($this->returnValue($fileInfo));
+
+               $repositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository', array('findBySha1Hash'));
+               $repositoryMock->expects($this->any())->method('findBySha1Hash')->will($this->returnValue(array()));
+               $fixture->expects($this->any())->method('getRepository')->will($this->returnValue($repositoryMock));
+
                $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
                $GLOBALS['TYPO3_DB']->expects($this->atLeastOnce())->method('sql_insert_id')->will($this->returnValue($fileInfo['uid']));
+
                $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
                $mockedFile->expects($this->once())->method('updateProperties')->with($this->equalTo($fileInfo));
+
                $fixture->indexFile($mockedFile);
        }
 
@@ -87,15 +97,23 @@ class IndexerServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         */
        public function indexFileSetsCreationdateAndTimestampPropertiesOfRecordToCurrentExecutionTime() {
                $fileInfo = array();
-               /** @var $fixture \TYPO3\CMS\Core\Resource\Service\IndexerService */
-               $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', array('gatherFileInformation'));
+               /** @var $fixture \TYPO3\CMS\Core\Resource\Service\IndexerService|\PHPUnit_Framework_MockObject_MockObject */
+               $fixture = $this->getMock('TYPO3\\CMS\\Core\\Resource\\Service\\IndexerService', array('gatherFileInformation', 'getRepository'));
+
                $fixture->expects($this->any())->method('gatherFileInformation')->will($this->returnValue($fileInfo));
+
+               $repositoryMock = $this->getMock('TYPO3\\CMS\\Core\\Resource\\FileRepository', array('findBySha1Hash'));
+               $repositoryMock->expects($this->any())->method('findBySha1Hash')->will($this->returnValue(array()));
+               $fixture->expects($this->any())->method('getRepository')->will($this->returnValue($repositoryMock));
+
                $GLOBALS['TYPO3_DB'] = $this->getMock('TYPO3\\CMS\\Core\\Database\\DatabaseConnection', array(), array(), '', FALSE);
                $GLOBALS['TYPO3_DB']->expects($this->once())->method('exec_INSERTquery')->with($this->anything(), $this->equalTo(array(
                        'crdate' => $GLOBALS['EXEC_TIME'],
                        'tstamp' => $GLOBALS['EXEC_TIME']
                )));
+
                $mockedFile = $this->getMock('TYPO3\\CMS\\Core\\Resource\\File', array(), array(), '', FALSE);
+
                $fixture->indexFile($mockedFile);
        }