From 173b000c3c11f93a5eb9eaadf3e60f12de871cfa Mon Sep 17 00:00:00 2001 From: Sven Luijten Date: Wed, 23 Mar 2016 20:37:44 +0100 Subject: [PATCH] Refactor tests --- tests/BaseTest.php | 31 ++++++++++++++++++++++++ tests/EnvEditorTest.php | 53 +++++++++++++---------------------------- tests/assets/.env | 3 --- 3 files changed, 48 insertions(+), 39 deletions(-) create mode 100644 tests/BaseTest.php delete mode 100644 tests/assets/.env diff --git a/tests/BaseTest.php b/tests/BaseTest.php new file mode 100644 index 0000000..7c511f3 --- /dev/null +++ b/tests/BaseTest.php @@ -0,0 +1,31 @@ +flex = new EnvEditor(__DIR__ . '/assets/.env'); + } + + /** + * Tear down the testing suite. + */ + public function tearDown() + { + unlink(__DIR__.'/assets/.env'); + } +} \ No newline at end of file diff --git a/tests/EnvEditorTest.php b/tests/EnvEditorTest.php index 4dad439..eb1e7bf 100644 --- a/tests/EnvEditorTest.php +++ b/tests/EnvEditorTest.php @@ -1,47 +1,36 @@ assertEquals(__DIR__.'/assets/.env', $f->getPath()); + $this->assertEquals(__DIR__ . '/assets/.env', $this->flex->getPath()); } /** @test */ public function it_can_read_entries() { - $f = new Sven\FlexEnv\EnvEditor(__DIR__.'/assets/.env'); - - file_put_contents(__DIR__.'/assets/.env', 'TEST=hello-world'); - file_put_contents(__DIR__.'/assets/.env', "\nFOO_BAR=something else", FILE_APPEND); + file_put_contents(__DIR__ . '/assets/.env', 'TEST=hello-world'); + file_put_contents(__DIR__ . '/assets/.env', "\nFOO_BAR=something else", FILE_APPEND); - $this->assertEquals('hello-world', $f->get('TEST')); - $this->assertEquals('something else', $f->get('FOO_BAR')); + $this->assertEquals('hello-world', $this->flex->get('TEST')); + $this->assertEquals('something else', $this->flex->get('FOO_BAR')); } /** @test */ public function it_returns_an_empty_string_if_value_not_found() { - $f = new Sven\FlexEnv\EnvEditor(__DIR__.'/assets/.env'); - - $this->assertEquals('', $f->get('I_DO_NOT_EXIST')); + $this->assertEquals('', $this->flex->get('I_DO_NOT_EXIST')); } /** @test */ public function it_can_add_values() { - @unlink(__DIR__.'/assets/.env'); - - $f = new Sven\FlexEnv\EnvEditor(__DIR__.'/assets/.env'); - - $result = $f->set('HELLO_WORLD', 'this-is-a-test') - ->get('HELLO_WORLD'); + $result = $this->flex->set('HELLO_WORLD', 'this-is-a-test') + ->get('HELLO_WORLD'); $this->assertEquals('this-is-a-test', $result); } @@ -49,17 +38,13 @@ public function it_can_add_values() /** @test */ public function it_removes_an_entry() { - @unlink(__DIR__.'/assets/.env'); - - $f = new Sven\FlexEnv\EnvEditor(__DIR__.'/assets/.env'); - - $result1 = $f->set('FOO_BAR', 'biz-baz') - ->get('FOO_BAR'); + $result1 = $this->flex->set('FOO_BAR', 'biz-baz') + ->get('FOO_BAR'); $this->assertEquals('biz-baz', $result1); - $result2 = $f->delete('FOO_BAR') - ->get('FOO_BAR'); + $result2 = $this->flex->delete('FOO_BAR') + ->get('FOO_BAR'); $this->assertEquals('', $result2); } @@ -67,16 +52,12 @@ public function it_removes_an_entry() /** @test */ public function it_lists_all_entries() { - @unlink(__DIR__.'/assets/.env'); - - $f = new Sven\FlexEnv\EnvEditor(__DIR__.'/assets/.env'); - - $f->set('TESTING', 'hello-world') - ->set('FOO_BAR', 'biz-baz'); + $this->flex->set('TESTING', 'hello-world') + ->set('FOO_BAR', 'biz-baz'); $this->assertEquals( ['TESTING' => 'hello-world', 'FOO_BAR' => 'biz-baz'], - $f->all() + $this->flex->all() ); } } diff --git a/tests/assets/.env b/tests/assets/.env deleted file mode 100644 index 31d73a3..0000000 --- a/tests/assets/.env +++ /dev/null @@ -1,3 +0,0 @@ - -TESTING=hello-world -FOO_BAR=biz-baz \ No newline at end of file