config.test.php 1.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
<?php

class ConfigTest extends PHPUnit_Framework_TestCase {

	/**
	 * Tear down the testing environment.
	 */
	public function tearDown()
	{
		Config::$items = array();
		Config::$cache = array();
	}

	/**
	 * Test the Config::get method.
	 *
	 * @group laravel
	 */
	public function testItemsCanBeRetrievedFromConfigFiles()
	{
		$this->assertEquals('UTF-8', Config::get('application.encoding'));
		$this->assertEquals('mysql', Config::get('database.connections.mysql.driver'));
		$this->assertEquals('dashboard', Config::get('dashboard::meta.bundle'));
	}

	/**
	 * Test the Config::has method.
	 *
	 * @group laravel
	 */
	public function testHasMethodIndicatesIfConfigItemExists()
	{
		$this->assertFalse(Config::has('application.foo'));
		$this->assertTrue(Config::has('application.encoding'));
	}

	/**
	 * Test the Config::set method.
	 *
	 * @group laravel
	 */
	public function testConfigItemsCanBeSet()
	{
		Config::set('application.encoding', 'foo');
		Config::set('dashboard::meta.bundle', 'bar');

		$this->assertEquals('foo', Config::get('application.encoding'));
		$this->assertEquals('bar', Config::get('dashboard::meta.bundle'));
	}

	/**
	 * Test that environment configurations are loaded correctly.
	 *
	 * @group laravel
	 */
	public function testEnvironmentConfigsOverrideNormalConfigurations()
	{
		$_SERVER['LARAVEL_ENV'] = 'local';

		$this->assertEquals('sqlite', Config::get('database.default'));

		unset($_SERVER['LARAVEL_ENV']);
	}

	/**
	 * Test that items can be set after the entire file has already been loaded.
	 *
	 * @group laravel
	 */
	public function testItemsCanBeSetAfterEntireFileIsLoaded()
	{
		Config::get('application');
		Config::set('application.key', 'taylor');
		$application = Config::get('application');

		$this->assertEquals('taylor', $application['key']);
	}

}