database.test.php 1.52 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
<?php

class DatabaseTest extends PHPUnit_Framework_TestCase {

	/**
	 * Set up the test environment.
	 */
	public function setUp()
	{
		DB::$connections = array();
	}

	/**
	 * Tear down the test environment.
	 */
	public function tearDown()
	{
		DB::$connections = array();
	}

	/**
	 * Test the DB::connection method.
	 *
	 * @group laravel
	 */
	public function testConnectionMethodReturnsConnection()
	{
		$connection = DatabaseConnectStub::connection();
		$this->assertTrue(isset(DB::$connections[Config::get('database.default')]));

		$connection = DatabaseConnectStub::connection('mysql');
		$this->assertTrue(isset(DB::$connections['mysql']));
		$this->assertEquals(DB::$connections['mysql']->pdo->laravel_config, Config::get('database.connections.mysql'));
	}

	/**
	 * Test the DB::profile method.
	 *
	 * @group laravel
	 */
	public function testProfileMethodReturnsQueries()
	{
		Laravel\Database\Connection::$queries = array('Taylor');
		$this->assertEquals(array('Taylor'), DB::profile());
		Laravel\Database\Connection::$queries = array();
	}

	/**
	 * Test the __callStatic method.
	 *
	 * @group laravel
	 */
	public function testConnectionMethodsCanBeCalledStaticly()
	{
		$this->assertEquals('sqlite', DB::driver());
	}

}

class DatabaseConnectStub extends Laravel\Database {

	protected static function connect($config) { return new PDOStub($config); }

}

class PDOStub extends PDO {
	
	public $laravel_config;

	public function __construct($config) { $this->laravel_config = $config; }

	public function foo() { return 'foo'; }

}