12
12
use Magento \Analytics \Model \ReportWriter ;
13
13
use Magento \Analytics \ReportXml \DB \ReportValidator ;
14
14
use Magento \Analytics \ReportXml \ReportProvider ;
15
- use Magento \Framework \Filesystem \Directory \WriteInterface ;
15
+ use Magento \Framework \Filesystem \Directory \WriteInterface as DirectoryWriteInterface ;
16
+ use Magento \Framework \Filesystem \File \WriteInterface as FileWriteInterface ;
16
17
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
17
18
use PHPUnit \Framework \MockObject \MockObject ;
18
19
use PHPUnit \Framework \TestCase ;
@@ -48,7 +49,7 @@ class ReportWriterTest extends TestCase
48
49
private $ objectManagerHelper ;
49
50
50
51
/**
51
- * @var WriteInterface |MockObject
52
+ * @var DirectoryWriteInterface |MockObject
52
53
*/
53
54
private $ directoryMock ;
54
55
@@ -82,7 +83,7 @@ protected function setUp(): void
82
83
$ this ->reportValidatorMock = $ this ->createMock (ReportValidator::class);
83
84
$ this ->providerFactoryMock = $ this ->createMock (ProviderFactory::class);
84
85
$ this ->reportProviderMock = $ this ->createMock (ReportProvider::class);
85
- $ this ->directoryMock = $ this ->getMockBuilder (WriteInterface ::class)
86
+ $ this ->directoryMock = $ this ->getMockBuilder (DirectoryWriteInterface ::class)
86
87
->getMockForAbstractClass ();
87
88
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
88
89
@@ -98,16 +99,15 @@ protected function setUp(): void
98
99
99
100
/**
100
101
* @param array $configData
102
+ * @param array $fileData
103
+ * @param array $expectedFileData
101
104
* @return void
102
105
*
103
106
* @dataProvider configDataProvider
104
107
*/
105
- public function testWrite (array $ configData)
108
+ public function testWrite (array $ configData, array $ fileData , array $ expectedFileData ): void
106
109
{
107
110
$ errors = [];
108
- $ fileData = [
109
- ['number ' => 1 , 'type ' => 'Shoes Usual ' ]
110
- ];
111
111
$ this ->configInterfaceMock
112
112
->expects ($ this ->once ())
113
113
->method ('get ' )
@@ -126,7 +126,7 @@ public function testWrite(array $configData)
126
126
->with ($ parameterName ?: null )
127
127
->willReturn ($ fileData );
128
128
$ errorStreamMock = $ this ->getMockBuilder (
129
- \ Magento \ Framework \ Filesystem \ File \WriteInterface ::class
129
+ FileWriteInterface ::class
130
130
)->getMockForAbstractClass ();
131
131
$ errorStreamMock
132
132
->expects ($ this ->once ())
@@ -136,8 +136,8 @@ public function testWrite(array $configData)
136
136
->expects ($ this ->exactly (2 ))
137
137
->method ('writeCsv ' )
138
138
->withConsecutive (
139
- [array_keys ($ fileData [0 ])],
140
- [$ fileData [0 ]]
139
+ [array_keys ($ expectedFileData [0 ])],
140
+ [$ expectedFileData [0 ]]
141
141
);
142
142
$ errorStreamMock ->expects ($ this ->once ())->method ('unlock ' );
143
143
$ errorStreamMock ->expects ($ this ->once ())->method ('close ' );
@@ -164,12 +164,12 @@ public function testWrite(array $configData)
164
164
*
165
165
* @dataProvider configDataProvider
166
166
*/
167
- public function testWriteErrorFile ($ configData )
167
+ public function testWriteErrorFile (array $ configData ): void
168
168
{
169
169
$ errors = ['orders ' , 'SQL Error: test ' ];
170
170
$ this ->configInterfaceMock ->expects ($ this ->once ())->method ('get ' )->willReturn ([$ configData ]);
171
171
$ errorStreamMock = $ this ->getMockBuilder (
172
- \ Magento \ Framework \ Filesystem \ File \WriteInterface ::class
172
+ FileWriteInterface ::class
173
173
)->getMockForAbstractClass ();
174
174
$ errorStreamMock ->expects ($ this ->once ())->method ('lock ' );
175
175
$ errorStreamMock ->expects ($ this ->once ())->method ('writeCsv ' )->with ($ errors );
@@ -184,7 +184,7 @@ public function testWriteErrorFile($configData)
184
184
/**
185
185
* @return void
186
186
*/
187
- public function testWriteEmptyReports ()
187
+ public function testWriteEmptyReports (): void
188
188
{
189
189
$ this ->configInterfaceMock ->expects ($ this ->once ())->method ('get ' )->willReturn ([]);
190
190
$ this ->reportValidatorMock ->expects ($ this ->never ())->method ('validate ' );
@@ -195,11 +195,11 @@ public function testWriteEmptyReports()
195
195
/**
196
196
* @return array
197
197
*/
198
- public function configDataProvider ()
198
+ public function configDataProvider (): array
199
199
{
200
200
return [
201
201
'reportProvider ' => [
202
- [
202
+ ' configData ' => [
203
203
'providers ' => [
204
204
[
205
205
'name ' => $ this ->providerName ,
@@ -209,6 +209,12 @@ public function configDataProvider()
209
209
],
210
210
]
211
211
]
212
+ ],
213
+ 'fileData ' => [
214
+ ['number ' => 1 , 'type ' => 'Shoes\"" Usual \\\\" ' ]
215
+ ],
216
+ 'expectedFileData ' => [
217
+ ['number ' => 1 , 'type ' => 'Shoes\"\" Usual \\" ' ]
212
218
]
213
219
],
214
220
];
0 commit comments