2013-12-11 15:08:54 -05:00
|
|
|
<?php
|
2014-03-20 16:54:12 +04:00
|
|
|
namespace PhpWord\Tests;
|
2013-12-11 15:08:54 -05:00
|
|
|
|
|
|
|
|
use PHPWord_Autoloader;
|
2014-03-02 13:11:33 -05:00
|
|
|
use PHPWord_Autoloader as Autoloader;
|
2013-12-11 15:08:54 -05:00
|
|
|
|
2014-03-12 20:13:06 +04:00
|
|
|
class AutoloaderTest extends \PHPUnit_Framework_TestCase
|
2013-12-11 15:08:54 -05:00
|
|
|
{
|
2014-02-24 19:17:06 +01:00
|
|
|
public function testRegister()
|
|
|
|
|
{
|
|
|
|
|
PHPWord_Autoloader::register();
|
|
|
|
|
$this->assertContains(array('PHPWord_Autoloader', 'load'), spl_autoload_functions());
|
2014-03-02 13:11:33 -05:00
|
|
|
$this->assertContains(array('PHPWord_Autoloader', 'autoload'), spl_autoload_functions());
|
2014-02-24 19:17:06 +01:00
|
|
|
}
|
|
|
|
|
|
2014-03-02 13:11:33 -05:00
|
|
|
public function testAutoloadLegacy()
|
2013-12-11 15:08:54 -05:00
|
|
|
{
|
2014-03-12 13:30:02 +07:00
|
|
|
$this->assertNull(
|
|
|
|
|
PHPWord_Autoloader::load('Foo'),
|
2014-03-20 16:54:12 +04:00
|
|
|
'PHPWord_Autoloader::load() is trying to load classes outside of the PhpWord namespace'
|
2014-03-12 13:30:02 +07:00
|
|
|
);
|
|
|
|
|
$this->assertTrue(
|
2014-03-20 16:54:12 +04:00
|
|
|
PHPWord_Autoloader::load('PhpWord'),
|
|
|
|
|
'PHPWord_Autoloader::load() failed to autoload the PhpWord class'
|
2014-03-12 13:30:02 +07:00
|
|
|
);
|
2013-12-11 15:08:54 -05:00
|
|
|
}
|
2014-03-02 13:11:33 -05:00
|
|
|
|
|
|
|
|
public function testAutoload()
|
|
|
|
|
{
|
|
|
|
|
$declared = get_declared_classes();
|
|
|
|
|
$declaredCount = count($declared);
|
|
|
|
|
Autoloader::autoload('Foo');
|
2014-03-12 13:30:02 +07:00
|
|
|
$this->assertEquals(
|
|
|
|
|
$declaredCount,
|
|
|
|
|
count(get_declared_classes()),
|
|
|
|
|
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load classes ' .
|
|
|
|
|
'outside of the PhpOffice\\PhpWord namespace'
|
|
|
|
|
);
|
2014-03-20 16:54:12 +04:00
|
|
|
// TODO change this class to the main PhpWord class when it is namespaced
|
2014-03-12 13:30:02 +07:00
|
|
|
Autoloader::autoload(
|
|
|
|
|
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException'
|
|
|
|
|
);
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', get_declared_classes()),
|
|
|
|
|
'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' .
|
|
|
|
|
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'
|
|
|
|
|
);
|
2014-03-02 13:11:33 -05:00
|
|
|
}
|
2014-03-18 17:26:03 +04:00
|
|
|
}
|