TestCase.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
  4. * @author Mediotype https://www.mediotype.com/
  5. */
  6. namespace Vertex\Tax\Test\Unit;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  8. /**
  9. * @SuppressWarnings(PHPMD.NumberOfChildren)
  10. */
  11. class TestCase extends \PHPUnit\Framework\TestCase
  12. {
  13. /** @var ObjectManager */
  14. protected $objectManager;
  15. protected function setUp()
  16. {
  17. $this->objectManager = new ObjectManager($this);
  18. parent::setUp();
  19. }
  20. protected function getObject($className, $arguments = [])
  21. {
  22. return $this->objectManager->getObject($className, $arguments);
  23. }
  24. protected function getCollection($className, $data = [])
  25. {
  26. return $this->objectManager->getCollectionMock($className, $data);
  27. }
  28. public function invokeInaccessibleMethod(&$object, $methodName)
  29. {
  30. $parameters = array_slice(func_get_args(), 2);
  31. $reflection = new \ReflectionMethod(get_class($object), $methodName);
  32. $reflection->setAccessible(true);
  33. return $reflection->invokeArgs($object, $parameters);
  34. }
  35. public function setInaccessibleProperty(&$object, $propertyName, $value)
  36. {
  37. $reflection = new \ReflectionProperty(get_class($object), $propertyName);
  38. $reflection->setAccessible(true);
  39. $reflection->setValue($object, $value);
  40. }
  41. public function setProtectedProperty(&$object, $propertyName, $value)
  42. {
  43. $reflection = new \ReflectionClass($object);
  44. $property = $reflection->getProperty($propertyName);
  45. $property->setAccessible(true);
  46. $property->setValue($object, $value);
  47. }
  48. }