fluent.test.php 1.06 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
<?php

use Laravel\Fluent;

class FluentTest extends PHPUnit_Framework_TestCase {

	/**
	 * Test the Fluent constructor.
	 *
	 * @group laravel
	 */
	public function testAttributesAreSetByConstructor()
	{
		$array = array('name' => 'Taylor', 'age' => 25);

		$fluent = new Fluent($array);

		$this->assertEquals($array, $fluent->attributes);
	}

	/**
	 * Test the Fluent::get method.
	 *
	 * @group laravel
	 */
	public function testGetMethodReturnsAttribute()
	{
		$fluent = new Fluent(array('name' => 'Taylor'));

		$this->assertEquals('Taylor', $fluent->get('name'));
		$this->assertEquals('Default', $fluent->get('foo', 'Default'));
		$this->assertEquals('Taylor', $fluent->name);
		$this->assertNull($fluent->foo);
	}

	public function testMagicMethodsCanBeUsedToSetAttributes()
	{
		$fluent = new Fluent;

		$fluent->name = 'Taylor';
		$fluent->developer();
		$fluent->age(25);

		$this->assertEquals('Taylor', $fluent->name);
		$this->assertTrue($fluent->developer);
		$this->assertEquals(25, $fluent->age);
		$this->assertInstanceOf('Laravel\\Fluent', $fluent->programmer());
	}

}