TYPO3 CMS  TYPO3_8-7
OnTheFlyTest.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 
22 
26 class OnTheFlyTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
31  protected $subject;
32 
33  protected function setUp()
34  {
35  $this->subject = new OnTheFly();
36  }
37 
42  {
43  $this->expectException(\UnexpectedValueException::class);
44  $this->expectExceptionCode(1441108674);
45  $this->subject->compile([]);
46  }
47 
51  public function compileReturnsIncomingData()
52  {
54  $formDataProviderProphecy = $this->prophesize(FormDataProviderInterface::class);
55  GeneralUtility::addInstance(FormDataProviderInterface::class, $formDataProviderProphecy->reveal());
56  $formDataProviderProphecy->addData(Argument::cetera())->willReturnArgument(0);
57  $providerList = [
58  FormDataProviderInterface::class,
59  ];
60  $this->subject->setProviderList($providerList);
61 
62  $input = [
63  'foo',
64  ];
65 
66  $this->assertEquals($input, $this->subject->compile($input));
67  }
68 
72  public function compileReturnsResultChangedByDataProvider()
73  {
75  $formDataProviderProphecy = $this->prophesize(FormDataProviderInterface::class);
76  GeneralUtility::addInstance(FormDataProviderInterface::class, $formDataProviderProphecy->reveal());
77 
78  $providerList = [
79  FormDataProviderInterface::class,
80  ];
81  $this->subject->setProviderList($providerList);
82  $providerResult = ['foo'];
83  $formDataProviderProphecy->addData(Argument::cetera())->shouldBeCalled()->willReturn($providerResult);
84 
85  $this->assertEquals($providerResult, $this->subject->compile([]));
86  }
87 
91  public function compileThrowsExceptionIfDataProviderDoesNotImplementInterface()
92  {
94  $formDataProviderProphecy = $this->prophesize(\stdClass::class);
95  GeneralUtility::addInstance(\stdClass::class, $formDataProviderProphecy->reveal());
96  $providerList = [
97  \stdClass::class,
98  ];
99  $this->subject->setProviderList($providerList);
100 
101  $this->expectException(\UnexpectedValueException::class);
102  $this->expectExceptionCode(1441108719);
103  $this->subject->compile([]);
104  }
105 }
static addInstance($className, $instance)