Skip to content

Commit 8b9d39b

Browse files
authored
add test case for accessing current scope before its value has been set (#552)
1 parent 94ce1fd commit 8b9d39b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/TransformerAbstract.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ abstract class TransformerAbstract
3838
/**
3939
* The transformer should know about the current scope, so we can fetch relevant params.
4040
*/
41-
protected ?Scope $currentScope;
41+
protected ?Scope $currentScope = null;
4242

4343
/**
4444
* Getter for availableIncludes.

test/TransformerAbstractTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,16 @@ public function testGetCurrentScope()
7474
$this->assertSame($transformer->getCurrentScope(), $scope);
7575
}
7676

77+
/**
78+
* @covers \League\Fractal\TransformerAbstract::getCurrentScope
79+
*/
80+
public function testCanAccessScopeBeforeInitialization()
81+
{
82+
$transformer = $this->getMockForAbstractClass('League\Fractal\TransformerAbstract');
83+
$currentScope = $transformer->getCurrentScope();
84+
$this->assertNull($currentScope);
85+
}
86+
7787
public function testProcessEmbeddedResourcesNoAvailableIncludes()
7888
{
7989
$transformer = m::mock('League\Fractal\TransformerAbstract')->makePartial();

0 commit comments

Comments
 (0)