7 declare(strict_types=1);
24 private $resultJsonFactoryMock;
36 $this->resultJsonFactoryMock = $this->getMockBuilder(JsonFactory::class)
37 ->disableOriginalConstructor()
38 ->setMethods([
'create',
'setData'])
41 $this->contextMock = $this->getMockBuilder(Context::class)
42 ->disableOriginalConstructor()
43 ->setMethods([
'getRequest'])
56 private function setObjectProperty($object,
string $propertyName,
$value) : void
60 $reflectionProperty->setAccessible(
true);
61 $reflectionProperty->setValue($object,
$value);
69 $value = [
'id' => 3,
'path' =>
'1/2/3',
'parentId' => 2];
70 $result =
'{"id":3,"path":"1/2/3","parentId":"2"}';
72 $requestMock = $this->getMockForAbstractClass(\
Magento\Framework\
App\RequestInterface::class);
74 $refreshPath = $this->getMockBuilder(RefreshPath::class)
75 ->setMethods([
'getRequest',
'create'])
76 ->setConstructorArgs([
78 $this->resultJsonFactoryMock,
81 $refreshPath->expects($this->any())->method(
'getRequest')->willReturn($requestMock);
82 $requestMock->expects($this->any())->method(
'getParam')->with(
'id')->willReturn(
$value[
'id']);
84 $categoryMock = $this->getMockBuilder(\
Magento\Catalog\Model\Category::class)
85 ->disableOriginalConstructor()
86 ->setMethods([
'getPath',
'getParentId',
'getResource'])
89 $categoryMock->expects($this->any())->method(
'getPath')->willReturn(
$value[
'path']);
90 $categoryMock->expects($this->any())->method(
'getParentId')->willReturn(
$value[
'parentId']);
94 $objectManagerMock = $this->getMockBuilder(ObjectManager::class)
95 ->disableOriginalConstructor()
96 ->setMethods([
'create'])
99 $this->setObjectProperty($refreshPath,
'_objectManager', $objectManagerMock);
100 $this->setObjectProperty($categoryMock,
'_resource', $categoryResource);
102 $objectManagerMock->expects($this->once())
104 ->with(\
Magento\Catalog\Model\Category::class)
105 ->willReturn($categoryMock);
107 $this->resultJsonFactoryMock->expects($this->any())->method(
'create')->willReturnSelf();
108 $this->resultJsonFactoryMock->expects($this->any())
113 $this->assertEquals(
$result, $refreshPath->execute());
121 $requestMock = $this->getMockForAbstractClass(\
Magento\Framework\
App\RequestInterface::class);
123 $refreshPath = $this->getMockBuilder(RefreshPath::class)
124 ->setMethods([
'getRequest',
'create'])
125 ->setConstructorArgs([
127 $this->resultJsonFactoryMock,
130 $refreshPath->expects($this->any())->method(
'getRequest')->willReturn($requestMock);
131 $requestMock->expects($this->any())->method(
'getParam')->with(
'id')->willReturn(
null);
133 $objectManagerMock = $this->getMockBuilder(ObjectManager::class)
134 ->disableOriginalConstructor()
135 ->setMethods([
'create'])
138 $this->setObjectProperty($refreshPath,
'_objectManager', $objectManagerMock);
140 $objectManagerMock->expects($this->never())
142 ->with(\
Magento\Catalog\Model\Category::class)
145 $refreshPath->execute();
testExecuteWithoutCategoryId()