Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
NoRouteObserverTest.php
Go to the documentation of this file.
1 <?php
7 
8 class NoRouteObserverTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $noRouteObserver;
14 
18  protected $observerMock;
19 
23  protected $eventMock;
24 
28  protected $objectMock;
29 
30  protected function setUp()
31  {
32  $this->observerMock = $this
33  ->getMockBuilder(\Magento\Framework\Event\Observer::class)
34  ->disableOriginalConstructor()
35  ->getMock();
36  $this->eventMock = $this
37  ->getMockBuilder(\Magento\Framework\Event::class)
38  ->setMethods(
39  [
40  'getStatus',
41  'getRedirect',
42  ]
43  )
44  ->disableOriginalConstructor()
45  ->getMock();
46  $this->objectMock = $this
47  ->getMockBuilder(\Magento\Framework\DataObject::class)
48  ->setMethods(
49  [
50  'setLoaded',
51  'setForwardModule',
52  'setForwardController',
53  'setForwardAction',
54  'setRedirectUrl',
55  'setRedirect',
56  'setPath',
57  'setArguments',
58  ]
59  )
60  ->disableOriginalConstructor()
61  ->getMock();
62 
63  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
64  $this->noRouteObserver = $objectManager->getObject(
65  \Magento\Cms\Observer\NoRouteObserver::class,
66  []
67  );
68  }
69 
73  public function testNoRoute()
74  {
75  $this->observerMock
76  ->expects($this->atLeastOnce())
77  ->method('getEvent')
78  ->willReturn($this->eventMock);
79  $this->eventMock
80  ->expects($this->atLeastOnce())
81  ->method('getStatus')
82  ->willReturn($this->objectMock);
83  $this->objectMock
84  ->expects($this->atLeastOnce())
85  ->method('setLoaded')
86  ->with(true)
87  ->willReturnSelf();
88  $this->objectMock
89  ->expects($this->atLeastOnce())
90  ->method('setForwardModule')
91  ->with('cms')
92  ->willReturnSelf();
93  $this->objectMock
94  ->expects($this->atLeastOnce())
95  ->method('setForwardController')
96  ->with('index')
97  ->willReturnSelf();
98  $this->objectMock
99  ->expects($this->atLeastOnce())
100  ->method('setForwardAction')
101  ->with('noroute')
102  ->willReturnSelf();
103 
104  $this->assertEquals($this->noRouteObserver, $this->noRouteObserver->execute($this->observerMock));
105  }
106 }
$objectManager
Definition: bootstrap.php:17