Skip to content

Commit c3e4f07

Browse files
committed
fix-issue-21755
1 parent f3d7a0d commit c3e4f07

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

lib/internal/Magento/Framework/Event/Invoker/InvokerDefault.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@
99
namespace Magento\Framework\Event\Invoker;
1010

1111
use Magento\Framework\Event\Observer;
12+
use Psr\Log\LoggerInterface;
13+
use Magento\Framework\App\State;
1214

15+
/**
16+
* Default Invoker.
17+
*/
1318
class InvokerDefault implements \Magento\Framework\Event\InvokerInterface
1419
{
1520
/**
@@ -22,20 +27,29 @@ class InvokerDefault implements \Magento\Framework\Event\InvokerInterface
2227
/**
2328
* Application state
2429
*
25-
* @var \Magento\Framework\App\State
30+
* @var State
2631
*/
2732
protected $_appState;
2833

34+
/**
35+
* @var LoggerInterface
36+
*/
37+
private $logger;
38+
2939
/**
3040
* @param \Magento\Framework\Event\ObserverFactory $observerFactory
31-
* @param \Magento\Framework\App\State $appState
41+
* @param State $appState
42+
* @param LoggerInterface $logger
3243
*/
3344
public function __construct(
3445
\Magento\Framework\Event\ObserverFactory $observerFactory,
35-
\Magento\Framework\App\State $appState
46+
State $appState,
47+
LoggerInterface $logger = null
3648
) {
3749
$this->_observerFactory = $observerFactory;
3850
$this->_appState = $appState;
51+
$this->logger = $logger ?: \Magento\Framework\App\ObjectManager::getInstance()
52+
->get(LoggerInterface::class);
3953
}
4054

4155
/**
@@ -61,6 +75,8 @@ public function dispatch(array $configuration, Observer $observer)
6175
}
6276

6377
/**
78+
* Execute Observer.
79+
*
6480
* @param \Magento\Framework\Event\ObserverInterface $object
6581
* @param Observer $observer
6682
* @return $this
@@ -70,14 +86,20 @@ protected function _callObserverMethod($object, $observer)
7086
{
7187
if ($object instanceof \Magento\Framework\Event\ObserverInterface) {
7288
$object->execute($observer);
73-
} elseif ($this->_appState->getMode() == \Magento\Framework\App\State::MODE_DEVELOPER) {
89+
} elseif ($this->_appState->getMode() == State::MODE_DEVELOPER) {
7490
throw new \LogicException(
7591
sprintf(
7692
'Observer "%s" must implement interface "%s"',
7793
get_class($object),
7894
\Magento\Framework\Event\ObserverInterface::class
7995
)
8096
);
97+
} else {
98+
$this->logger->warning(sprintf(
99+
'Observer "%s" must implement interface "%s"',
100+
get_class($object),
101+
\Magento\Framework\Event\ObserverInterface::class
102+
));
81103
}
82104
return $this;
83105
}

lib/internal/Magento/Framework/Event/Test/Unit/Invoker/InvokerDefaultTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class InvokerDefaultTest extends \PHPUnit\Framework\TestCase
3232
*/
3333
protected $_invokerDefault;
3434

35+
/**
36+
* @var |Psr\Log|LoggerInterface
37+
*/
38+
private $loggerMock;
39+
3540
protected function setUp()
3641
{
3742
$this->_observerFactoryMock = $this->createMock(\Magento\Framework\Event\ObserverFactory::class);
@@ -41,10 +46,12 @@ protected function setUp()
4146
['execute']
4247
);
4348
$this->_appStateMock = $this->createMock(\Magento\Framework\App\State::class);
49+
$this->loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
4450

4551
$this->_invokerDefault = new \Magento\Framework\Event\Invoker\InvokerDefault(
4652
$this->_observerFactoryMock,
47-
$this->_appStateMock
53+
$this->_appStateMock,
54+
$this->loggerMock
4855
);
4956
}
5057

@@ -166,13 +173,15 @@ public function testWrongInterfaceCallWithDisabledDeveloperMode($shared)
166173
$this->returnValue($notObserver)
167174
);
168175
$this->_appStateMock->expects(
169-
$this->once()
176+
$this->exactly(2)
170177
)->method(
171178
'getMode'
172179
)->will(
173180
$this->returnValue(\Magento\Framework\App\State::MODE_PRODUCTION)
174181
);
175182

183+
$this->loggerMock->expects($this->once())->method('warning');
184+
176185
$this->_invokerDefault->dispatch(
177186
[
178187
'shared' => $shared,

0 commit comments

Comments
 (0)