1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace League\Fractal\Test;
- use League\Fractal\Manager;
- use League\Fractal\Resource\ResourceInterface;
- use League\Fractal\Scope;
- use League\Fractal\ScopeFactory;
- use PHPUnit\Framework\TestCase;
- class ScopeFactoryTest extends TestCase
- {
- public function testItImplementsScopeFactoryInterface()
- {
- $this->assertInstanceOf('League\\Fractal\\ScopeFactoryInterface', $this->createSut());
- }
- public function testItCreatesScopes()
- {
- $sut = $this->createSut();
- $manager = $this->createManager();
- $resource = $this->createResource();
- $scopeIdentifier = 'foo_identifier';
- $scope = $sut->createScopeFor($manager, $resource, $scopeIdentifier);
- $this->assertInstanceOf('League\\Fractal\\Scope', $scope);
- $this->assertSame($resource, $scope->getResource());
- $this->assertSame($scopeIdentifier, $scope->getScopeIdentifier());
- }
- public function testItCreatesScopesWithParent()
- {
- $manager = $this->createManager();
- $scope = new Scope($manager, $this->createResource(), 'parent_identifier');
- $scope->setParentScopes([
- 'parent_scope',
- ]);
- $resource = $this->createResource();
- $scopeIdentifier = 'foo_identifier';
- $expectedParentScopes = [
- 'parent_scope',
- 'parent_identifier',
- ];
- $sut = $this->createSut();
- $scope = $sut->createChildScopeFor($manager, $scope, $resource, $scopeIdentifier);
- $this->assertInstanceOf('League\\Fractal\\Scope', $scope);
- $this->assertSame($resource, $scope->getResource());
- $this->assertSame($scopeIdentifier, $scope->getScopeIdentifier());
- $this->assertEquals($expectedParentScopes, $scope->getParentScopes());
- }
- /**
- * @return ScopeFactory
- */
- private function createSut()
- {
- return new ScopeFactory();
- }
- /**
- * @return Manager
- */
- private function createManager()
- {
- return $this->getMock('League\\Fractal\\Manager');
- }
- /**
- * @return ResourceInterface
- */
- private function createResource()
- {
- return $this->getMock('League\\Fractal\\Resource\\ResourceInterface');
- }
- }
|