Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 6a53a89

Browse files
committed
Adds missing unit test for autoincluding the ClassMapAutoloader
1 parent b67c1eb commit 6a53a89

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

tests/Zend/Loader/AllTests.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
}
2626

2727
require_once 'Zend/Loader/AutoloaderTest.php';
28+
require_once 'Zend/Loader/AutoloaderFactoryClassMapLoaderTest.php';
2829
require_once 'Zend/Loader/AutoloaderFactoryTest.php';
2930
require_once 'Zend/Loader/AutoloaderMultiVersionTest.php';
3031
require_once 'Zend/Loader/Autoloader/ResourceTest.php';
@@ -52,6 +53,7 @@ public static function suite()
5253
$suite = new PHPUnit_Framework_TestSuite('Zend Framework - Zend_Loader');
5354

5455
$suite->addTestSuite('Zend_Loader_AutoloaderTest');
56+
$suite->addTestSuite('Zend_Loader_AutoloaderFactoryClassMapLoaderTest');
5557
$suite->addTestSuite('Zend_Loader_AutoloaderFactoryTest');
5658
$suite->addTestSuite('Zend_Loader_AutoloaderMultiVersionTest');
5759
$suite->addTestSuite('Zend_Loader_Autoloader_ResourceTest');
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Zend Framework
4+
*
5+
* LICENSE
6+
*
7+
* This source file is subject to the new BSD license that is bundled
8+
* with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://framework.zend.com/license/new-bsd
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to [email protected] so we can send you a copy immediately.
14+
*
15+
* @category Zend
16+
* @package Zend_Loader
17+
* @subpackage UnitTests
18+
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
19+
* @license http://framework.zend.com/license/new-bsd New BSD License
20+
*/
21+
22+
if (!defined('PHPUnit_MAIN_METHOD')) {
23+
define('PHPUnit_MAIN_METHOD', 'Zend_Loader_AutoloaderFactoryClassMapLoaderTest::main');
24+
}
25+
26+
require_once 'Zend/Loader/AutoloaderFactory.php';
27+
28+
/**
29+
* @package Zend_Loader
30+
* @subpackage UnitTests
31+
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
32+
* @license http://framework.zend.com/license/new-bsd New BSD License
33+
* @group Loader
34+
*/
35+
class Zend_Loader_AutoloaderFactoryClassMapLoaderTest extends PHPUnit_Framework_TestCase
36+
{
37+
38+
/**
39+
* @var array
40+
*/
41+
protected $_loaders;
42+
43+
/**
44+
* @var string
45+
*/
46+
protected $_includePath;
47+
48+
public static function main()
49+
{
50+
$suite = new PHPUnit_Framework_TestSuite(__CLASS__);
51+
$result = PHPUnit_TextUI_TestRunner::run($suite);
52+
}
53+
54+
public function setUp()
55+
{
56+
// Store original autoloaders
57+
$this->_loaders = spl_autoload_functions();
58+
if (!is_array($this->_loaders)) {
59+
// spl_autoload_functions does not return empty array when no
60+
// autoloaders registered...
61+
$this->_loaders = array();
62+
}
63+
64+
// Clear out other autoloaders to ensure those being tested are at the
65+
// top of the stack
66+
foreach ($this->_loaders as $loader) {
67+
spl_autoload_unregister($loader);
68+
}
69+
70+
// Store original include_path
71+
$this->_includePath = get_include_path();
72+
}
73+
74+
public function tearDown()
75+
{
76+
Zend_Loader_AutoloaderFactory::unregisterAutoloaders();
77+
// Restore original autoloaders
78+
$loaders = spl_autoload_functions();
79+
if (is_array($loaders)) {
80+
foreach ($loaders as $loader) {
81+
spl_autoload_unregister($loader);
82+
}
83+
}
84+
85+
foreach ($this->_loaders as $loader) {
86+
spl_autoload_register($loader);
87+
}
88+
89+
// Restore original include_path
90+
set_include_path($this->_includePath);
91+
}
92+
93+
public function testAutoincluding()
94+
{
95+
Zend_Loader_AutoloaderFactory::factory(
96+
array(
97+
'Zend_Loader_ClassMapAutoloader' => array(
98+
dirname(__FILE__) . '/_files/goodmap.php',
99+
),
100+
)
101+
);
102+
$loader = Zend_Loader_AutoloaderFactory::getRegisteredAutoloader(
103+
'Zend_Loader_ClassMapAutoloader'
104+
);
105+
$map = $loader->getAutoloadMap();
106+
$this->assertTrue(is_array($map));
107+
$this->assertEquals(2, count($map));
108+
}
109+
}
110+
111+
if (PHPUnit_MAIN_METHOD == 'Zend_Loader_AutoloaderFactoryClassMapLoaderTest::main') {
112+
Zend_Loader_AutoloaderFactoryClassMapLoaderTest::main();
113+
}

0 commit comments

Comments
 (0)