fluent.test.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. use Laravel\Fluent;
  3. class FluentTest extends PHPUnit_Framework_TestCase {
  4. /**
  5. * Test the Fluent constructor.
  6. *
  7. * @group laravel
  8. */
  9. public function testAttributesAreSetByConstructor()
  10. {
  11. $array = array('name' => 'Taylor', 'age' => 25);
  12. $fluent = new FLuent($array);
  13. $this->assertEquals($array, $fluent->attributes);
  14. }
  15. /**
  16. * Test the Fluent::get method.
  17. *
  18. * @group laravel
  19. */
  20. public function testGetMethodReturnsAttribute()
  21. {
  22. $fluent = new Fluent(array('name' => 'Taylor'));
  23. $this->assertEquals('Taylor', $fluent->get('name'));
  24. $this->assertEquals('Default', $fluent->get('foo', 'Default'));
  25. $this->assertEquals('Taylor', $fluent->name);
  26. $this->assertNull($fluent->foo);
  27. }
  28. public function testMagicMethodsCanBeUsedToSetAttributes()
  29. {
  30. $fluent = new FLuent;
  31. $fluent->name = 'Taylor';
  32. $fluent->developer();
  33. $fluent->age(25);
  34. $this->assertEquals('Taylor', $fluent->name);
  35. $this->assertTrue($fluent->developer);
  36. $this->assertEquals(25, $fluent->age);
  37. $this->assertInstanceOf('Laravel\\Fluent', $fluent->programmer());
  38. }
  39. }