diff --git a/.gitignore b/.gitignore index a67d42b..77951aa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ composer.phar /vendor/ +composer.lock +.phpunit.result.cache # Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..a062072 --- /dev/null +++ b/composer.json @@ -0,0 +1,21 @@ +{ + "name": "zhamao/config", + "description": "A simple json and php config provider supporting env variable", + "license": "Apache-2.0", + "authors": [ + { + "name": "whale", + "email": "crazysnowcc@gamil.com" + } + ], + "minimum-stability": "stable", + "require": {}, + "require-dev": { + "phpunit/phpunit": "^9.3" + }, + "autoload": { + "psr-4": { + "ZM\\Config\\": "src/ZM/Config" + } + } +} diff --git a/src/ZM/Config/ZMConfig.php b/src/ZM/Config/ZMConfig.php new file mode 100644 index 0000000..26faa4b --- /dev/null +++ b/src/ZM/Config/ZMConfig.php @@ -0,0 +1,86 @@ +assertIsArray(ZMConfig::get("test")); + } + + public function testEnvSetting() + { + ZMConfig::env("production"); + $this->assertEquals("production", ZMConfig::get("test")["hello"]); + } + + public function testNonExistEnv() + { + ZMConfig::env("development"); + $this->assertIsBool(ZMConfig::get("test")); + } + + public function testGetKey() { + $this->assertEquals("world", ZMConfig::get("test", "hello")); + $this->assertNull(ZMConfig::get("test", "qwe")); + } + + public function testJson() { + $this->assertIsArray(ZMConfig::get("global")); + $this->assertEquals("test", ZMConfig::get("global", "name")); + } +} diff --git a/test/config/global.json b/test/config/global.json new file mode 100644 index 0000000..600e5f1 --- /dev/null +++ b/test/config/global.json @@ -0,0 +1,3 @@ +{ + "name": "test" +} diff --git a/test/config/test.production.php b/test/config/test.production.php new file mode 100644 index 0000000..417a0ba --- /dev/null +++ b/test/config/test.production.php @@ -0,0 +1,5 @@ +