Permalink
Browse files

Adding unit tests for Configuration.

  • Loading branch information...
1 parent 791065f commit f7380241a5ea3d301f28298ec1547403e2f2d499 @zyxist zyxist committed Jul 9, 2011
View
1 tests/TestSuite/Toolset/AllTests.php
@@ -17,6 +17,7 @@ public static function suite()
$suite->addTestSuite('TestSuite\\Toolset\\AbstractToolTest');
$suite->addTestSuite('TestSuite\\Toolset\\ClassMapBuilderTest');
$suite->addTestSuite('TestSuite\\Toolset\\CoreDumpTest');
+ $suite->addTestSuite('TestSuite\\Toolset\\ConfigurationTest');
return $suite;
} // end suite();
View
142 tests/TestSuite/Toolset/ConfigurationTest.php
@@ -0,0 +1,142 @@
+<?php
+/**
+ * Unit tests for Open Power Autoloader
+ *
+ * @author Tomasz "Zyx" Jędrzejewski
+ * @copyright Copyright (c) 2009-2011 Invenzzia Group
+ * @license http://www.invenzzia.org/license/new-bsd New BSD License
+ */
+namespace TestSuite\Toolset;
+use Opl\Autoloader\Toolset\Configuration;
+
+/**
+ * @covers \Opl\Autoloader\Toolset\Configuration
+ */
+class ConfigurationTest extends \PHPUnit_Framework_TestCase
+{
+ public function testLoadCorrectFile()
+ {
+ $configuration = new Configuration('./data/configs/correctConfig.xml');
+
+ $this->assertEquals('<?php
+/**
+ * The index.php beginning
+ */
+', $configuration->getFileHeader());
+ $this->assertEquals('
+$application = new Application();
+$application->start();', $configuration->getFileFooter());
+ $this->assertEquals(array('\\', '_'), $configuration->getSeparators());
+
+ $this->assertEquals(array(
+ 'serialized-class-map' => './data/classMap.txt',
+ 'chdb-class-map' => './data/classMap.chdb',
+ 'core-dump' => './data/coreDump.txt',
+ 'core-export' => './web/core.php',
+ 'index' => './web/index.php',
+ 'cli' => './cli/cli.php'
+ ), $configuration->getFiles());
+
+ $this->assertEquals(array(
+ 'Opl' => array('path' => './src/Opl', 'extension' => '.php'),
+ 'Symfony' => array('path' => './src/Symfony', 'extension' => '.php'),
+ 'Doctrine\DBAL' => array('path' => './src/DBAL', 'extension' => '.php'),
+ 'Doctrine\ORM' => array('path' => './src/ORM', 'extension' => '.php5'),
+ ), $configuration->getSeparatorNamespaces('\\'));
+ $this->assertEquals(array(
+ 'Zend' => array('path' => './src/Zend', 'extension' => '.php')
+ ), $configuration->getSeparatorNamespaces('_'));
+
+ $this->assertFalse($configuration->hasSimpleNamespacesOnly());
+ } // end testLoadCorrectFile();
+
+ public function testGetFilesCanIgnoreSpecialTypes()
+ {
+ $configuration = new Configuration('./data/configs/correctConfig.xml');
+ $this->assertEquals(array(
+ 'index' => './web/index.php',
+ 'cli' => './cli/cli.php'
+ ), $configuration->getFiles(true));
+ } // end testGetFilesCanIgnoreSpecialTypes();
+
+ /**
+ * @expectedException OutOfBoundsException
+ */
+ public function testGetSeparatorNamespacesThrowsExceptionIfSeparatorIsNotDefined()
+ {
+ $configuration = new Configuration('./data/configs/correctConfig.xml');
+
+ $this->assertEquals('array', gettype($configuration->getSeparatorNamespaces('_')));
+ $configuration->getSeparatorNamespaces('joe');
+ } // end test testGetSeparatorNamespacesThrowsExceptionIfSeparatorIsNotDefined();
+
+ public function testGetFileReturnsTheFileOfTheGivenType()
+ {
+ $configuration = new Configuration('./data/configs/correctConfig.xml');
+ $this->assertEquals('./data/classMap.txt', $configuration->getFile('serialized-class-map'));
+ $this->assertEquals('./web/index.php', $configuration->getFile('index'));
+ } // end testGetFileReturnsTheFileOfTheGivenType();
+
+ /**
+ * @expectedException OutOfBoundsException
+ */
+ public function testGetFileThrowsExceptionIfTypeIsNotDefined()
+ {
+ $configuration = new Configuration('./data/configs/correctConfig.xml');
+ $this->assertTrue($configuration->hasFile('index'));
+ $this->assertEquals('./web/index.php', $configuration->getFile('index'));
+ $this->assertFalse($configuration->hasFile('joe'));
+ $configuration->getFile('joe');
+ } // end testGetFileThrowsExceptionIfTypeIsNotDefined();
+
+ public function testLoadSimpleConfigFile()
+ {
+ $configuration = new Configuration('./data/configs/simpleConfig.xml');
+
+ $this->assertEquals(array(
+ 'Opl' => array('path' => './src/Opl', 'extension' => '.php'),
+ 'Symfony' => array('path' => './src/Symfony', 'extension' => '.php'),
+ 'Doctrine' => array('path' => './src/Doctrine', 'extension' => '.php'),
+ ), $configuration->getSeparatorNamespaces('\\'));
+ $this->assertTrue($configuration->hasSimpleNamespacesOnly());
+ } // end testLoadSimpleConfigFile();
+
+ public function testLoadNoHeadings()
+ {
+ $configuration = new Configuration('./data/configs/noHeadings.xml');
+ $this->assertEquals('<?php'.PHP_EOL, $configuration->getFileHeader());
+ $this->assertEquals(null, $configuration->getFileFooter());
+ } // end testLoadNoHeadings();
+
+ /**
+ * @expectedException Opl\Autoloader\Exception\FileFormatException
+ */
+ public function testLoadInvalidFile()
+ {
+ $configuration = new Configuration('./data/configs/invalidFile.xml');
+ } // end testLoadInvalidFile();
+
+ /**
+ * @expectedException Opl\Autoloader\Exception\FileFormatException
+ */
+ public function testLoadMissingFileAttribute()
+ {
+ $configuration = new Configuration('./data/configs/missingFileAttribute.xml');
+ } // end testLoadMissingFileAttribute();
+
+ /**
+ * @expectedException Opl\Autoloader\Exception\FileFormatException
+ */
+ public function testLoadMissingNamespaceAttribute()
+ {
+ $configuration = new Configuration('./data/configs/missingNamespaceAttribute.xml');
+ } // end testLoadMissingNamespaceAttribute();
+
+ /**
+ * @expectedException Opl\Autoloader\Exception\FileFormatException
+ */
+ public function testLoadMissingSeparatorAttribute()
+ {
+ $configuration = new Configuration('./data/configs/missingSeparatorAttribute.xml');
+ } // end testLoadMissingSeparatorAttribute();
+} // end ConfigurationTest;
View
34 tests/data/configs/correctConfig.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<autoload>
+ <file-header><![CDATA[
+<?php
+/**
+ * The index.php beginning
+ */
+]]></file-header>
+ <file-footer><![CDATA[
+$application = new Application();
+$application->start();
+ ]]></file-footer>
+
+ <export-files>
+ <file type="serialized-class-map">./data/classMap.txt</file>
+ <file type="chdb-class-map">./data/classMap.chdb</file>
+ <file type="core-dump">./data/coreDump.txt</file>
+ <file type="core-export">./web/core.php</file>
+
+ <file type="index">./web/index.php</file>
+ <file type="cli">./cli/cli.php</file>
+ </export-files>
+
+ <separator value="\">
+ <namespace name="Opl">./src/Opl</namespace>
+ <namespace name="Symfony" extension=".php">./src/Symfony</namespace>
+ <namespace name="Doctrine\DBAL">./src/DBAL</namespace>
+ <namespace name="Doctrine\ORM" extension=".php5">./src/ORM</namespace>
+ </separator>
+
+ <separator value="_">
+ <namespace name="Zend">./src/Zend</namespace>
+ </separator>
+</autoload>
View
5 tests/data/configs/invalidFile.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<autoload>
+ <!-- do not even try to "fix" this file... -->
+ <file-header>
+</autoload>
View
6 tests/data/configs/missingFileAttribute.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<autoload>
+ <export-files>
+ <file>./data/classMap.txt</file>
+ </export-files>
+</autoload>
View
19 tests/data/configs/missingNamespaceAttribute.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<autoload>
+ <export-files>
+ <file type="serialized-class-map">./data/classMap.txt</file>
+ <file type="chdb-class-map">./data/classMap.chdb</file>
+ <file type="core-dump">./data/coreDump.txt</file>
+ <file type="core-export">./web/core.php</file>
+
+ <file type="index">./web/index.php</file>
+ <file type="cli">./cli/cli.php</file>
+ </export-files>
+
+ <separator value="\">
+ <namespace>./src/Opl</namespace>
+ <namespace name="Symfony" extension=".php">./src/Symfony</namespace>
+ <namespace name="Doctrine\DBAL">./src/DBAL</namespace>
+ <namespace name="Doctrine\ORM" extension=".php5">./src/ORM</namespace>
+ </separator>
+</autoload>
View
19 tests/data/configs/missingSeparatorAttribute.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<autoload>
+ <export-files>
+ <file type="serialized-class-map">./data/classMap.txt</file>
+ <file type="chdb-class-map">./data/classMap.chdb</file>
+ <file type="core-dump">./data/coreDump.txt</file>
+ <file type="core-export">./web/core.php</file>
+
+ <file type="index">./web/index.php</file>
+ <file type="cli">./cli/cli.php</file>
+ </export-files>
+
+ <separator>
+ <namespace name="Opl">./src/Opl</namespace>
+ <namespace name="Symfony" extension=".php">./src/Symfony</namespace>
+ <namespace name="Doctrine\DBAL">./src/DBAL</namespace>
+ <namespace name="Doctrine\ORM" extension=".php5">./src/ORM</namespace>
+ </separator>
+</autoload>
View
19 tests/data/configs/noHeadings.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<autoload>
+ <export-files>
+ <file type="serialized-class-map">./data/classMap.txt</file>
+ <file type="chdb-class-map">./data/classMap.chdb</file>
+ <file type="core-dump">./data/coreDump.txt</file>
+ <file type="core-export">./web/core.php</file>
+
+ <file type="index">./web/index.php</file>
+ <file type="cli">./cli/cli.php</file>
+ </export-files>
+
+ <separator value="\">
+ <namespace name="Opl">./src/Opl</namespace>
+ <namespace name="Symfony" extension=".php">./src/Symfony</namespace>
+ <namespace name="Doctrine\DBAL">./src/DBAL</namespace>
+ <namespace name="Doctrine\ORM" extension=".php5">./src/ORM</namespace>
+ </separator>
+</autoload>
View
33 tests/data/configs/simpleConfig.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<autoload>
+ <file-header><![CDATA[
+<?php
+/**
+ * The index.php beginning
+ */
+]]></file-header>
+ <file-footer><![CDATA[
+$application = new Application();
+$application->start();
+ ]]></file-footer>
+
+ <export-files>
+ <file type="serialized-class-map">./data/classMap.txt</file>
+ <file type="chdb-class-map">./data/classMap.chdb</file>
+ <file type="core-dump">./data/coreDump.txt</file>
+ <file type="core-export">./web/core.php</file>
+
+ <file type="index">./web/index.php</file>
+ <file type="cli">./cli/cli.php</file>
+ </export-files>
+
+ <separator value="\">
+ <namespace name="Opl">./src/Opl</namespace>
+ <namespace name="Symfony">./src/Symfony</namespace>
+ <namespace name="Doctrine">./src/Doctrine</namespace>
+ </separator>
+
+ <separator value="_">
+ <namespace name="Zend">./src/Zend</namespace>
+ </separator>
+</autoload>

0 comments on commit f738024

Please sign in to comment.