_apiConfigMock = $this->getMockBuilder( Config::class )->disableOriginalConstructor() ->getMock(); $this->_routeMock = $this->getMockBuilder( Route::class )->disableOriginalConstructor() ->setMethods( ['match'] )->getMock(); $areaListMock = $this->createMock(AreaList::class); $areaListMock->expects($this->once()) ->method('getFrontName') ->willReturn('rest'); $objectManager = new ObjectManager($this); $this->_request = $objectManager->getObject( Request::class, [ 'areaList' => $areaListMock, ] ); /** Initialize SUT. */ $this->_router = $objectManager->getObject( Router::class, [ 'apiConfig' => $this->_apiConfigMock ] ); } protected function tearDown(): void { unset($this->_routeMock); unset($this->_request); unset($this->_apiConfigMock); unset($this->_router); parent::tearDown(); } public function testMatch() { $this->_apiConfigMock->expects( $this->once() )->method( 'getRestRoutes' )->willReturn( [$this->_routeMock] ); $this->_routeMock->expects( $this->once() )->method( 'match' )->with( $this->_request )->willReturn( [] ); $matchedRoute = $this->_router->match($this->_request); $this->assertEquals($this->_routeMock, $matchedRoute); } public function testNotMatch() { $this->expectException('Magento\Framework\Webapi\Exception'); $this->_apiConfigMock->expects( $this->once() )->method( 'getRestRoutes' )->willReturn( [$this->_routeMock] ); $this->_routeMock->expects( $this->once() )->method( 'match' )->with( $this->_request )->willReturn( false ); $this->_router->match($this->_request); } }