My first commit of codes

This commit is contained in:
sujitprasad
2015-05-01 13:13:01 +05:30
parent 4c8e5096f1
commit a6e5a69348
8487 changed files with 1317246 additions and 0 deletions

View File

@@ -0,0 +1,156 @@
<?php
class DotenvTest extends \PHPUnit_Framework_TestCase
{
public function testDotenvLoadsEnvironmentVars()
{
Dotenv::load(dirname(__DIR__) . '/fixtures');
$this->assertEquals('bar', getenv('FOO'));
$this->assertEquals('baz', getenv('BAR'));
$this->assertEquals('with spaces', getenv('SPACED'));
$this->assertEquals('', getenv('NULL'));
}
public function testCommentedDotenvLoadsEnvironmentVars()
{
Dotenv::load(dirname(__DIR__) . '/fixtures', 'commented.env');
$this->assertEquals('bar', getenv('CFOO'));
$this->assertEquals(false, getenv('CBAR'));
$this->assertEquals(false, getenv('CZOO'));
$this->assertEquals('with spaces', getenv('CSPACED'));
$this->assertEquals('a value with a # character', getenv('CQUOTES'));
$this->assertEquals('a value with a # character & a quote " character inside quotes', getenv('CQUOTESWITHQUOTE'));
$this->assertEquals('', getenv('CNULL'));
}
public function testQuotedDotenvLoadsEnvironmentVars()
{
Dotenv::load(dirname(__DIR__) . '/fixtures', 'quoted.env');
$this->assertEquals('bar', getenv('QFOO'));
$this->assertEquals('baz', getenv('QBAR'));
$this->assertEquals('with spaces', getenv('QSPACED'));
$this->assertEquals('', getenv('QNULL'));
$this->assertEquals('pgsql:host=localhost;dbname=test', getenv('QEQUALS'));
$this->assertEquals("test some escaped characters like a quote (') or maybe a backslash (\\)", getenv('QESCAPED'));
}
public function testExportedDotenvLoadsEnvironmentVars()
{
Dotenv::load(dirname(__DIR__) . '/fixtures', 'exported.env');
$this->assertEquals('bar', getenv('EFOO'));
$this->assertEquals('baz', getenv('EBAR'));
$this->assertEquals('with spaces', getenv('ESPACED'));
$this->assertEquals('', getenv('ENULL'));
}
public function testDotenvLoadsEnvGlobals()
{
Dotenv::load(dirname(__DIR__) . '/fixtures');
$this->assertEquals('bar', $_SERVER['FOO']);
$this->assertEquals('baz', $_SERVER['BAR']);
$this->assertEquals('with spaces', $_SERVER['SPACED']);
$this->assertEquals('', $_SERVER['NULL']);
}
public function testDotenvLoadsServerGlobals()
{
Dotenv::load(dirname(__DIR__) . '/fixtures');
$this->assertEquals('bar', $_ENV['FOO']);
$this->assertEquals('baz', $_ENV['BAR']);
$this->assertEquals('with spaces', $_ENV['SPACED']);
$this->assertEquals('', $_ENV['NULL']);
}
public function testDotenvRequiredStringEnvironmentVars()
{
Dotenv::load(dirname(__DIR__) . '/fixtures');
$res = Dotenv::required('FOO');
$this->assertTrue($res);
}
public function testDotenvRequiredArrayEnvironmentVars()
{
Dotenv::load(dirname(__DIR__) . '/fixtures');
$res = Dotenv::required(array('FOO', 'BAR'));
$this->assertTrue($res);
}
public function testDotenvNestedEnvironmentVars()
{
Dotenv::load(dirname(__DIR__) . '/fixtures', 'nested.env');
$this->assertEquals('Hello World!', $_ENV['NVAR3']);
$this->assertEquals('${NVAR1} ${NVAR2}', $_ENV['NVAR4']); // not resolved
$this->assertEquals('$NVAR1 {NVAR2}', $_ENV['NVAR5']); // not resolved
}
public function testDotenvAllowedValues()
{
Dotenv::load(dirname(__DIR__) . '/fixtures');
$res = Dotenv::required('FOO', array('bar', 'baz'));
$this->assertTrue($res);
}
/**
* @expectedException RuntimeException
* @expectedExceptionMessage Required environment variable missing, or value not allowed: 'FOO'
*/
public function testDotenvProhibitedValues()
{
Dotenv::load(dirname(__DIR__) . '/fixtures');
$res = Dotenv::required('FOO', array('buzz'));
$this->assertTrue($res);
}
/**
* @expectedException RuntimeException
* @expectedExceptionMessage Required environment variable missing, or value not allowed: 'FOOX', 'NOPE'
*/
public function testDotenvRequiredThrowsRuntimeException()
{
Dotenv::load(dirname(__DIR__) . '/fixtures');
$res = Dotenv::required(array('FOOX', 'NOPE'));
}
public function testDotenvNullFileArgumentUsesDefault()
{
Dotenv::load(dirname(__DIR__) . '/fixtures', null);
$this->assertEquals('bar', getenv('FOO'));
}
/**
* The fixture data has whitespace between the key and in the value string
* Test that these keys are trimmed down
*/
public function testDotenvTrimmedKeys()
{
Dotenv::load(dirname(__DIR__) . '/fixtures', 'quoted.env');
$this->assertTrue(isset($_ENV['QWHITESPACE']));
}
public function testDotenvDoesNotOverwriteEnvWhenImmutable()
{
Dotenv::makeMutable(); // only need this because we've previously set the variable
Dotenv::setEnvironmentVariable('QFOO=external');
Dotenv::makeImmutable();
Dotenv::load(dirname(__DIR__) . '/fixtures', 'quoted.env');
$this->assertEquals('external', getenv('QFOO'));
}
public function testDotenvDoesNotOverwriteEnvWhenMutable()
{
Dotenv::makeMutable();
Dotenv::setEnvironmentVariable('QFOO=external');
Dotenv::load(dirname(__DIR__) . '/fixtures', 'quoted.env');
$this->assertEquals('bar', getenv('QFOO'));
}
public function testDotenvAllowsSpecialCharacters()
{
Dotenv::load(dirname(__DIR__) . '/fixtures', 'specialchars.env');
$this->assertEquals('$a6^C7k%zs+e^.jvjXk', getenv('SPVAR1'));
$this->assertEquals('?BUty3koaV3%GA*hMAwH}B', getenv('SPVAR2'));
$this->assertEquals('jdgEB4{QgEC]HL))&GcXxokB+wqoN+j>xkV7K?m$r', getenv('SPVAR3'));
$this->assertEquals('22222:22#2^{', getenv('SPVAR4'));
$this->assertEquals("test some escaped characters like a quote \\' or maybe a backslash \\\\", getenv('SPVAR5'));
}
}

