55 */
66namespace Magento \Framework \Image \Adapter ;
77
8+ use Magento \Framework \App \Filesystem \DirectoryList ;
9+ use Magento \Framework \Filesystem \Directory \WriteInterface ;
10+
811/**
12+ * @magentoDataFixture Magento/Framework/Image/_files/image_fixture.php
913 * @magentoAppIsolation enabled
1014 */
1115class InterfaceTest extends \PHPUnit \Framework \TestCase
@@ -20,6 +24,19 @@ class InterfaceTest extends \PHPUnit\Framework\TestCase
2024 \Magento \Framework \Image \Adapter \AdapterInterface::ADAPTER_IM ,
2125 ];
2226
27+ /**
28+ * @var \Magento\Framework\ObjectManagerInterface
29+ */
30+ private $ objectManager ;
31+
32+ /**
33+ * @inheritdoc
34+ */
35+ protected function setUp (): void
36+ {
37+ $ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
38+ }
39+
2340 /**
2441 * Add adapters to each data provider case
2542 *
@@ -79,14 +96,14 @@ protected function _compareColors($colorBefore, $colorAfter)
7996 */
8097 protected function _getFixture ($ pattern )
8198 {
82- $ dir = dirname (__DIR__ ) . '/_files/ ' ;
83- $ data = glob ($ dir . $ pattern );
84-
85- if (!empty ($ data )) {
86- return $ data [0 ];
99+ if (!$ pattern ) {
100+ return null ;
87101 }
88-
89- return null ;
102+ $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
103+ /** @var $rootDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
104+ $ rootDirectory = $ objectManager ->get (\Magento \Framework \Filesystem \Directory \TargetDirectory::class)
105+ ->getDirectoryWrite (DirectoryList::TMP );
106+ return $ rootDirectory ->getAbsolutePath ('image/test/ ' . $ pattern );
90107 }
91108
92109 /**
@@ -114,8 +131,7 @@ protected function _getAdapter($adapterType)
114131 {
115132 $ adapter = null ;
116133 try {
117- $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
118- $ adapter = $ objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ($ adapterType );
134+ $ adapter = $ this ->objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ($ adapterType );
119135 } catch (\Exception $ e ) {
120136 $ this ->markTestSkipped ($ e ->getMessage ());
121137 }
@@ -206,29 +222,36 @@ public function testImageSize($image, $adapterType)
206222
207223 /**
208224 * @param string $image
209- * @param array $tempPath (dirName, newName)
225+ * @param array $tmpDir (dirName, newName)
210226 * @param string $adapterType
211227 *
228+ * @throws \Magento\Framework\Exception\FileSystemException
229+ *
212230 * @dataProvider saveDataProvider
213231 * @depends testOpen
214232 */
215- public function testSave ($ image , $ tempPath , $ adapterType )
233+ public function testSave ($ image , $ tmpDir , $ adapterType )
216234 {
217235 $ adapter = $ this ->_getAdapter ($ adapterType );
218236 $ adapter ->open ($ image );
219- try {
220- call_user_func_array ([$ adapter , 'save ' ], $ tempPath );
221- $ tempPath = join ('' , $ tempPath );
222- $ this ->assertFileExists ($ tempPath );
223- unlink ($ tempPath );
224- } catch (\Exception $ e ) {
225- $ this ->assertFalse (is_dir ($ tempPath [0 ]) && is_writable ($ tempPath [0 ]));
226- }
237+
238+ /** @var $rootDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
239+ $ rootDirectory = $ this ->objectManager ->get (\Magento \Framework \Filesystem \Directory \TargetDirectory::class)
240+ ->getDirectoryWrite (DirectoryList::TMP );
241+
242+ call_user_func_array ([$ adapter , 'save ' ], $ tmpDir );
243+ $ tmpDir = join ('' , $ tmpDir );
244+ $ this ->assertTrue ($ rootDirectory ->isExist ($ tmpDir ));
245+ $ rootDirectory ->delete ($ tmpDir );
227246 }
228247
229248 public function saveDataProvider ()
230249 {
231- $ dir = \Magento \TestFramework \Helper \Bootstrap::getInstance ()->getAppTempDir () . '/ ' ;
250+ $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
251+ /** @var $rootDirectory \Magento\Framework\Filesystem\Directory\WriteInterface */
252+ $ rootDirectory = $ objectManager ->get (\Magento \Framework \Filesystem \Directory \TargetDirectory::class)
253+ ->getDirectoryWrite (DirectoryList::TMP );
254+ $ dir = $ rootDirectory ->getAbsolutePath ('image/ ' );
232255 return $ this ->_prepareData (
233256 [
234257 [$ this ->_getFixture ('image_adapters_test.png ' ), [$ dir . uniqid ('test_image_adapter ' )]],
@@ -640,9 +663,7 @@ public function testCreatePngFromString($pixel1, $expectedColor1, $pixel2, $expe
640663 $ adapter = $ this ->_getAdapter ($ adapterType );
641664
642665 /** @var \Magento\Framework\Filesystem\Directory\ReadFactory readFactory */
643- $ readFactory = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ()->get (
644- \Magento \Framework \Filesystem \Directory \ReadFactory::class
645- );
666+ $ readFactory = $ this ->objectManager ->get (\Magento \Framework \Filesystem \Directory \ReadFactory::class);
646667 $ reader = $ readFactory ->create (BP );
647668 $ path = $ reader ->getAbsolutePath ('lib/internal/LinLibertineFont/LinLibertine_Re-4.4.1.ttf ' );
648669 $ adapter ->createPngFromString ('T ' , $ path );
@@ -698,8 +719,7 @@ public function createPngFromStringDataProvider()
698719
699720 public function testValidateUploadFile ()
700721 {
701- $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
702- $ imageAdapter = $ objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ();
722+ $ imageAdapter = $ this ->objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ();
703723 $ this ->assertTrue ($ imageAdapter ->validateUploadFile ($ this ->_getFixture ('magento_thumbnail.jpg ' )));
704724 }
705725
@@ -713,8 +733,7 @@ public function testValidateUploadFileException($fileName, $expectedErrorMsg, $u
713733 {
714734 $ this ->expectException (\InvalidArgumentException::class);
715735
716- $ objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
717- $ imageAdapter = $ objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ();
736+ $ imageAdapter = $ this ->objectManager ->get (\Magento \Framework \Image \AdapterFactory::class)->create ();
718737 $ filePath = $ useFixture ? $ this ->_getFixture ($ fileName ) : $ fileName ;
719738
720739 try {
0 commit comments