7
7
8
8
namespace Magento \Reports \Test \Unit \Model \ResourceModel \Report \Quote ;
9
9
10
- use Magento \Eav \Model \Entity \ AbstractEntity ;
10
+ use Magento \Catalog \Model \ResourceModel \ Product \ Collection as ProductCollection ;
11
11
use Magento \Eav \Model \Entity \Attribute \AbstractAttribute ;
12
- use Magento \Framework \DB \Adapter \AdapterInterface ;
13
12
use Magento \Framework \DB \Adapter \Pdo \Mysql ;
14
13
use Magento \Framework \DB \Select ;
15
14
use Magento \Framework \Event \ManagerInterface ;
16
15
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
17
16
use Magento \Quote \Model \ResourceModel \Quote ;
18
- use Magento \Reports \Model \ResourceModel \Quote \Collection ;
17
+ use Magento \Reports \Model \Product \DataRetriever as ProductDataRetriever ;
18
+ use Magento \Reports \Model \ResourceModel \Quote \Collection as QuoteCollection ;
19
+ use Magento \Reports \Model \ResourceModel \Quote \Item \Collection as QuoteItemCollection ;
20
+ use Magento \Sales \Model \ResourceModel \Order \Collection as OrderCollection ;
19
21
use PHPUnit \Framework \MockObject \MockObject ;
20
22
use PHPUnit \Framework \TestCase ;
21
23
@@ -34,16 +36,22 @@ class CollectionTest extends TestCase
34
36
*/
35
37
protected $ selectMock ;
36
38
39
+ /**
40
+ * @var ProductDataRetriever|MockObject
41
+ */
42
+ private $ productDataRetriever ;
43
+
37
44
protected function setUp (): void
38
45
{
39
46
$ this ->objectManager = new ObjectManager ($ this );
40
47
$ this ->selectMock = $ this ->createMock (Select::class);
48
+ $ this ->productDataRetriever = $ this ->createMock (ProductDataRetriever::class);
41
49
}
42
50
43
51
public function testGetSelectCountSql ()
44
52
{
45
53
/** @var MockObject $collection */
46
- $ collection = $ this ->getMockBuilder (Collection ::class)
54
+ $ collection = $ this ->getMockBuilder (QuoteCollection ::class)
47
55
->setMethods (['getSelect ' ])
48
56
->disableOriginalConstructor ()
49
57
->getMock ();
@@ -61,8 +69,8 @@ public function testPrepareActiveCartItems()
61
69
{
62
70
/** @var MockObject $collection */
63
71
$ constructArgs = $ this ->objectManager
64
- ->getConstructArguments (\ Magento \ Reports \ Model \ ResourceModel \ Quote \ Item \Collection ::class);
65
- $ collection = $ this ->getMockBuilder (\ Magento \ Reports \ Model \ ResourceModel \ Quote \ Item \Collection ::class)
72
+ ->getConstructArguments (QuoteItemCollection ::class);
73
+ $ collection = $ this ->getMockBuilder (QuoteItemCollection ::class)
66
74
->setMethods (['getSelect ' , 'getTable ' , 'getFlag ' , 'setFlag ' ])
67
75
->disableOriginalConstructor ()
68
76
->setConstructorArgs ($ constructArgs )
@@ -88,18 +96,18 @@ public function testLoadWithFilter()
88
96
{
89
97
/** @var MockObject $collection */
90
98
$ constructArgs = $ this ->objectManager
91
- ->getConstructArguments (\ Magento \ Reports \ Model \ ResourceModel \ Quote \ Item \Collection ::class);
99
+ ->getConstructArguments (QuoteItemCollection ::class);
92
100
$ constructArgs ['eventManager ' ] = $ this ->getMockForAbstractClass (ManagerInterface::class);
93
- $ connectionMock = $ this ->getMockForAbstractClass (AdapterInterface::class);
94
101
$ resourceMock = $ this ->createMock (Quote::class);
95
102
$ resourceMock ->expects ($ this ->any ())->method ('getConnection ' )
96
103
->willReturn ($ this ->createMock (Mysql::class));
97
104
$ constructArgs ['resource ' ] = $ resourceMock ;
98
- $ productResourceMock = $ this ->createMock (\ Magento \ Catalog \ Model \ ResourceModel \ Product \Collection ::class);
105
+ $ productResourceMock = $ this ->createMock (ProductCollection ::class);
99
106
$ constructArgs ['productResource ' ] = $ productResourceMock ;
100
- $ orderResourceMock = $ this ->createMock (\ Magento \ Sales \ Model \ ResourceModel \ Order \Collection ::class);
107
+ $ orderResourceMock = $ this ->createMock (OrderCollection ::class);
101
108
$ constructArgs ['orderResource ' ] = $ orderResourceMock ;
102
- $ collection = $ this ->getMockBuilder (\Magento \Reports \Model \ResourceModel \Quote \Item \Collection::class)
109
+ $ constructArgs ['productDataRetriever ' ] = $ this ->productDataRetriever ;
110
+ $ collection = $ this ->getMockBuilder (QuoteItemCollection::class)
103
111
->setMethods (
104
112
[
105
113
'_beforeLoad ' ,
@@ -129,24 +137,12 @@ public function testLoadWithFilter()
129
137
//productLoad()
130
138
$ productAttributeMock = $ this ->createMock (AbstractAttribute::class);
131
139
$ priceAttributeMock = $ this ->createMock (AbstractAttribute::class);
132
- $ productResourceMock ->expects ($ this ->once ())->method ('getConnection ' )->willReturn ($ connectionMock );
133
140
$ productResourceMock ->expects ($ this ->any ())->method ('getAttribute ' )
134
141
->willReturnMap ([['name ' , $ productAttributeMock ], ['price ' , $ priceAttributeMock ]]);
135
- $ productResourceMock ->expects ($ this ->once ())->method ('getSelect ' )->willReturn ($ this ->selectMock );
136
- $ eavEntity = $ this ->createMock (AbstractEntity::class);
137
- $ eavEntity ->expects ($ this ->once ())->method ('getLinkField ' )->willReturn ('entity_id ' );
138
- $ productResourceMock ->expects ($ this ->once ())->method ('getEntity ' )->willReturn ($ eavEntity );
139
- $ this ->selectMock ->expects ($ this ->once ())->method ('reset ' )->willReturnSelf ();
140
- $ this ->selectMock ->expects ($ this ->once ())->method ('from ' )->willReturnSelf ();
141
- $ this ->selectMock ->expects ($ this ->once ())->method ('useStraightJoin ' )->willReturnSelf ();
142
- $ this ->selectMock ->expects ($ this ->once ())->method ('joinInner ' )->willReturnSelf ();
143
- $ this ->selectMock ->expects ($ this ->once ())->method ('joinLeft ' )->willReturnSelf ();
144
142
$ collection ->expects ($ this ->once ())->method ('getOrdersData ' )->willReturn ([]);
145
- $ productAttributeMock ->expects ($ this ->once ())->method ('getBackend ' )->willReturnSelf ();
146
- $ priceAttributeMock ->expects ($ this ->once ())->method ('getBackend ' )->willReturnSelf ();
147
- $ connectionMock ->expects ($ this ->once ())->method ('fetchAssoc ' )->willReturn ([1 , 2 , 3 ]);
148
143
//_afterLoad()
149
144
$ collection ->expects ($ this ->once ())->method ('getItems ' )->willReturn ([]);
145
+ $ this ->productDataRetriever ->expects ($ this ->once ())->method ('execute ' )->willReturn ([]);
150
146
$ collection ->loadWithFilter ();
151
147
}
152
148
}
0 commit comments