Skip to content

Commit

Permalink
add test case for accessing current scope before its value has been s…
Browse files Browse the repository at this point in the history
…et (#552)
  • Loading branch information
Plastonick committed Apr 11, 2022
1 parent 94ce1fd commit 8b9d39b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/TransformerAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class TransformerAbstract
/**
* The transformer should know about the current scope, so we can fetch relevant params.
*/
protected ?Scope $currentScope;
protected ?Scope $currentScope = null;

/**
* Getter for availableIncludes.
Expand Down
10 changes: 10 additions & 0 deletions test/TransformerAbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ public function testGetCurrentScope()
$this->assertSame($transformer->getCurrentScope(), $scope);
}

/**
* @covers \League\Fractal\TransformerAbstract::getCurrentScope
*/
public function testCanAccessScopeBeforeInitialization()
{
$transformer = $this->getMockForAbstractClass('League\Fractal\TransformerAbstract');
$currentScope = $transformer->getCurrentScope();
$this->assertNull($currentScope);
}

public function testProcessEmbeddedResourcesNoAvailableIncludes()
{
$transformer = m::mock('League\Fractal\TransformerAbstract')->makePartial();
Expand Down

0 comments on commit 8b9d39b

Please sign in to comment.