ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package GeoIP Data for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\Geoip\Test\Unit\Traits;
|
||||
|
||||
/**
|
||||
* Create Object Manager instance for test purposes.
|
||||
*
|
||||
* @codingStandardsIgnoreFile
|
||||
*/
|
||||
trait ObjectManagerTrait
|
||||
{
|
||||
/**
|
||||
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @return \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
|
||||
*/
|
||||
private function getObjectManager()
|
||||
{
|
||||
if (!$this->objectManager) {
|
||||
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
|
||||
}
|
||||
|
||||
return $this->objectManager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* @author Amasty Team
|
||||
* @copyright Copyright (c) Amasty (https://www.amasty.com)
|
||||
* @package GeoIP Data for Magento 2 (System)
|
||||
*/
|
||||
|
||||
namespace Amasty\Geoip\Test\Unit\Traits;
|
||||
|
||||
/**
|
||||
* Provide useful methods with reflection.
|
||||
*
|
||||
* @codingStandardsIgnoreFile
|
||||
*/
|
||||
trait ReflectionTrait
|
||||
{
|
||||
/**
|
||||
* @param object $object
|
||||
* @param string $methodName
|
||||
* @param array $parameters
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
private function invokeMethod($object, $methodName, array $parameters = [])
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($object));
|
||||
$method = $reflection->getMethod($methodName);
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invokeArgs($object, $parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $object
|
||||
* @param string $propertyName
|
||||
* @param mixed $value
|
||||
* @param string $originalClassName
|
||||
*
|
||||
* @return object
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
private function setProperty($object, $propertyName, $value, $originalClassName = '')
|
||||
{
|
||||
$reflection = new \ReflectionClass($originalClassName ?: get_class($object));
|
||||
$property = $reflection->getProperty($propertyName);
|
||||
$property->setAccessible(true);
|
||||
$property->setValue($object, $value);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @param $propertyName
|
||||
* @param string $originalClassName
|
||||
*
|
||||
* @return mixed
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
private function getProperty($object, $propertyName, $originalClassName = '')
|
||||
{
|
||||
$reflection = new \ReflectionClass($originalClassName ?: get_class($object));
|
||||
$property = $reflection->getProperty($propertyName);
|
||||
$property->setAccessible(true);
|
||||
|
||||
return $property->getValue($object);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user