PrimitiveTest.php 1.4 KB

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