c34351b04b0763add55928b36904a52004074329
[yaffs-website] / Tests / Psr4ClassLoaderTest.php
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 PHPUnit\Framework\TestCase;
15 use Symfony\Component\ClassLoader\Psr4ClassLoader;
16
17 /**
18  * @group legacy
19  */
20 class Psr4ClassLoaderTest extends TestCase
21 {
22     /**
23      * @param string $className
24      * @dataProvider getLoadClassTests
25      */
26     public function testLoadClass($className)
27     {
28         $loader = new Psr4ClassLoader();
29         $loader->addPrefix(
30             'Acme\\DemoLib',
31             __DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'psr-4'
32         );
33         $loader->loadClass($className);
34         $this->assertTrue(class_exists($className), sprintf('loadClass() should load %s', $className));
35     }
36
37     /**
38      * @return array
39      */
40     public function getLoadClassTests()
41     {
42         return array(
43             array('Acme\\DemoLib\\Foo'),
44             array('Acme\\DemoLib\\Class_With_Underscores'),
45             array('Acme\\DemoLib\\Lets\\Go\\Deeper\\Foo'),
46             array('Acme\\DemoLib\\Lets\\Go\\Deeper\\Class_With_Underscores'),
47         );
48     }
49
50     /**
51      * @param string $className
52      * @dataProvider getLoadNonexistentClassTests
53      */
54     public function testLoadNonexistentClass($className)
55     {
56         $loader = new Psr4ClassLoader();
57         $loader->addPrefix(
58             'Acme\\DemoLib',
59             __DIR__.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'psr-4'
60         );
61         $loader->loadClass($className);
62         $this->assertFalse(class_exists($className), sprintf('loadClass() should not load %s', $className));
63     }
64
65     /**
66      * @return array
67      */
68     public function getLoadNonexistentClassTests()
69     {
70         return array(
71             array('Acme\\DemoLib\\I_Do_Not_Exist'),
72             array('UnknownVendor\\SomeLib\\I_Do_Not_Exist'),
73         );
74     }
75 }