Skip to content

[3.1] Added more validator tests #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/Dotenv/ValidatorBooleanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function invalidBooleanValuesDataProvider()

/**
* @dataProvider invalidBooleanValuesDataProvider
* @expectedException Dotenv\Exception\ValidationException
* @expectedException \Dotenv\Exception\ValidationException
* @expectedExceptionMessage One or more environment variables failed assertions: INVALID_
*/
public function testCanInvalidateNonBooleans($boolean)
Expand Down
81 changes: 81 additions & 0 deletions tests/Dotenv/ValidatorIntegerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

use Dotenv\Dotenv;
use PHPUnit\Framework\TestCase;

class ValidatorIntegerTest extends TestCase
{
/**
* @var string
*/
private $fixturesFolder;

public function setUp()
{
$this->fixturesFolder = dirname(__DIR__).'/fixtures/env';
}

/**
* List of valid integer values in fixtures/env/integers.env.
*
* @return array
*/
public function validIntegerValuesDataProvider()
{
return [
['VALID_ZERO'],
['VALID_ONE'],
['VALID_TWO'],

['VALID_LARGE'],
['VALID_HUGE'],
];
}

/**
* @dataProvider validIntegerValuesDataProvider
*/
public function testCanValidateIntegers($integer)
{
$dotenv = Dotenv::create($this->fixturesFolder, 'integers.env');
$dotenv->load();

$dotenv->required($integer)->isInteger();

$this->assertTrue(true); // anything wrong - an exception will be thrown
}

/**
* List of non-integer values in fixtures/env/integers.env.
*
* @return array
*/
public function invalidIntegerValuesDataProvider()
{
return [
['INVALID_SOMETHING'],
['INVALID_EMPTY'],
['INVALID_EMPTY_STRING'],
['INVALID_NULL'],
['INVALID_NEGATIVE'],
['INVALID_MINUS'],
['INVALID_TILDA'],
['INVALID_EXCLAMATION'],
['INVALID_SPACES'],
['INVALID_COMMAS'],
];
}

/**
* @dataProvider invalidIntegerValuesDataProvider
* @expectedException \Dotenv\Exception\ValidationException
* @expectedExceptionMessage One or more environment variables failed assertions: INVALID_
*/
public function testCanInvalidateNonIntegers($integer)
{
$dotenv = Dotenv::create($this->fixturesFolder, 'integers.env');
$dotenv->load();

$dotenv->required($integer)->isInteger();
}
}
17 changes: 17 additions & 0 deletions tests/fixtures/env/integers.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
VALID_ZERO=0
VALID_ONE=1
VALID_TWO=2

VALID_LARGE=99999999
VALID_HUGE=99999999999999999999999999999999

INVALID_SOMETHING=something
INVALID_EMPTY=
INVALID_EMPTY_STRING=""
INVALID_NULL=null
INVALID_NEGATIVE=-2
INVALID_MINUS=-
INVALID_TILDA=~
INVALID_EXCLAMATION=!
INVALID_SPACES=" 123"
INVALID_COMMAS="123,123"