Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ObserverFactoryTest.php
Go to the documentation of this file.
1 <?php
8 
9 use \Magento\Framework\Event\ObserverFactory;
10 
16 class ObserverFactoryTest extends \PHPUnit\Framework\TestCase
17 {
21  protected $objectManagerMock;
22 
26  protected $observerFactory;
27 
28  protected function setUp()
29  {
30  $this->objectManagerMock = $this->createPartialMock(
31  \Magento\Framework\ObjectManager\ObjectManager::class,
32  ['get', 'create']
33  );
34  $this->observerFactory = new ObserverFactory($this->objectManagerMock);
35  }
36 
37  public function testGet()
38  {
39  $className = 'Magento\Class';
40  $observerMock = $this->getMockBuilder('Observer')->getMock();
41  $this->objectManagerMock->expects($this->once())
42  ->method('get')
43  ->with($className)
44  ->will($this->returnValue($observerMock));
45 
46  $result = $this->observerFactory->get($className);
47  $this->assertEquals($observerMock, $result);
48  }
49 
50  public function testCreate()
51  {
52  $className = 'Magento\Class';
53  $observerMock = $this->getMockBuilder('Observer')->getMock();
54  $arguments = ['arg1', 'arg2'];
55 
56  $this->objectManagerMock->expects($this->once())
57  ->method('create')
58  ->with($className, $this->equalTo($arguments))
59  ->will($this->returnValue($observerMock));
60 
61  $result = $this->observerFactory->create($className, $arguments);
62  $this->assertEquals($observerMock, $result);
63  }
64 }
$arguments
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31