3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Analytics \Test \Unit \Model ;
7
9
8
10
use Magento \Analytics \Model \ConfigInterface ;
9
11
use Magento \Analytics \Model \ProviderFactory ;
10
12
use Magento \Analytics \Model \ReportWriter ;
11
13
use Magento \Analytics \ReportXml \DB \ReportValidator ;
12
14
use Magento \Analytics \ReportXml \ReportProvider ;
13
- use Magento \Framework \Filesystem \Directory \WriteInterface ;
15
+ use Magento \Framework \Filesystem \Directory \WriteInterface as DirectoryWriteInterface ;
16
+ use Magento \Framework \Filesystem \File \WriteInterface as FileWriteInterface ;
14
17
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
18
+ use PHPUnit \Framework \MockObject \MockObject ;
19
+ use PHPUnit \Framework \TestCase ;
15
20
16
21
/**
17
22
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18
23
*/
19
- class ReportWriterTest extends \ PHPUnit \ Framework \ TestCase
24
+ class ReportWriterTest extends TestCase
20
25
{
21
26
/**
22
- * @var ConfigInterface|\PHPUnit_Framework_MockObject_MockObject
27
+ * @var ConfigInterface|MockObject
23
28
*/
24
29
private $ configInterfaceMock ;
25
30
26
31
/**
27
- * @var ReportValidator|\PHPUnit_Framework_MockObject_MockObject
32
+ * @var ReportValidator|MockObject
28
33
*/
29
34
private $ reportValidatorMock ;
30
35
31
36
/**
32
- * @var ProviderFactory|\PHPUnit_Framework_MockObject_MockObject
37
+ * @var ProviderFactory|MockObject
33
38
*/
34
39
private $ providerFactoryMock ;
35
40
36
41
/**
37
- * @var ReportProvider|\PHPUnit_Framework_MockObject_MockObject
42
+ * @var ReportProvider|MockObject
38
43
*/
39
44
private $ reportProviderMock ;
40
45
@@ -44,7 +49,7 @@ class ReportWriterTest extends \PHPUnit\Framework\TestCase
44
49
private $ objectManagerHelper ;
45
50
46
51
/**
47
- * @var WriteInterface|\PHPUnit_Framework_MockObject_MockObject
52
+ * @var DirectoryWriteInterface|MockObject
48
53
*/
49
54
private $ directoryMock ;
50
55
@@ -80,7 +85,7 @@ protected function setUp()
80
85
->disableOriginalConstructor ()->getMock ();
81
86
$ this ->reportProviderMock = $ this ->getMockBuilder (ReportProvider::class)
82
87
->disableOriginalConstructor ()->getMock ();
83
- $ this ->directoryMock = $ this ->getMockBuilder (WriteInterface ::class)->getMockForAbstractClass ();
88
+ $ this ->directoryMock = $ this ->getMockBuilder (DirectoryWriteInterface ::class)->getMockForAbstractClass ();
84
89
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
85
90
86
91
$ this ->reportWriter = $ this ->objectManagerHelper ->getObject (
@@ -95,16 +100,15 @@ protected function setUp()
95
100
96
101
/**
97
102
* @param array $configData
103
+ * @param array $fileData
104
+ * @param array $expectedFileData
98
105
* @return void
99
106
*
100
107
* @dataProvider configDataProvider
101
108
*/
102
- public function testWrite (array $ configData )
109
+ public function testWrite (array $ configData, array $ fileData , array $ expectedFileData )
103
110
{
104
111
$ errors = [];
105
- $ fileData = [
106
- ['number ' => 1 , 'type ' => 'Shoes Usual ' ]
107
- ];
108
112
$ this ->configInterfaceMock
109
113
->expects ($ this ->once ())
110
114
->method ('get ' )
@@ -123,7 +127,7 @@ public function testWrite(array $configData)
123
127
->with ($ parameterName ?: null )
124
128
->willReturn ($ fileData );
125
129
$ errorStreamMock = $ this ->getMockBuilder (
126
- \ Magento \ Framework \ Filesystem \ File \WriteInterface ::class
130
+ FileWriteInterface ::class
127
131
)->getMockForAbstractClass ();
128
132
$ errorStreamMock
129
133
->expects ($ this ->once ())
@@ -133,8 +137,8 @@ public function testWrite(array $configData)
133
137
->expects ($ this ->exactly (2 ))
134
138
->method ('writeCsv ' )
135
139
->withConsecutive (
136
- [array_keys ($ fileData [0 ])],
137
- [$ fileData [0 ]]
140
+ [array_keys ($ expectedFileData [0 ])],
141
+ [$ expectedFileData [0 ]]
138
142
);
139
143
$ errorStreamMock ->expects ($ this ->once ())->method ('unlock ' );
140
144
$ errorStreamMock ->expects ($ this ->once ())->method ('close ' );
@@ -166,7 +170,7 @@ public function testWriteErrorFile($configData)
166
170
$ errors = ['orders ' , 'SQL Error: test ' ];
167
171
$ this ->configInterfaceMock ->expects ($ this ->once ())->method ('get ' )->willReturn ([$ configData ]);
168
172
$ errorStreamMock = $ this ->getMockBuilder (
169
- \ Magento \ Framework \ Filesystem \ File \WriteInterface ::class
173
+ FileWriteInterface ::class
170
174
)->getMockForAbstractClass ();
171
175
$ errorStreamMock ->expects ($ this ->once ())->method ('lock ' );
172
176
$ errorStreamMock ->expects ($ this ->once ())->method ('writeCsv ' )->with ($ errors );
@@ -196,7 +200,7 @@ public function configDataProvider()
196
200
{
197
201
return [
198
202
'reportProvider ' => [
199
- [
203
+ ' configData ' => [
200
204
'providers ' => [
201
205
[
202
206
'name ' => $ this ->providerName ,
@@ -206,6 +210,12 @@ public function configDataProvider()
206
210
],
207
211
]
208
212
]
213
+ ],
214
+ 'fileData ' => [
215
+ ['number ' => 1 , 'type ' => 'Shoes\"" Usual \\\\" ' ]
216
+ ],
217
+ 'expectedFileData ' => [
218
+ ['number ' => 1 , 'type ' => 'Shoes\"\" Usual \\" ' ]
209
219
]
210
220
],
211
221
];
0 commit comments