Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 183 lines (158 sloc) 4.845 kb
edda8afa »
2012-03-28 moved component and bridge unit tests to the src/ directory
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\ClassLoader\Tests;
13
14 use Symfony\Component\ClassLoader\ClassCollectionLoader;
15
9c929006 »
2012-07-10 [ClassLoader] fixed order of interfaces in generated class collection…
16 require_once __DIR__.'/Fixtures/ClassesWithParents/GInterface.php';
5828147f »
2012-07-03 fixed unit tests
17 require_once __DIR__.'/Fixtures/ClassesWithParents/CInterface.php';
18 require_once __DIR__.'/Fixtures/ClassesWithParents/B.php';
19 require_once __DIR__.'/Fixtures/ClassesWithParents/A.php';
20
edda8afa »
2012-03-28 moved component and bridge unit tests to the src/ directory
21 class ClassCollectionLoaderTest extends \PHPUnit_Framework_TestCase
22 {
a04dde5a »
2012-07-02 [ClassLoader] ordered ClassCollectionLoader writing to avoid redeclar…
23 /**
24 * @dataProvider getDifferentOrders
25 */
26 public function testClassReordering(array $classes)
27 {
685dd120 »
2012-07-03 [ClassLoader] made ClassCollectionLoader::load() automatically includ…
28 $expected = array(
9c929006 »
2012-07-10 [ClassLoader] fixed order of interfaces in generated class collection…
29 'ClassesWithParents\\GInterface',
685dd120 »
2012-07-03 [ClassLoader] made ClassCollectionLoader::load() automatically includ…
30 'ClassesWithParents\\CInterface',
31 'ClassesWithParents\\B',
32 'ClassesWithParents\\A',
33 );
a04dde5a »
2012-07-02 [ClassLoader] ordered ClassCollectionLoader writing to avoid redeclar…
34
685dd120 »
2012-07-03 [ClassLoader] made ClassCollectionLoader::load() automatically includ…
35 $r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
36 $m = $r->getMethod('getOrderedClasses');
37 $m->setAccessible(true);
a04dde5a »
2012-07-02 [ClassLoader] ordered ClassCollectionLoader writing to avoid redeclar…
38
685dd120 »
2012-07-03 [ClassLoader] made ClassCollectionLoader::load() automatically includ…
39 $ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
a04dde5a »
2012-07-02 [ClassLoader] ordered ClassCollectionLoader writing to avoid redeclar…
40
685dd120 »
2012-07-03 [ClassLoader] made ClassCollectionLoader::load() automatically includ…
41 $this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
a04dde5a »
2012-07-02 [ClassLoader] ordered ClassCollectionLoader writing to avoid redeclar…
42 }
5828147f »
2012-07-03 fixed unit tests
43
a04dde5a »
2012-07-02 [ClassLoader] ordered ClassCollectionLoader writing to avoid redeclar…
44 public function getDifferentOrders()
45 {
46 return array(
47 array(array(
48 'ClassesWithParents\\A',
49 'ClassesWithParents\\CInterface',
9c929006 »
2012-07-10 [ClassLoader] fixed order of interfaces in generated class collection…
50 'ClassesWithParents\\GInterface',
a04dde5a »
2012-07-02 [ClassLoader] ordered ClassCollectionLoader writing to avoid redeclar…
51 'ClassesWithParents\\B',
52 )),
53 array(array(
54 'ClassesWithParents\\B',
55 'ClassesWithParents\\A',
56 'ClassesWithParents\\CInterface',
57 )),
58 array(array(
59 'ClassesWithParents\\CInterface',
60 'ClassesWithParents\\B',
61 'ClassesWithParents\\A',
62 )),
685dd120 »
2012-07-03 [ClassLoader] made ClassCollectionLoader::load() automatically includ…
63 array(array(
64 'ClassesWithParents\\A',
65 )),
66 );
67 }
68
69 /**
70 * @dataProvider getDifferentOrdersForTraits
71 */
72 public function testClassWithTraitsReordering(array $classes)
73 {
74 if (version_compare(phpversion(), '5.4.0', '<')) {
75 $this->markTestSkipped('Requires PHP > 5.4.0.');
76
77 return;
78 }
79
80 require_once __DIR__.'/Fixtures/ClassesWithParents/ATrait.php';
81 require_once __DIR__.'/Fixtures/ClassesWithParents/BTrait.php';
82 require_once __DIR__.'/Fixtures/ClassesWithParents/CTrait.php';
83 require_once __DIR__.'/Fixtures/ClassesWithParents/D.php';
84 require_once __DIR__.'/Fixtures/ClassesWithParents/E.php';
85
86 $expected = array(
9c929006 »
2012-07-10 [ClassLoader] fixed order of interfaces in generated class collection…
87 'ClassesWithParents\\GInterface',
685dd120 »
2012-07-03 [ClassLoader] made ClassCollectionLoader::load() automatically includ…
88 'ClassesWithParents\\CInterface',
89 'ClassesWithParents\\CTrait',
90 'ClassesWithParents\\ATrait',
91 'ClassesWithParents\\BTrait',
92 'ClassesWithParents\\B',
93 'ClassesWithParents\\A',
94 'ClassesWithParents\\D',
95 'ClassesWithParents\\E',
96 );
97
98 $r = new \ReflectionClass('Symfony\Component\ClassLoader\ClassCollectionLoader');
99 $m = $r->getMethod('getOrderedClasses');
100 $m->setAccessible(true);
101
102 $ordered = $m->invoke('Symfony\Component\ClassLoader\ClassCollectionLoader', $classes);
103
104 $this->assertEquals($expected, array_map(function ($class) { return $class->getName(); }, $ordered));
105 }
106
107 public function getDifferentOrdersForTraits()
108 {
109 return array(
110 array(array(
111 'ClassesWithParents\\E',
112 'ClassesWithParents\\ATrait',
113 )),
114 array(array(
115 'ClassesWithParents\\E',
116 )),
a04dde5a »
2012-07-02 [ClassLoader] ordered ClassCollectionLoader writing to avoid redeclar…
117 );
118 }
119
edda8afa »
2012-03-28 moved component and bridge unit tests to the src/ directory
120 public function testFixNamespaceDeclarations()
121 {
122 $source = <<<EOF
123 <?php
124
125 namespace Foo;
126 class Foo {}
127 namespace Bar ;
128 class Foo {}
129 namespace Foo\Bar;
130 class Foo {}
131 namespace Foo\Bar\Bar
132 {
133 class Foo {}
134 }
135 namespace
136 {
137 class Foo {}
138 }
139 EOF;
140
141 $expected = <<<EOF
142 <?php
143
144 namespace Foo
145 {
146 class Foo {}
147 }
0b8b41c5 »
2012-05-01 fixed CS
148 namespace Bar
edda8afa »
2012-03-28 moved component and bridge unit tests to the src/ directory
149 {
150 class Foo {}
151 }
152 namespace Foo\Bar
153 {
154 class Foo {}
155 }
156 namespace Foo\Bar\Bar
157 {
158 class Foo {}
159 }
160 namespace
161 {
162 class Foo {}
163 }
164 EOF;
165
166 $this->assertEquals($expected, ClassCollectionLoader::fixNamespaceDeclarations($source));
167 }
168
169 /**
170 * @expectedException InvalidArgumentException
171 */
172 public function testUnableToLoadClassException()
173 {
174 ClassCollectionLoader::load(array('SomeNotExistingClass'), '', 'foo', false);
175 }
406ab9f5 »
2012-08-27 load test
176
177 public function testLoadTwiceClass()
178 {
179 ClassCollectionLoader::load(array('Foo'), '', 'foo', false);
180 ClassCollectionLoader::load(array('Foo'), '', 'foo', false);
181 }
edda8afa »
2012-03-28 moved component and bridge unit tests to the src/ directory
182 }
Something went wrong with that request. Please try again.