19
19
use Magento \Eav \Model \Entity \Type ;
20
20
use Magento \Framework \Filesystem ;
21
21
use Magento \Framework \Filesystem \Directory \WriteInterface ;
22
- use Magento \TestFramework \Helper \Bootstrap ;
22
+ use Magento \Framework \Filesystem \File \WriteInterface as FileWriteInterface ;
23
+ use Magento \Framework \Filesystem \Driver \File ;
23
24
24
25
/**
25
26
* Integration test for product view front action.
@@ -84,11 +85,10 @@ public function testViewActionWithCanonicalTag(): void
84
85
* View product with custom attribute when attribute removed from it.
85
86
*
86
87
* It tests that after changing product attribute set from Default to Custom
87
- * there are no waring messages in log in case Custom not contains attribute from Default.
88
+ * there are no warning messages in log in case Custom not contains attribute from Default.
88
89
*
89
90
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_country_of_manufacture.php
90
91
* @magentoDataFixture Magento/Catalog/_files/attribute_set_based_on_default_without_country_of_manufacture.php
91
- * @magentoDbIsolation disabled
92
92
* @return void
93
93
*/
94
94
public function testViewActionCustomAttributeSetWithoutCountryOfManufacture (): void
@@ -129,9 +129,7 @@ private function checkSystemLogForMessage(string $message): bool
129
129
*/
130
130
private function getProductBySku (string $ sku ): Product
131
131
{
132
- $ product = $ this ->productRepository ->get ($ sku );
133
-
134
- return $ product ;
132
+ return $ this ->productRepository ->get ($ sku );
135
133
}
136
134
137
135
/**
@@ -175,31 +173,28 @@ private function getProductAttributeSetByName(string $attributeSetName): ?Set
175
173
private function getSystemLogContent (): string
176
174
{
177
175
$ logDir = $ this ->getLogDirectoryWrite ();
178
- $ logFullFileName = $ logDir ->getAbsolutePath ($ this ->systemLogFileName );
179
- $ content = $ this ->tail ($ logFullFileName , 10 );
176
+ $ logFile = $ logDir ->openFile ($ this ->systemLogFileName , ' rb ' );
177
+ $ content = $ this ->tail ($ logFile , 10 );
180
178
181
179
return $ content ;
182
180
}
183
181
184
182
/**
185
183
* Get file tail.
186
184
*
187
- * @param string $filename
185
+ * @param FileWriteInterface $file
188
186
* @param int $lines
189
187
* @param int $buffer
190
188
* @return false|string
191
189
*/
192
- private function tail (string $ filename , int $ lines = 10 , int $ buffer = 4096 )
190
+ private function tail (FileWriteInterface $ file , int $ lines = 10 , int $ buffer = 4096 )
193
191
{
194
- // Open the file
195
- $ f = fopen ($ filename , "rb " );
196
-
197
192
// Jump to last character
198
- fseek ( $ f , -1 , SEEK_END );
193
+ $ file -> seek ( -1 , SEEK_END );
199
194
200
195
// Read it and adjust line number if necessary
201
196
// (Otherwise the result would be wrong if file doesn't end with a blank line)
202
- if (fread ( $ f , 1 ) != "\n" ) {
197
+ if ($ file -> read ( 1 ) != "\n" ) {
203
198
$ lines --;
204
199
}
205
200
@@ -208,18 +203,18 @@ private function tail(string $filename, int $lines = 10, int $buffer = 4096)
208
203
$ chunk = '' ;
209
204
210
205
// While we would like more
211
- while (ftell ( $ f ) > 0 && $ lines >= 0 ) {
206
+ while ($ file -> tell ( ) > 0 && $ lines >= 0 ) {
212
207
// Figure out how far back we should jump
213
- $ seek = min (ftell ( $ f ), $ buffer );
208
+ $ seek = min ($ file -> tell ( ), $ buffer );
214
209
215
210
// Do the jump (backwards, relative to where we are)
216
- fseek ( $ f , -$ seek , SEEK_CUR );
211
+ $ file -> seek ( -$ seek , SEEK_CUR );
217
212
218
213
// Read a chunk and prepend it to our output
219
- $ output = ($ chunk = fread ( $ f , $ seek )) . $ output ;
214
+ $ output = ($ chunk = $ file -> read ( $ seek )) . $ output ;
220
215
221
216
// Jump back to where we started reading
222
- fseek ( $ f , -mb_strlen ($ chunk , '8bit ' ), SEEK_CUR );
217
+ $ file -> seek ( -mb_strlen ($ chunk , '8bit ' ), SEEK_CUR );
223
218
224
219
// Decrease our line counter
225
220
$ lines -= substr_count ($ chunk , "\n" );
@@ -233,7 +228,7 @@ private function tail(string $filename, int $lines = 10, int $buffer = 4096)
233
228
}
234
229
235
230
// Close file and return
236
- fclose ( $ f );
231
+ $ file -> close ( );
237
232
238
233
return $ output ;
239
234
}
0 commit comments