getConfig() public method

Get configuration from a .env file.
public getConfig ( string $name ) : string | null
$name string Configuration name
return string | null
示例#1
0
 public function test_Should_UpdateExistingDbSettings()
 {
     vfsStream::newFile('.env')->at($this->rootDir);
     $dotenvReader = new DotenvReader(new LaravelFilesystem($this->app['files']), vfsStream::url('rootDir/.env'));
     $dotenvWriter = new DotenvWriter(new LaravelFilesystem($this->app['files']), vfsStream::url('rootDir/.env'));
     $configDbSettingRepository = new ConfigDbSetting($dotenvReader, $dotenvWriter);
     $configDbSettingRepository->update(['driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'username', 'password' => 'password']);
     $this->assertEquals('mysql', $dotenvReader->getConfig('DB_DRIVER'));
     $this->assertEquals('localhost', $dotenvReader->getConfig('DB_HOST'));
     $this->assertEquals('database', $dotenvReader->getConfig('DB_DATABASE'));
     $this->assertEquals('username', $dotenvReader->getConfig('DB_USERNAME'));
     $this->assertEquals('password', $dotenvReader->getConfig('DB_PASSWORD'));
 }
示例#2
0
 public function test_Should_UpdateExistingAppSettings()
 {
     vfsStream::newFile('.env')->at($this->rootDir);
     $dotenvReader = new DotenvReader(new LaravelFilesystem($this->app['files']), vfsStream::url('rootDir/.env'));
     $dotenvWriter = new DotenvWriter(new LaravelFilesystem($this->app['files']), vfsStream::url('rootDir/.env'));
     $configAppSettingRepository = new ConfigAppSetting($dotenvReader, $dotenvWriter);
     $configAppSettingRepository->update(['url' => 'http://example.com']);
     $this->assertEquals('http://example.com', $dotenvReader->getConfig('APP_URL'));
 }
示例#3
0
 public function test_Should_UpdateExistingMailSettings()
 {
     vfsStream::newFile('.env')->at($this->rootDir);
     $dotenvReader = new DotenvReader(new LaravelFilesystem($this->app['files']), vfsStream::url('rootDir/.env'));
     $dotenvWriter = new DotenvWriter(new LaravelFilesystem($this->app['files']), vfsStream::url('rootDir/.env'));
     $configMailSettingRepository = new ConfigMailSetting($dotenvReader, $dotenvWriter);
     $configMailSettingRepository->update(['driver' => 'smtp', 'from_address' => '*****@*****.**', 'from_name' => 'from_name', 'smtp_host' => 'localhost', 'smtp_port' => 587, 'smtp_encryption' => 'tls', 'smtp_username' => '*****@*****.**', 'smtp_password' => 'password', 'sendmail_path' => '/usr/sbin/sendmail -bs']);
     $this->assertEquals('smtp', $dotenvReader->getConfig('MAIL_DRIVER'));
     $this->assertEquals('*****@*****.**', $dotenvReader->getConfig('MAIL_FROM_ADDRESS'));
     $this->assertEquals('from_name', $dotenvReader->getConfig('MAIL_FROM_NAME'));
     $this->assertEquals('localhost', $dotenvReader->getConfig('MAIL_HOST'));
     $this->assertEquals(587, $dotenvReader->getConfig('MAIL_PORT'));
     $this->assertEquals('tls', $dotenvReader->getConfig('MAIL_ENCRYPTION'));
     $this->assertEquals('*****@*****.**', $dotenvReader->getConfig('MAIL_USERNAME'));
     $this->assertEquals('password', $dotenvReader->getConfig('MAIL_PASSWORD'));
     $this->assertEquals('/usr/sbin/sendmail -bs', $dotenvReader->getConfig('MAIL_SENDMAIL'));
 }
示例#4
0
    public function test_Should_GetNull_When_ConfigDoesNotExist()
    {
        $contents = <<<EOF
NAME1=value1
NAME2='value2'
NAME3= v a l u e 3 
NAME4=

EOF;
        $dotenv = vfsStream::newFile('.env')->at($this->rootDir)->setContent($contents);
        $dotenvReader = new DotenvReader(new LaravelFilesystem($this->app['files']), vfsStream::url('rootDir/.env'));
        $value = $dotenvReader->getConfig('NAME5');
        $this->assertNull($value);
    }