|
2 | 2 | namespace Go\ParserReflection;
|
3 | 3 |
|
4 | 4 | use Go\ParserReflection\Stub\ClassWithConstantsAndInheritance;
|
| 5 | +use Go\ParserReflection\Stub\ClassWithMagicConstants; |
5 | 6 | use Go\ParserReflection\Stub\ClassWithMethodsAndProperties;
|
6 | 7 | use Go\ParserReflection\Stub\ClassWithScalarConstants;
|
7 | 8 | use Go\ParserReflection\Stub\FinalClass;
|
@@ -176,11 +177,42 @@ public function testNewInstanceWithoutConstructorMethod()
|
176 | 177 |
|
177 | 178 | public function testSetStaticPropertyValueMethod()
|
178 | 179 | {
|
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 | + } |
184 | 216 | }
|
185 | 217 |
|
186 | 218 | public function testGetMethodsFiltering()
|
|
0 commit comments