aboutsummaryrefslogtreecommitdiff
path: root/tests/DotenvTest.php
diff options
context:
space:
mode:
authorАлександр Кирюхин <alexander@kiryukhin.su>2018-01-19 03:13:16 +0300
committerАлександр Кирюхин <alexander@kiryukhin.su>2018-01-19 03:13:16 +0300
commit6f452ea995c25a30f214a530fddc6e9d236bdfce (patch)
treeb6538c4e7bd600f3dd4bcaf0d1340155d95da373 /tests/DotenvTest.php
parent6b07f5f4ebb3043efc4991debebb14529cb77aa5 (diff)
Completed reference implementation, added tests
Diffstat (limited to 'tests/DotenvTest.php')
-rw-r--r--tests/DotenvTest.php68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/DotenvTest.php b/tests/DotenvTest.php
new file mode 100644
index 0000000..59dd8b0
--- /dev/null
+++ b/tests/DotenvTest.php
@@ -0,0 +1,68 @@
+<?php
+declare(strict_types=1);
+
+/**
+ * @author: Alexander Kiryukhin <alexander@kiryukhin.su>
+ * @license: MIT
+ */
+
+use NeonXP\Dotenv\Compiler\CompilerInterface;
+use NeonXP\Dotenv\Dotenv;
+use NeonXP\Dotenv\Exception\RuntimeException;
+use NeonXP\Dotenv\Loader\LoaderInterface;
+use NeonXP\Dotenv\Parser\ParserInterface;
+
+use PHPUnit\Framework\TestCase;
+
+/**
+ * Class TestDotenv
+ */
+class DotenvTest extends TestCase
+{
+ /**
+ * @var LoaderInterface
+ */
+ private $mockLoader;
+
+ /**
+ * @var ParserInterface
+ */
+ private $mockParser;
+
+ /**
+ * @var CompilerInterface
+ */
+ private $mockCompiler;
+
+ public function setUp()
+ {
+ $this->mockLoader = new MockLoader();
+ $this->mockParser = new MockParser();
+ $this->mockCompiler = new MockCompiler();
+ }
+
+ public function testLoad()
+ {
+ $dotenv = new Dotenv($this->mockLoader, $this->mockParser, $this->mockCompiler);
+
+ try {
+ $dotenv->get('TEST1');
+ $this->assertTrue(false, 'Dotenv must throws exception if it not loaded');
+ } catch (RuntimeException $exception) {
+ $this->assertTrue(true, 'Dotenv must throws exception if it not loaded');
+ }
+
+ $dotenv->load();
+
+ $this->assertNull( $dotenv->get('NOT_EXISTS'));
+ $this->assertEquals('default value', $dotenv->get('NOT_EXISTS', 'default value'));
+ $this->assertEquals('VALUE3', $dotenv->get('KEY3', 'default value'));
+ $this->assertEquals('VALUE3', $dotenv['KEY3']);
+ $idx = 1;
+ foreach ($dotenv as $key => $value) {
+ $this->assertEquals("KEY{$idx}", $key);
+ $this->assertEquals("VALUE{$idx}", $value);
+ $idx++;
+ }
+ }
+} \ No newline at end of file