[FEATURE] Support @Flow\Inject annotations in Extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Object / Container / ClassInfoFactoryTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Object\Container;
3
4 /***************************************************************
5 * Copyright notice
6 * (c) 2010 Daniel Pötzinger
7 * (c) 2010 Bastian Waidelich <bastian@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('extbase') . 'Tests/Unit/Object/Container/Fixtures/Testclasses.php';
27
28 /**
29 * Testcase for class t3lib_object_ClassInfoFactory.
30 *
31 * @author Daniel Pötzinger
32 * @author Bastian Waidelich <bastian@typo3.org>
33 */
34 class ClassInfoFactoryTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
35
36 /**
37 * @var \TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory
38 */
39 private $classInfoFactory;
40
41 /**
42
43 */
44 public function setUp() {
45 $this->classInfoFactory = new \TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory();
46 }
47
48 /**
49 * @test
50 * @expectedException \TYPO3\CMS\Extbase\Object\Container\Exception\UnknownObjectException
51 */
52 public function buildClassInfoFromClassNameThrowsExceptionIfGivenClassNameCantBeReflected() {
53 $this->classInfoFactory->buildClassInfoFromClassName('SomeNonExistingClass');
54 }
55
56 /**
57 * @test
58 */
59 public function buildClassInfoDoesNotIncludeInjectSettingsMethodInListOfInjectMethods() {
60 $classInfo = $this->classInfoFactory->buildClassInfoFromClassName('t3lib_object_tests_class_with_injectsettings');
61 $this->assertEquals(array('injectFoo' => 't3lib_object_tests_resolveablecyclic1'), $classInfo->getInjectMethods());
62 }
63
64 /**
65 * @test
66 */
67 public function buildClassInfoDetectsPropertiesToInjectByAnnotation() {
68 $classInfo = $this->classInfoFactory->buildClassInfoFromClassName('TYPO3\\CMS\\Extbase\\Tests\\Fixture\\ClassWithInjectProperties');
69 $this->assertEquals(
70 array(
71 'secondDummyClass' => 'TYPO3\\CMS\\Extbase\\Tests\\Fixture\\SecondDummyClass',
72 'secondDummyClassWithFlowInject' => 'TYPO3\\CMS\\Extbase\\Tests\\Fixture\\SecondDummyClass'
73 ),
74 $classInfo->getInjectProperties()
75 );
76 }
77
78 /**
79 * @test
80 */
81 public function buildClassInfoReturnsCustomClassInfoForDateTime() {
82
83 /** @var \PHPUnit_Framework_MockObject_MockObject | \TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory $classInfoFactory */
84 $classInfoFactory = $this->getMock('TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory', array('dummy'));
85 $classInfoFactory->expects($this->never())->method('getConstructorArguments');
86
87 $classInfo = $classInfoFactory->buildClassInfoFromClassName('DateTime');
88 $this->assertEquals(
89 new \TYPO3\CMS\Extbase\Object\Container\ClassInfo('DateTime', array(), array(), FALSE, FALSE, array()),
90 $classInfo
91 );
92 }
93 }
94
95 ?>