Skip to content

Commit ea35a09

Browse files
author
Alexander Akimov
authored
Merge pull request #1539 from magento-plankton/MAGETWO-75452-develop
[Plankton] Bugs
2 parents 205a408 + b327246 commit ea35a09

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

lib/internal/Magento/Framework/Model/ResourceModel/AbstractResource.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ abstract class AbstractResource
2323
*/
2424
protected $serializer;
2525

26+
/**
27+
* @var \Psr\Log\LoggerInterface
28+
*/
29+
protected $_logger;
30+
2631
/**
2732
* Constructor
2833
*/
@@ -92,7 +97,7 @@ public function commit()
9297
call_user_func($callback);
9398
}
9499
} catch (\Exception $e) {
95-
$this->logger->critical($e);
100+
$this->getLogger()->critical($e);
96101
}
97102
}
98103
return $this;
@@ -252,4 +257,18 @@ protected function getSerializer()
252257
}
253258
return $this->serializer;
254259
}
260+
261+
/**
262+
* Get logger
263+
*
264+
* @return \Psr\Log\LoggerInterface
265+
* @deprecated
266+
*/
267+
private function getLogger()
268+
{
269+
if (null === $this->_logger) {
270+
$this->_logger = ObjectManager::getInstance()->get(\Psr\Log\LoggerInterface::class);
271+
}
272+
return $this->_logger;
273+
}
255274
}

lib/internal/Magento/Framework/Model/Test/Unit/ResourceModel/AbstractResourceTest.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@ class AbstractResourceTest extends \PHPUnit\Framework\TestCase
2222
*/
2323
private $serializerMock;
2424

25+
/**
26+
* @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $loggerMock;
29+
2530
protected function setUp()
2631
{
2732
$objectManager = new ObjectManager($this);
2833
$this->serializerMock = $this->createMock(Json::class);
34+
$this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
2935
$this->abstractResource = $objectManager->getObject(AbstractResourceStub::class);
30-
$objectManager->setBackwardCompatibleProperty(
31-
$this->abstractResource,
32-
'serializer',
33-
$this->serializerMock
34-
);
36+
$objectManager->setBackwardCompatibleProperty($this->abstractResource, 'serializer', $this->serializerMock);
37+
$objectManager->setBackwardCompatibleProperty($this->abstractResource, '_logger', $this->loggerMock);
3538
}
3639

3740
/**
@@ -201,9 +204,6 @@ function () use ($closureExpectation) {
201204
$this->abstractResource->commit();
202205
}
203206

204-
/**
205-
* @expectedException \Exception
206-
*/
207207
public function testCommitZeroLevelCallbackException()
208208
{
209209
/** @var AdapterInterface|\PHPUnit_Framework_MockObject_MockObject $connection */
@@ -221,6 +221,8 @@ function () {
221221
$connection->expects($this->once())
222222
->method('getTransactionLevel')
223223
->willReturn(0);
224+
$this->loggerMock->expects($this->once())
225+
->method('critical');
224226

225227
$this->abstractResource->commit();
226228
}

0 commit comments

Comments
 (0)