QRTestAbstract.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Class QRTestAbstract
  4. *
  5. * @filesource QRTestAbstract.php
  6. * @created 17.11.2017
  7. * @package chillerlan\QRCodeTest
  8. * @author Smiley <smiley@chillerlan.net>
  9. * @copyright 2017 Smiley
  10. * @license MIT
  11. */
  12. namespace chillerlan\QRCodeTest;
  13. use PHPUnit\Framework\TestCase;
  14. use ReflectionClass, ReflectionMethod, ReflectionProperty;
  15. abstract class QRTestAbstract extends TestCase{
  16. /**
  17. * @var \ReflectionClass
  18. */
  19. protected $reflection;
  20. /**
  21. * @var string
  22. */
  23. protected $FQCN;
  24. protected function setUp():void{
  25. $this->reflection = new ReflectionClass($this->FQCN);
  26. }
  27. /**
  28. * @param string $method
  29. *
  30. * @return \ReflectionMethod
  31. */
  32. protected function getMethod(string $method):ReflectionMethod {
  33. $method = $this->reflection->getMethod($method);
  34. $method->setAccessible(true);
  35. return $method;
  36. }
  37. /**
  38. * @param string $property
  39. *
  40. * @return \ReflectionProperty
  41. */
  42. protected function getProperty(string $property):ReflectionProperty{
  43. $property = $this->reflection->getProperty($property);
  44. $property->setAccessible(true);
  45. return $property;
  46. }
  47. /**
  48. * @param $object
  49. * @param string $property
  50. * @param $value
  51. *
  52. * @return void
  53. */
  54. protected function setProperty($object, string $property, $value){
  55. $property = $this->getProperty($property);
  56. $property->setAccessible(true);
  57. $property->setValue($object, $value);
  58. }
  59. }