From 7110d9f866a2b8f887b3e3f18f45960ffa6cb8ed Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Wed, 1 Jun 2016 21:48:20 -0500 Subject: [PATCH] Better tests for BaseConfig --- tests/system/Config/BaseConfigTest.php | 48 +++++++++++++++++++ tests/system/Config/fixtures/.env | 6 ++- tests/system/Config/fixtures/SimpleConfig.php | 11 +++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/tests/system/Config/BaseConfigTest.php b/tests/system/Config/BaseConfigTest.php index a3a785a267..ca118315a8 100644 --- a/tests/system/Config/BaseConfigTest.php +++ b/tests/system/Config/BaseConfigTest.php @@ -20,6 +20,54 @@ class BaseConfigTest extends CIUnitTestCase //-------------------------------------------------------------------- + public function testBasicValues() + { + $dotenv = new DotEnv($this->fixturesFolder, '.env'); + $dotenv->load(); + + $config = new \SimpleConfig(); + + $this->assertEquals('bar', $config->FOO); + } + + //-------------------------------------------------------------------- + + public function testPrefixedValues() + { + $dotenv = new DotEnv($this->fixturesFolder, '.env'); + $dotenv->load(); + + $config = new \SimpleConfig(); + + $this->assertEquals('baz', $config->onedeep); + } + + //-------------------------------------------------------------------- + + public function testPrefixedArrayValues() + { + $dotenv = new DotEnv($this->fixturesFolder, '.env'); + $dotenv->load(); + + $config = new \SimpleConfig(); + + $this->assertEquals('ci4', $config->default['name']); + } + + //-------------------------------------------------------------------- + + public function testArrayValues() + { + $dotenv = new DotEnv($this->fixturesFolder, '.env'); + $dotenv->load(); + + $config = new \SimpleConfig(); + + $this->assertEquals('simpleton', $config->simple['name']); + } + + //-------------------------------------------------------------------- + public function testSetsDefaultValues() { $dotenv = new DotEnv($this->fixturesFolder, 'commented.env'); diff --git a/tests/system/Config/fixtures/.env b/tests/system/Config/fixtures/.env index 456466a1be..02e25e0296 100644 --- a/tests/system/Config/fixtures/.env +++ b/tests/system/Config/fixtures/.env @@ -2,4 +2,8 @@ FOO=bar BAR=baz SPACED="with spaces" -NULL= \ No newline at end of file +NULL= + +SimpleConfig.onedeep=baz +SimpleConfig.default.name=ci4 +simple.name=simpleton \ No newline at end of file diff --git a/tests/system/Config/fixtures/SimpleConfig.php b/tests/system/Config/fixtures/SimpleConfig.php index df0b4a0599..9f72fe4090 100644 --- a/tests/system/Config/fixtures/SimpleConfig.php +++ b/tests/system/Config/fixtures/SimpleConfig.php @@ -9,4 +9,15 @@ class SimpleConfig extends \CodeIgniter\Config\BaseConfig public $first = 'foo'; public $second = 'bar'; + + public $FOO; + public $onedeep; + + public $default = [ + 'name' => null + ]; + + public $simple = [ + 'name' => null + ]; }