From 0b631ade5bbd3aee6bba9a76aa6e932d96370b0a Mon Sep 17 00:00:00 2001 From: hmlb Date: Wed, 7 Oct 2015 10:58:28 +0200 Subject: [PATCH] No concessions to code quality ! --- src/HMLB/PHPUnit/Listener/VWListener.php | 1 - src/HMLB/VW/SecretSoftware.php | 22 +++++++++++++++++----- src/Tests/VWTest.php | 1 - 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/HMLB/PHPUnit/Listener/VWListener.php b/src/HMLB/PHPUnit/Listener/VWListener.php index dca872a..91a4f62 100644 --- a/src/HMLB/PHPUnit/Listener/VWListener.php +++ b/src/HMLB/PHPUnit/Listener/VWListener.php @@ -107,4 +107,3 @@ public function endTestSuite(PHPUnit_Framework_TestSuite $suite) { } } - diff --git a/src/HMLB/VW/SecretSoftware.php b/src/HMLB/VW/SecretSoftware.php index bb7e0df..65cff69 100644 --- a/src/HMLB/VW/SecretSoftware.php +++ b/src/HMLB/VW/SecretSoftware.php @@ -3,9 +3,9 @@ namespace HMLB\VW; use PHPUnit_Framework_TestCase; -use PHPUnit_Framework_TestResult; use PHPUnit_Runner_BaseTestRunner; use ReflectionClass; +use ReflectionProperty; /** * You didn't see that. @@ -85,8 +85,7 @@ public function force(PHPUnit_Framework_TestCase $test) */ private function forcePropertyValue(ReflectionClass $reflection, $property, $value, $object) { - $propertyReflection = $reflection->getProperty($property); - $propertyReflection->setAccessible(true); + $propertyReflection = $this->accessProperty($reflection, $property); $propertyReflection->setValue($object, $value); $propertyReflection->setAccessible(false); @@ -102,11 +101,24 @@ private function forcePropertyValue(ReflectionClass $reflection, $property, $val */ private function getPropertyValue(ReflectionClass $reflection, $property, $object) { - $propertyReflection = $reflection->getProperty($property); - $propertyReflection->setAccessible(true); + $propertyReflection = $this->accessProperty($reflection, $property); $value = $propertyReflection->getValue($object); $propertyReflection->setAccessible(false); return $value; } + + /** + * @param ReflectionClass $reflection + * @param string $property + * + * @return ReflectionProperty + */ + private function accessProperty(ReflectionClass $reflection, $property) + { + $propertyReflection = $reflection->getProperty($property); + $propertyReflection->setAccessible(true); + + return $propertyReflection; + } } diff --git a/src/Tests/VWTest.php b/src/Tests/VWTest.php index d2e2743..207af8b 100644 --- a/src/Tests/VWTest.php +++ b/src/Tests/VWTest.php @@ -22,4 +22,3 @@ public function testEnvironmentalImpactCompliance() $this->assertLessThan($this->legalLimit, $this->noxEmissions); } } -