disableSessionConfigMock = $this->createMock(DisableSession::class); $this->appStateMock = $this->createMock(State::class); $this->sessionStartCheckerMock = $this->createMock(SessionStartChecker::class); $this->model = (new ObjectManager($this))->getObject( DisableSessionPlugin::class, [ 'disableSessionConfig' => $this->disableSessionConfigMock, 'appState' => $this->appStateMock ] ); } /** * Test afterCheck plugin result over original method result. * * @param string $area * @param bool $config * @param bool $methodResult * @param bool $expectedResult * @return void * @dataProvider testAfterCheckDataProvider */ public function testAfterCheck(string $area, bool $config, bool $methodResult, bool $expectedResult) { $this->disableSessionConfigMock->expects($this->any())->method('isDisabled')->willReturn($config); $this->appStateMock->expects($this->any())->method('getAreaCode')->willReturn($area); $this->assertEquals($expectedResult, $this->model->afterCheck($this->sessionStartCheckerMock, $methodResult)); } /** * Data provider for testAfterCheck. * * @return array[] */ public function testAfterCheckDataProvider() { return [ ['area' => 'graphql', 'config' => true, 'methodResult' => false, 'expected' => false], ['area' => 'graphql', 'config' => true, 'methodResult' => true, 'expected' => false], ['area' => 'graphql', 'config' => false, 'methodResult' => true, 'expected' => true], ['area' => 'graphql', 'config' => false, 'methodResult' => false, 'expected' => false], ['area' => 'other', 'config' => false, 'methodResult' => false, 'expected' => false], ['area' => 'other', 'config' => true, 'methodResult' => false, 'expected' => false], ['area' => 'other', 'config' => true, 'methodResult' => true, 'expected' => true], ['area' => 'other', 'config' => false, 'methodResult' => true, 'expected' => true], ]; } /** * Test afterCheck plugin result over original method result when no area code set. * * @param bool $config * @param bool $methodResult * @param bool $expectedResult * @return void * @dataProvider testAfterCheckDataProviderNoAreaCode */ public function testAfterCheckNoArea(bool $config, bool $methodResult, bool $expectedResult) { $this->disableSessionConfigMock->expects($this->any())->method('isDisabled')->willReturn($config); $this->appStateMock->expects($this->any()) ->method('getAreaCode') ->willThrowException(new LocalizedException(__('Are code not set'))); $this->assertEquals($expectedResult, $this->model->afterCheck($this->sessionStartCheckerMock, $methodResult)); } /** * Data provider for testAfterCheck. * * @return array[] */ public function testAfterCheckDataProviderNoAreaCode() { return [ ['config' => true, 'methodResult' => true, 'expected' => true], ['config' => true, 'methodResult' => false, 'expected' => false], ['config' => false, 'methodResult' => true, 'expected' => true], ['config' => false, 'methodResult' => false, 'expected' => false], ]; } }