[TASK] Use real ObjectManager stubs in unit tests
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Task / UpdateExtensionListTaskTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Task;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Extensionmanager\Task\UpdateExtensionListTask;
18 use TYPO3\CMS\Extensionmanager\Utility\Repository\Helper;
19 use TYPO3\CMS\Scheduler\Task\AbstractTask;
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21
22 /**
23 * Test case
24 */
25 class UpdateExtensionListTaskTest extends UnitTestCase
26 {
27 /**
28 * @var bool Reset singletons created by subject
29 */
30 protected $resetSingletonInstances = true;
31
32 /**
33 * @test
34 */
35 public function updateExtensionListTaskIsInstanceOfAbstractTask()
36 {
37 $taskMock = $this->getMockBuilder(UpdateExtensionListTask::class)->getMock();
38 $this->assertInstanceOf(AbstractTask::class, $taskMock);
39 }
40
41 /**
42 * @test
43 */
44 public function executeCallsUpdateExtListOfRepositoryHelper()
45 {
46 $repositoryHelper = $this->createMock(Helper::class);
47 $repositoryHelper
48 ->expects($this->once())
49 ->method('updateExtList');
50
51 $objectManagerMock = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
52 $objectManagerMock
53 ->expects($this->at(0))
54 ->method('get')
55 ->with(Helper::class)
56 ->will($this->returnValue($repositoryHelper));
57
58 $persistenceManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class)->getMock();
59 $objectManagerMock
60 ->expects($this->at(1))
61 ->method('get')
62 ->will($this->returnValue($persistenceManagerMock));
63
64 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $objectManagerMock);
65
66 $task = $this->getMockBuilder(UpdateExtensionListTask::class)
67 ->setMethods(['dummy'])
68 ->disableOriginalConstructor()
69 ->getMock();
70 $task->execute();
71 }
72
73 /**
74 * @test
75 */
76 public function executeCallsPersistAllOnPersistenceManager()
77 {
78 $repositoryHelper = $this->createMock(Helper::class);
79 $objectManagerMock = $this->createMock(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
80 $objectManagerMock
81 ->expects($this->at(0))
82 ->method('get')
83 ->with(Helper::class)
84 ->will($this->returnValue($repositoryHelper));
85
86 $persistenceManagerMock = $this->getMockBuilder(\TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager::class)->getMock();
87 $persistenceManagerMock
88 ->expects($this->once())
89 ->method('persistAll');
90
91 $objectManagerMock
92 ->expects($this->at(1))
93 ->method('get')
94 ->will($this->returnValue($persistenceManagerMock));
95
96 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class, $objectManagerMock);
97
98 /** @var UpdateExtensionListTask|PHPUnit_Framework_MockObject_MockObject $task */
99 $task = $this->getMockBuilder(UpdateExtensionListTask::class)
100 ->setMethods(['dummy'])
101 ->disableOriginalConstructor()
102 ->getMock();
103 $task->execute();
104 }
105 }