From 2ebf9e49e380e0892763b64c055736dd08806bea Mon Sep 17 00:00:00 2001 From: David Pugh Date: Fri, 8 Apr 2022 11:46:01 +0100 Subject: [PATCH] add test case for accessing current scope before its value has been set --- src/TransformerAbstract.php | 2 +- test/TransformerAbstractTest.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/TransformerAbstract.php b/src/TransformerAbstract.php index 94f05614..5464077e 100644 --- a/src/TransformerAbstract.php +++ b/src/TransformerAbstract.php @@ -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. diff --git a/test/TransformerAbstractTest.php b/test/TransformerAbstractTest.php index cfe8f6aa..6a705e4a 100755 --- a/test/TransformerAbstractTest.php +++ b/test/TransformerAbstractTest.php @@ -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();