Skip to content

Commit

Permalink
Merge pull request #34 from magento-extensibility/MAGETWO-31968-Logge…
Browse files Browse the repository at this point in the history
…r-Fatal-Error

[Extensibility] Magetwo 31968 logger fatal error
  • Loading branch information
vpelipenko committed Jan 16, 2015
2 parents 415a139 + 9cedc5a commit 5dde4a3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class AbstractTest extends \PHPUnit_Framework_TestCase
*/
protected $filesystemMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject |\Psr\Log\LoggerInterface
*/
protected $loggerMock;

protected function setUp()
{
$this->directoryWriteMock = $this->getMock(
Expand All @@ -49,10 +54,11 @@ protected function setUp()
)->will(
$this->returnValue($this->directoryWriteMock)
);
$this->loggerMock = $this->getMockBuilder( 'Psr\Log\LoggerInterface')->getMock();

$this->_model = $this->getMockForAbstractClass(
'Magento\Framework\Image\Adapter\AbstractAdapter',
[$this->filesystemMock]
[$this->filesystemMock, $this->loggerMock]
);
}

Expand All @@ -61,6 +67,7 @@ protected function tearDown()
$this->directoryWriteMock = null;
$this->_model = null;
$this->filesystemMock = null;
$this->loggerMock = null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,63 @@
*/
namespace Magento\Framework\Image\Adapter;

use Magento\Framework\Filesystem\FilesystemException;
use Magento\TestFramework\Helper\ObjectManager;

class ImageMagickTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject |\Magento\Framework\Filesystem
*/
protected $filesystemMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject |\Psr\Log\LoggerInterface
*/
protected $loggerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject | \Magento\Framework\Filesystem\Directory\WriteInterface
*/
protected $writeMock;
/**
* @var \Magento\Framework\Image\Adapter\ImageMagick
*/
protected $imageMagic;

public function setup()
{
$objectManager = new ObjectManager($this);
$this->loggerMock = $this->getMockBuilder( 'Psr\Log\LoggerInterface')->getMock();
$this->writeMock = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\WriteInterface')->getMock();
$this->filesystemMock = $this->getMock(
'Magento\Framework\Filesystem',
['getDirectoryWrite'],
[],
'',
false
);
$this->filesystemMock
->expects($this->once())
->method('getDirectoryWrite')
->will($this->returnValue( $this->writeMock));

$this->imageMagic = $objectManager
->getObject(
'Magento\Framework\Image\Adapter\ImageMagick',
['filesystem' => $this->filesystemMock,
'logger' => $this->loggerMock]
);
}
/**
* @param string $imagePath
* @param string $expectedMessage
* @dataProvider watermarkDataProvider
*/
public function testWatermark($imagePath, $expectedMessage)
{
$filesystem =
$this->getMockBuilder('Magento\Framework\Filesystem')->disableOriginalConstructor()->getMock();
$this->setExpectedException('LogicException', $expectedMessage);
$object = new \Magento\Framework\Image\Adapter\ImageMagick($filesystem);
$object->watermark($imagePath);
$this->imageMagic->watermark($imagePath);
}

/**
Expand All @@ -33,4 +78,16 @@ public function watermarkDataProvider()
]
];
}

/**
* @expectedException \Exception
* @expectedExceptionMessage Unable to write file into directory product/cache. Access forbidden.
*/
public function testSaveWithException()
{
$exception = new FilesystemException();
$this->writeMock->method('create')->will($this->throwException($exception));
$this->loggerMock->expects($this->once())->method('critical')->with($exception);
$this->imageMagic->save('product/cache', 'sample.jpg');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,16 @@ abstract public function getColorAt($x, $y);
* Initialize default values
*
* @param \Magento\Framework\Filesystem $filesystem
* @param \Psr\Log\LoggerInterface $logger
* @param array $data
*/
public function __construct(\Magento\Framework\Filesystem $filesystem, array $data = [])
{
public function __construct(
\Magento\Framework\Filesystem $filesystem,
\Psr\Log\LoggerInterface $logger,
array $data = []
) {
$this->_filesystem = $filesystem;
$this->logger = $logger;
$this->directoryWrite = $this->_filesystem->getDirectoryWrite(DirectoryList::ROOT);
}

Expand Down

0 comments on commit 5dde4a3

Please sign in to comment.