|
5 | 5 | */ |
6 | 6 | namespace Magento\Store\Test\Unit\Model; |
7 | 7 |
|
8 | | -use Magento\Store\Api\Data\WebsiteInterface; |
9 | 8 | use Magento\Store\Api\Data\GroupInterface; |
10 | 9 | use Magento\Store\Api\Data\StoreInterface; |
| 10 | +use Magento\Store\Api\Data\WebsiteInterface; |
| 11 | +use Magento\Store\Api\GroupRepositoryInterface; |
| 12 | +use Magento\Store\Api\StoreRepositoryInterface; |
| 13 | +use Magento\Store\Api\WebsiteRepositoryInterface; |
11 | 14 | use Magento\Store\Model\Group; |
12 | 15 | use Magento\Store\Model\ScopeTreeProvider; |
13 | 16 | use Magento\Store\Model\Store; |
|
16 | 19 | use Magento\Framework\App\Config\ScopeConfigInterface; |
17 | 20 | use Magento\Store\Model\Website; |
18 | 21 |
|
| 22 | +/** |
| 23 | + * @covers \Magento\Store\Model\ScopeTreeProvider |
| 24 | + */ |
19 | 25 | class ScopeTreeProviderTest extends \PHPUnit\Framework\TestCase |
20 | 26 | { |
21 | | - /** @var ScopeTreeProvider */ |
22 | | - protected $model; |
| 27 | + /** |
| 28 | + * @var ScopeTreeProvider |
| 29 | + */ |
| 30 | + private $model; |
23 | 31 |
|
24 | | - /** @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject */ |
25 | | - protected $storeManagerMock; |
| 32 | + /** |
| 33 | + * @var \PHPUnit_Framework_MockObject_MockObject|WebsiteRepositoryInterface |
| 34 | + */ |
| 35 | + private $websiteRepositoryMock; |
| 36 | + |
| 37 | + /** |
| 38 | + * @var \PHPUnit_Framework_MockObject_MockObject|GroupRepositoryInterface |
| 39 | + */ |
| 40 | + private $groupRepositoryMock; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var \PHPUnit_Framework_MockObject_MockObject|StoreRepositoryInterface |
| 44 | + */ |
| 45 | + private $storeRepositoryMock; |
26 | 46 |
|
27 | 47 | protected function setUp() |
28 | 48 | { |
29 | | - $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class) |
30 | | - ->getMockForAbstractClass(); |
| 49 | + $this->websiteRepositoryMock = $this->createMock(WebsiteRepositoryInterface::class); |
| 50 | + $this->groupRepositoryMock = $this->createMock(GroupRepositoryInterface::class); |
| 51 | + $this->storeRepositoryMock = $this->createMock(StoreRepositoryInterface::class); |
31 | 52 |
|
32 | | - $this->model = new ScopeTreeProvider($this->storeManagerMock); |
| 53 | + $this->model = new ScopeTreeProvider( |
| 54 | + $this->websiteRepositoryMock, |
| 55 | + $this->groupRepositoryMock, |
| 56 | + $this->storeRepositoryMock |
| 57 | + ); |
33 | 58 | } |
34 | 59 |
|
35 | 60 | public function testGet() |
@@ -58,40 +83,34 @@ public function testGet() |
58 | 83 | 'scopes' => [$websiteData], |
59 | 84 | ]; |
60 | 85 |
|
61 | | - /** @var Website|\PHPUnit_Framework_MockObject_MockObject $websiteMock */ |
62 | | - $websiteMock = $this->getMockBuilder(\Magento\Store\Model\Website::class) |
63 | | - ->disableOriginalConstructor() |
64 | | - ->getMock(); |
65 | | - $websiteMock->expects($this->any()) |
| 86 | + $websiteMock = $this->createMock(WebsiteInterface::class); |
| 87 | + $websiteMock->expects($this->atLeastOnce()) |
66 | 88 | ->method('getId') |
67 | 89 | ->willReturn($websiteId); |
| 90 | + $this->websiteRepositoryMock->expects($this->once()) |
| 91 | + ->method('getList') |
| 92 | + ->willReturn([$websiteMock]); |
68 | 93 |
|
69 | | - /** @var Group|\PHPUnit_Framework_MockObject_MockObject $groupMock */ |
70 | | - $groupMock = $this->getMockBuilder(\Magento\Store\Model\Group::class) |
71 | | - ->disableOriginalConstructor() |
72 | | - ->getMock(); |
73 | | - $groupMock->expects($this->any()) |
| 94 | + $groupMock = $this->createMock(GroupInterface::class); |
| 95 | + $groupMock->expects($this->atLeastOnce()) |
74 | 96 | ->method('getId') |
75 | 97 | ->willReturn($groupId); |
| 98 | + $groupMock->expects($this->atLeastOnce()) |
| 99 | + ->method('getWebsiteId') |
| 100 | + ->willReturn($websiteId); |
| 101 | + $this->groupRepositoryMock->expects($this->once()) |
| 102 | + ->method('getList') |
| 103 | + ->willReturn([$groupMock, $groupMock]); |
76 | 104 |
|
77 | | - /** @var Store|\PHPUnit_Framework_MockObject_MockObject $storeMock */ |
78 | | - $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class) |
79 | | - ->disableOriginalConstructor() |
80 | | - ->getMock(); |
81 | | - $storeMock->expects($this->any()) |
| 105 | + $storeMock = $this->createMock(StoreInterface::class); |
| 106 | + $storeMock->expects($this->atLeastOnce()) |
82 | 107 | ->method('getId') |
83 | 108 | ->willReturn($storeId); |
84 | | - |
85 | | - $this->storeManagerMock->expects($this->any()) |
86 | | - ->method('getWebsites') |
87 | | - ->willReturn([$websiteMock]); |
88 | | - |
89 | | - $websiteMock->expects($this->any()) |
90 | | - ->method('getGroups') |
91 | | - ->willReturn([$groupMock, $groupMock]); |
92 | | - |
93 | | - $groupMock->expects($this->any()) |
94 | | - ->method('getStores') |
| 109 | + $storeMock->expects($this->atLeastOnce()) |
| 110 | + ->method('getStoreGroupId') |
| 111 | + ->willReturn($groupId); |
| 112 | + $this->storeRepositoryMock->expects($this->once()) |
| 113 | + ->method('getList') |
95 | 114 | ->willReturn([$storeMock, $storeMock, $storeMock]); |
96 | 115 |
|
97 | 116 | $this->assertEquals($result, $this->model->get()); |
|
0 commit comments