-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c64206e
commit 173b000
Showing
3 changed files
with
48 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Sven\FlexEnv\Tests; | ||
|
||
use Sven\FlexEnv\EnvEditor; | ||
|
||
abstract class BaseTest extends \Orchestra\Testbench\TestCase | ||
{ | ||
/** | ||
* The EnvEditor instance. | ||
* | ||
* @var \Sven\FlexEnv\EnvEditor | ||
*/ | ||
protected $flex; | ||
|
||
/** | ||
* Set up the testing suite. | ||
*/ | ||
public function setUp() | ||
{ | ||
$this->flex = new EnvEditor(__DIR__ . '/assets/.env'); | ||
} | ||
|
||
/** | ||
* Tear down the testing suite. | ||
*/ | ||
public function tearDown() | ||
{ | ||
unlink(__DIR__.'/assets/.env'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,63 @@ | ||
<?php | ||
|
||
namespace Sven\FlexEnv\Tests; | ||
|
||
class EnvEditorTest extends Orchestra\Testbench\TestCase | ||
class EnvEditorTest extends BaseTest | ||
{ | ||
/** @test */ | ||
public function it_creates_an_env_file_if_none_exists() | ||
{ | ||
@unlink(__DIR__.'/assets/.env'); | ||
|
||
$f = new Sven\FlexEnv\EnvEditor(__DIR__.'/assets/.env'); | ||
|
||
$this->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); | ||
} | ||
|
||
/** @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); | ||
} | ||
|
||
/** @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() | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.