diff --git a/app/code/Magento/Captcha/Cron/DeleteExpiredImages.php b/app/code/Magento/Captcha/Cron/DeleteExpiredImages.php index afacad9b249e3..e7fd3c3689e92 100644 --- a/app/code/Magento/Captcha/Cron/DeleteExpiredImages.php +++ b/app/code/Magento/Captcha/Cron/DeleteExpiredImages.php @@ -97,7 +97,7 @@ protected function _deleteExpiredImagesForWebsite( $imageDirectory = $this->_mediaDirectory->getRelativePath($helper->getImgDir($website)); foreach ($this->_mediaDirectory->read($imageDirectory) as $filePath) { if ($this->_mediaDirectory->isFile($filePath) - && $this->_fileInfo->getPathInfo($filePath, PATHINFO_EXTENSION) == 'png' + && $this->_fileInfo->getPathInfo($filePath)['extension'] == 'png' && $this->_mediaDirectory->stat($filePath)['mtime'] < $expire ) { $this->_mediaDirectory->delete($filePath); diff --git a/app/code/Magento/Captcha/Test/Unit/Cron/DeleteExpiredImagesTest.php b/app/code/Magento/Captcha/Test/Unit/Cron/DeleteExpiredImagesTest.php index 97fdb1b6380fa..5704c436e6b49 100644 --- a/app/code/Magento/Captcha/Test/Unit/Cron/DeleteExpiredImagesTest.php +++ b/app/code/Magento/Captcha/Test/Unit/Cron/DeleteExpiredImagesTest.php @@ -147,6 +147,18 @@ public function testDeleteExpiredImages($website, $isFile, $filename, $mTime, $t $this->_directory->expects($this->exactly($timesToCall))->method('isFile')->willReturn($isFile); $this->_directory->expects($this->any())->method('stat')->willReturn(['mtime' => $mTime]); + // Mock getPathInfo to return proper array structure for our fix + $extension = pathinfo($filename, PATHINFO_EXTENSION); + $this->_fileInfo->expects($this->any()) + ->method('getPathInfo') + ->with($filename) + ->willReturn([ + 'dirname' => '.', + 'basename' => $filename, + 'extension' => $extension, + 'filename' => pathinfo($filename, PATHINFO_FILENAME) + ]); + $this->_deleteExpiredImages->execute(); }