ItemTest.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php namespace League\Fractal\Test;
  2. use League\Fractal\Resource\Item;
  3. use Mockery;
  4. class ItemResourceTest extends \PHPUnit_Framework_TestCase
  5. {
  6. protected $simpleItem = array('foo' => 'bar');
  7. public function testGetData()
  8. {
  9. $resource = new Item($this->simpleItem, function() {});
  10. $this->assertEquals($resource->getData(), $this->simpleItem);
  11. }
  12. public function testGetTransformer()
  13. {
  14. $resource = new Item($this->simpleItem, function () {
  15. });
  16. $this->assertTrue(is_callable($resource->getTransformer()));
  17. $transformer = 'thismightbeacallablestring';
  18. $resource = new Item($this->simpleItem, $transformer);
  19. $this->assertEquals($resource->getTransformer(), $transformer);
  20. }
  21. /**
  22. * @covers League\Fractal\Resource\Item::setResourceKey
  23. */
  24. public function testSetResourceKey()
  25. {
  26. $collection = Mockery::mock('League\Fractal\Resource\Item')->makePartial();
  27. $this->assertInstanceOf('League\Fractal\Resource\Item', $collection->setResourceKey('foo'));
  28. }
  29. /**
  30. * @covers League\Fractal\Resource\Item::getResourceKey
  31. */
  32. public function testGetResourceKey()
  33. {
  34. $collection = Mockery::mock('League\Fractal\Resource\Item')->makePartial();
  35. $collection->setResourceKey('foo');
  36. $this->assertEquals('foo', $collection->getResourceKey());
  37. }
  38. }