8136bfe3a88e3896cb3c30016a79db995edb6dea
[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 * 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 require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('extbase') . 'Tests/Unit/Object/Container/Fixtures/Testclasses.php';
18
19 /**
20 * Test case
21 */
22 class ClassInfoFactoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
23
24 /**
25 * @var \TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory
26 */
27 protected $classInfoFactory;
28
29 /**
30 * Set up
31 */
32 public function setUp() {
33 $this->classInfoFactory = new \TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory();
34 }
35
36 /**
37 * @test
38 * @expectedException \TYPO3\CMS\Extbase\Object\Container\Exception\UnknownObjectException
39 */
40 public function buildClassInfoFromClassNameThrowsExceptionIfGivenClassNameCantBeReflected() {
41 $this->classInfoFactory->buildClassInfoFromClassName('SomeNonExistingClass');
42 }
43
44 /**
45 * @test
46 */
47 public function buildClassInfoDoesNotIncludeInjectSettingsMethodInListOfInjectMethods() {
48 $classInfo = $this->classInfoFactory->buildClassInfoFromClassName('t3lib_object_tests_class_with_injectsettings');
49 $this->assertEquals(array('injectFoo' => 't3lib_object_tests_resolveablecyclic1'), $classInfo->getInjectMethods());
50 }
51
52 /**
53 * @test
54 */
55 public function buildClassInfoDetectsPropertiesToInjectByAnnotation() {
56 $classInfo = $this->classInfoFactory->buildClassInfoFromClassName('TYPO3\\CMS\\Extbase\\Tests\\Fixture\\ClassWithInjectProperties');
57 $this->assertEquals(array('secondDummyClass' => 'TYPO3\\CMS\\Extbase\\Tests\\Fixture\\SecondDummyClass'), $classInfo->getInjectProperties());
58 }
59
60 /**
61 * @test
62 */
63 public function buildClassInfoReturnsCustomClassInfoForDateTime() {
64
65 /** @var \PHPUnit_Framework_MockObject_MockObject | \TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory $classInfoFactory */
66 $classInfoFactory = $this->getMock('TYPO3\CMS\Extbase\Object\Container\ClassInfoFactory', array('dummy'));
67 $classInfoFactory->expects($this->never())->method('getConstructorArguments');
68
69 $classInfo = $classInfoFactory->buildClassInfoFromClassName('DateTime');
70 $this->assertEquals(
71 new \TYPO3\CMS\Extbase\Object\Container\ClassInfo('DateTime', array(), array(), FALSE, FALSE, array()),
72 $classInfo
73 );
74 }
75 }