Skip to content

Commit 9e8dffc

Browse files
loren-osbornaik099
authored andcommitted
Eliminate nonsencical forward_static_call()s (#86)
1 parent 31bd6b5 commit 9e8dffc

4 files changed

+44
-10
lines changed

src/Traits/ReflectionClassLikeTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ public function getStaticProperties()
800800
{
801801
// In runtime static properties can be changed in any time
802802
if ($this->isInitialized()) {
803-
return forward_static_call('parent::getStaticProperties');
803+
return parent::getStaticProperties();
804804
}
805805

806806
$properties = [];
@@ -908,7 +908,7 @@ public function setStaticPropertyValue($name, $value)
908908
{
909909
$this->initializeInternalReflection();
910910

911-
forward_static_call('parent::setStaticPropertyValue', $name, $value);
911+
parent::setStaticPropertyValue($name, $value);
912912
}
913913

914914
private function recursiveCollect(\Closure $collector)

src/Traits/ReflectionFunctionLikeTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getClosureScopeClass()
5353
{
5454
$this->initializeInternalReflection();
5555

56-
return forward_static_call('parent::getClosureScopeClass');
56+
return parent::getClosureScopeClass();
5757
}
5858

5959
/**
@@ -63,7 +63,7 @@ public function getClosureThis()
6363
{
6464
$this->initializeInternalReflection();
6565

66-
return forward_static_call('parent::getClosureThis');
66+
return parent::getClosureThis();
6767
}
6868

6969
public function getDocComment()

tests/AbstractTestCase.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
1515
{
16+
const DEFAULT_STUB_FILENAME = '/Stub/FileWithClasses55.php';
17+
1618
/**
1719
* @var ReflectionFileNamespace
1820
*/
@@ -109,6 +111,6 @@ protected function setUpFile($fileName)
109111

110112
protected function setUp()
111113
{
112-
$this->setUpFile(__DIR__ . '/Stub/FileWithClasses55.php');
114+
$this->setUpFile(__DIR__ . self::DEFAULT_STUB_FILENAME);
113115
}
114116
}

tests/ReflectionClassTest.php

+37-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace Go\ParserReflection;
33

44
use Go\ParserReflection\Stub\ClassWithConstantsAndInheritance;
5+
use Go\ParserReflection\Stub\ClassWithMagicConstants;
56
use Go\ParserReflection\Stub\ClassWithMethodsAndProperties;
67
use Go\ParserReflection\Stub\ClassWithScalarConstants;
78
use Go\ParserReflection\Stub\FinalClass;
@@ -176,11 +177,42 @@ public function testNewInstanceWithoutConstructorMethod()
176177

177178
public function testSetStaticPropertyValueMethod()
178179
{
179-
$parsedRefClass = $this->parsedRefFileNamespace->getClass(ClassWithConstantsAndInheritance::class);
180-
$originalRefClass = new \ReflectionClass(ClassWithConstantsAndInheritance::class);
181-
182-
$parsedRefClass->setStaticPropertyValue('h', 'test');
183-
$this->assertSame($parsedRefClass->getStaticPropertyValue('h'), $originalRefClass->getStaticPropertyValue('h'));
180+
$parsedRefClass1 = $this->parsedRefFileNamespace->getClass(ClassWithConstantsAndInheritance::class);
181+
$originalRefClass1 = new \ReflectionClass(ClassWithConstantsAndInheritance::class);
182+
$parsedRefClass2 = $this->parsedRefFileNamespace->getClass(ClassWithMagicConstants::class);
183+
$originalRefClass2 = new \ReflectionClass(ClassWithMagicConstants::class);
184+
$defaultProp1Value = $originalRefClass1->getStaticPropertyValue('h');
185+
$defaultProp2Value = $originalRefClass2->getStaticPropertyValue('a');
186+
$ex = null;
187+
try {
188+
$this->assertEquals(M_PI, $parsedRefClass1->getStaticPropertyValue('h'), 'Close to expected value of M_PI', 0.0001);
189+
$this->assertEquals(M_PI, $originalRefClass1->getStaticPropertyValue('h'), 'Close to expected value of M_PI', 0.0001);
190+
$this->assertEquals(
191+
realpath(dirname(__DIR__ . parent::DEFAULT_STUB_FILENAME)),
192+
realpath($parsedRefClass2->getStaticPropertyValue('a')),
193+
'Expected value');
194+
$this->assertEquals(
195+
$originalRefClass2->getStaticPropertyValue('a'),
196+
$parsedRefClass2->getStaticPropertyValue('a'),
197+
'Same as native implementation');
198+
199+
$parsedRefClass1->setStaticPropertyValue('h', 'test');
200+
$parsedRefClass2->setStaticPropertyValue('a', 'different value');
201+
202+
$this->assertSame('test', $parsedRefClass1->getStaticPropertyValue('h'));
203+
$this->assertSame('test', $originalRefClass1->getStaticPropertyValue('h'));
204+
$this->assertSame('different value', $parsedRefClass2->getStaticPropertyValue('a'));
205+
$this->assertSame('different value', $originalRefClass2->getStaticPropertyValue('a'));
206+
}
207+
catch (\Exception $e) {
208+
$ex = $e;
209+
}
210+
// I didn't want to write a tearDown() for one test.
211+
$originalRefClass1->setStaticPropertyValue('h', $defaultProp1Value);
212+
$originalRefClass2->setStaticPropertyValue('a', $defaultProp2Value);
213+
if ($ex) {
214+
throw $ex;
215+
}
184216
}
185217

186218
public function testGetMethodsFiltering()

0 commit comments

Comments
 (0)