View File

@@ -0,0 +1,18 @@
<?php
error_reporting(-1);
date_default_timezone_set('UTC');
/**
* Path trickery ensures test suite will always run, standalone or within
* another composer package. Designed to find composer autoloader and require
*/
$vendorPos = strpos(__DIR__, 'vendor/vlucas/phpdotenv');
if($vendorPos !== false) {
// Package has been cloned within another composer package, resolve path to autoloader
$vendorDir = substr(__DIR__, 0, $vendorPos) . 'vendor/';
$loader = require $vendorDir . 'autoload.php';
} else {
// Package itself (cloned standalone)
$loader = require __DIR__.'/../vendor/autoload.php';
}

View File

@@ -0,0 +1,11 @@
# This is a comment
CFOO=bar
#CBAR=baz
#CZOO=goo # a comment on a commented row
CSPACED=with spaces # this is a comment
CQUOTES="a value with a # character" # this is a comment
CQUOTESWITHQUOTE="a value with a # character & a quote \" character inside quotes" # " this is a comment
CNULL=
## this is a comment ##

View File

@@ -0,0 +1,5 @@
export EFOO='bar'
export EBAR='baz'
export ESPACED='with spaces'
export ENULL=''

View File

@@ -0,0 +1,5 @@
NVAR1='Hello'
NVAR2='World!'
NVAR3='{$NVAR1} {$NVAR2}'
NVAR4='${NVAR1} ${NVAR2}'
NVAR5='$NVAR1 {NVAR2}'

View File

@@ -0,0 +1,9 @@
QFOO='bar'
QBAR='baz'
QSPACED='with spaces'
QEQUALS='pgsql:host=localhost;dbname=test'
QNULL=''
QWHITESPACE = 'no space'
QESCAPED='test some escaped characters like a quote (\') or maybe a backslash (\\)'

View File

@@ -0,0 +1,5 @@
SPVAR1='$a6^C7k%zs+e^.jvjXk'
SPVAR2='?BUty3koaV3%GA*hMAwH}B'
SPVAR3='jdgEB4{QgEC]HL))&GcXxokB+wqoN+j>xkV7K?m$r'
SPVAR4='22222:22#2^{'
SPVAR5=test some escaped characters like a quote \' or maybe a backslash \\ # not escaped