TYPO3 CMS  TYPO3_8-7
OrderedProviderListTest.php
Go to the documentation of this file.
1 <?php
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 
23 
27 class OrderedProviderListTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
28 {
32  protected $subject;
33 
34  protected function setUp()
35  {
36  $this->subject = new OrderedProviderList();
37  }
38 
42  public function compileReturnsIncomingData()
43  {
45  $orderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
46  GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceProphecy->reveal());
47  $orderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
48 
49  $input = ['foo'];
50 
51  $this->subject->setProviderList([]);
52  $this->assertEquals($input, $this->subject->compile($input));
53  }
54 
58  public function compileReturnsResultChangedByDataProvider()
59  {
61  $orderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
62  GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceProphecy->reveal());
63  $orderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
64 
66  $formDataProviderProphecy = $this->prophesize(FormDataProviderInterface::class);
67  GeneralUtility::addInstance(FormDataProviderInterface::class, $formDataProviderProphecy->reveal());
68  $providerResult = ['foo'];
69  $formDataProviderProphecy->addData(Argument::cetera())->shouldBeCalled()->willReturn($providerResult);
70 
71  $this->subject->setProviderList([
72  FormDataProviderInterface::class => [],
73  ]);
74  $this->assertEquals($providerResult, $this->subject->compile([]));
75  }
76 
80  public function compileThrowsExceptionIfDataProviderDoesNotImplementInterface()
81  {
83  $orderingServiceProphecy = $this->prophesize(DependencyOrderingService::class);
84  GeneralUtility::addInstance(DependencyOrderingService::class, $orderingServiceProphecy->reveal());
85  $orderingServiceProphecy->orderByDependencies(Argument::cetera())->willReturnArgument(0);
86 
88  $formDataProviderProphecy = $this->prophesize(\stdClass::class);
89  GeneralUtility::addInstance(\stdClass::class, $formDataProviderProphecy->reveal());
90 
91  $this->expectException(\UnexpectedValueException::class);
92  $this->expectExceptionCode(1485299408);
93 
94  $this->subject->setProviderList([
95  \stdClass::class => [],
96  ]);
97  $this->subject->compile([]);
98  }
99 }
static addInstance($className, $instance)