ScopeFactoryTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace League\Fractal\Test;
  3. use League\Fractal\Manager;
  4. use League\Fractal\Resource\ResourceInterface;
  5. use League\Fractal\Scope;
  6. use League\Fractal\ScopeFactory;
  7. use PHPUnit\Framework\TestCase;
  8. class ScopeFactoryTest extends TestCase
  9. {
  10. public function testItImplementsScopeFactoryInterface()
  11. {
  12. $this->assertInstanceOf('League\\Fractal\\ScopeFactoryInterface', $this->createSut());
  13. }
  14. public function testItCreatesScopes()
  15. {
  16. $sut = $this->createSut();
  17. $manager = $this->createManager();
  18. $resource = $this->createResource();
  19. $scopeIdentifier = 'foo_identifier';
  20. $scope = $sut->createScopeFor($manager, $resource, $scopeIdentifier);
  21. $this->assertInstanceOf('League\\Fractal\\Scope', $scope);
  22. $this->assertSame($resource, $scope->getResource());
  23. $this->assertSame($scopeIdentifier, $scope->getScopeIdentifier());
  24. }
  25. public function testItCreatesScopesWithParent()
  26. {
  27. $manager = $this->createManager();
  28. $scope = new Scope($manager, $this->createResource(), 'parent_identifier');
  29. $scope->setParentScopes([
  30. 'parent_scope',
  31. ]);
  32. $resource = $this->createResource();
  33. $scopeIdentifier = 'foo_identifier';
  34. $expectedParentScopes = [
  35. 'parent_scope',
  36. 'parent_identifier',
  37. ];
  38. $sut = $this->createSut();
  39. $scope = $sut->createChildScopeFor($manager, $scope, $resource, $scopeIdentifier);
  40. $this->assertInstanceOf('League\\Fractal\\Scope', $scope);
  41. $this->assertSame($resource, $scope->getResource());
  42. $this->assertSame($scopeIdentifier, $scope->getScopeIdentifier());
  43. $this->assertEquals($expectedParentScopes, $scope->getParentScopes());
  44. }
  45. /**
  46. * @return ScopeFactory
  47. */
  48. private function createSut()
  49. {
  50. return new ScopeFactory();
  51. }
  52. /**
  53. * @return Manager
  54. */
  55. private function createManager()
  56. {
  57. return $this->getMock('League\\Fractal\\Manager');
  58. }
  59. /**
  60. * @return ResourceInterface
  61. */
  62. private function createResource()
  63. {
  64. return $this->getMock('League\\Fractal\\Resource\\ResourceInterface');
  65. }
  66. }