From 306c864d842fe8d40c9e0ed039bca8524f48dbc6 Mon Sep 17 00:00:00 2001 From: Baptiste Leduc Date: Sat, 19 May 2018 15:46:27 +0200 Subject: [PATCH 1/3] updating tests to remove trimed spaces from explicit variable --- tests/Dotenv/DotenvTest.php | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/tests/Dotenv/DotenvTest.php b/tests/Dotenv/DotenvTest.php index daed85db..ea4841b3 100644 --- a/tests/Dotenv/DotenvTest.php +++ b/tests/Dotenv/DotenvTest.php @@ -259,7 +259,7 @@ public function testDotenvAssertions() $dotenv->load(); $this->assertSame('val1', getenv('ASSERTVAR1')); $this->assertEmpty(getenv('ASSERTVAR2')); - $this->assertEmpty(getenv('ASSERTVAR3')); + $this->assertSame(' ', getenv('ASSERTVAR3')); $this->assertSame('0', getenv('ASSERTVAR4')); $dotenv->required(array( @@ -271,6 +271,7 @@ public function testDotenvAssertions() $dotenv->required(array( 'ASSERTVAR1', + 'ASSERTVAR3', 'ASSERTVAR4', ))->notEmpty(); @@ -295,30 +296,6 @@ public function testDotenvEmptyThrowsRuntimeException() $dotenv->required('ASSERTVAR2')->notEmpty(); } - /** - * @expectedException \Dotenv\Exception\ValidationException - * @expectedExceptionMessage One or more environment variables failed assertions: ASSERTVAR3 is empty. - */ - public function testDotenvStringOfSpacesConsideredEmpty() - { - $dotenv = new Dotenv($this->fixturesFolder, 'assertions.env'); - $dotenv->load(); - $this->assertEmpty(getenv('ASSERTVAR3')); - - $dotenv->required('ASSERTVAR3')->notEmpty(); - } - - /** - * @expectedException \Dotenv\Exception\ValidationException - * @expectedExceptionMessage One or more environment variables failed assertions: ASSERTVAR3 is empty. - */ - public function testDotenvHitsLastChain() - { - $dotenv = new Dotenv($this->fixturesFolder, 'assertions.env'); - $dotenv->load(); - $dotenv->required('ASSERTVAR3')->notEmpty(); - } - /** * @expectedException \Dotenv\Exception\ValidationException * @expectedExceptionMessage One or more environment variables failed assertions: foo is missing. From 9125e7e381f584700955f55cc509341f956b88ab Mon Sep 17 00:00:00 2001 From: Baptiste Leduc Date: Sat, 19 May 2018 15:49:44 +0200 Subject: [PATCH 2/3] removing trim on env values --- src/Loader.php | 2 +- src/Validator.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Loader.php b/src/Loader.php index e245353d..6ea9b4ae 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -252,7 +252,7 @@ protected function sanitiseVariableValue($name, $value) } } - return array($name, trim($value)); + return array($name, $value); } /** diff --git a/src/Validator.php b/src/Validator.php index 53a7fd5a..e10a47f6 100644 --- a/src/Validator.php +++ b/src/Validator.php @@ -56,7 +56,7 @@ public function notEmpty() { return $this->assertCallback( function ($value) { - return strlen(trim($value)) > 0; + return strlen($value) > 0; }, 'is empty' ); From 43f87af761b4ef9ee749b97862f4c0aef259b24f Mon Sep 17 00:00:00 2001 From: Baptiste Leduc Date: Sat, 19 May 2018 15:51:55 +0200 Subject: [PATCH 3/3] updating tests to have value with trailing space --- tests/Dotenv/DotenvTest.php | 2 +- tests/fixtures/env/assertions.env | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Dotenv/DotenvTest.php b/tests/Dotenv/DotenvTest.php index ea4841b3..243186d1 100644 --- a/tests/Dotenv/DotenvTest.php +++ b/tests/Dotenv/DotenvTest.php @@ -259,7 +259,7 @@ public function testDotenvAssertions() $dotenv->load(); $this->assertSame('val1', getenv('ASSERTVAR1')); $this->assertEmpty(getenv('ASSERTVAR2')); - $this->assertSame(' ', getenv('ASSERTVAR3')); + $this->assertSame('val3 ', getenv('ASSERTVAR3')); $this->assertSame('0', getenv('ASSERTVAR4')); $dotenv->required(array( diff --git a/tests/fixtures/env/assertions.env b/tests/fixtures/env/assertions.env index 2a4f4b01..2e5d181d 100644 --- a/tests/fixtures/env/assertions.env +++ b/tests/fixtures/env/assertions.env @@ -1,4 +1,4 @@ ASSERTVAR1="val1" ASSERTVAR2="" -ASSERTVAR3=" " +ASSERTVAR3="val3 " ASSERTVAR4="0" # empty looking value