summaryrefslogtreecommitdiffstats
path: root/tests/lib/SimpleSAML/Utils
diff options
context:
space:
mode:
authorJaime Perez Crespo <jaime.perez@uninett.no>2015-08-11 12:42:41 +0200
committerJaime Perez Crespo <jaime.perez@uninett.no>2015-08-11 12:42:41 +0200
commitc14eb4c04e61520ad6e9ef04ad2306f11e3478fc (patch)
tree0eb5e02c0f0d4ad15ec0aab287a61b1b0d98e35a /tests/lib/SimpleSAML/Utils
parentece38d6d1842f0f0e01da4909e411ba0dfeb7d6d (diff)
parentc3248ebf531aece37d9f6c0315e8955c92cbd1c2 (diff)
downloadsimplesamlphp-c14eb4c04e61520ad6e9ef04ad2306f11e3478fc.zip
simplesamlphp-c14eb4c04e61520ad6e9ef04ad2306f11e3478fc.tar.gz
simplesamlphp-c14eb4c04e61520ad6e9ef04ad2306f11e3478fc.tar.bz2
Merge branch 'master' of https://github.com/tldev/simplesamlphp into feature/config-from-env
Diffstat (limited to 'tests/lib/SimpleSAML/Utils')
-rw-r--r--tests/lib/SimpleSAML/Utils/ConfigTest.php49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/lib/SimpleSAML/Utils/ConfigTest.php b/tests/lib/SimpleSAML/Utils/ConfigTest.php
new file mode 100644
index 0000000..2fdc080
--- /dev/null
+++ b/tests/lib/SimpleSAML/Utils/ConfigTest.php
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * Tests for SimpleSAML\Utils\Config
+ */
+class Utils_ConfigTest extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Test default config dir with not environment variable
+ */
+ public function testDefaultConfigDir()
+ {
+ // clear env var
+ putenv('SIMPLESAMLPHP_CONFIG_DIR');
+ $configDir = \SimpleSAML\Utils\Config::getConfigDir();
+
+ $this->assertEquals($configDir, dirname(dirname(dirname(dirname(__DIR__)))) . '/config');
+ }
+
+ /**
+ * Test valid dir specified by env var overrides default config dir
+ */
+ public function testEnvVariableConfigDir()
+ {
+ putenv('SIMPLESAMLPHP_CONFIG_DIR=' . __DIR__);
+ $configDir = \SimpleSAML\Utils\Config::getConfigDir();
+
+ $this->assertEquals($configDir, __DIR__);
+ }
+
+ /**
+ * Test invalid dir specified by env var results in a thrown exception
+ */
+ public function testInvalidEnvVariableConfigDirThrowsException()
+ {
+ // I used a random hash to ensure this test directory is always invalid
+ $invalidDir = __DIR__ . '/e9826ad19cbc4f5bf20c0913ffcd2ce6';
+ putenv('SIMPLESAMLPHP_CONFIG_DIR=' . $invalidDir);
+
+ $this->setExpectedException(
+ 'InvalidArgumentException',
+ 'Config directory specified by environment variable SIMPLESAMLPHP_CONFIG_DIR is not a directory. ' .
+ 'Given: "' . $invalidDir . '"'
+ );
+
+ \SimpleSAML\Utils\Config::getConfigDir();
+ }
+}