authSession = $this->createPartialMock( Session::class, ['isLoggedIn', '__call'] ); $this->configProvider = $this->createMock(ConfigProvider::class); $this->isLoggingAllowed = $objectManager->getObject( IsLoggingAllowed::class, [ 'authSession' => $this->authSession, 'configProvider' => $this->configProvider ] ); } public function testExecuteNotLogged() { $this->authSession->expects($this->once())->method('isLoggedIn')->willReturn(false); $this->assertFalse($this->isLoggingAllowed->execute()); } public function testExecuteWrongAdmin() { $this->authSession->expects($this->once())->method('isLoggedIn')->willReturn(true); $this->authSession->expects($this->any())->method('__call')->with(...['getUser'])->willReturn( $this->createConfiguredMock(User::class, ['getId' => 'test_admin2']) ); $this->configProvider->expects($this->any())->method('isEnabledLogAllAdmins')->willReturn(false); $this->configProvider->expects($this->any())->method('getAdminUsers')->willReturn(['test_admin1']); $this->assertFalse($this->isLoggingAllowed->execute()); } public function testExecuteRightAdmin() { $this->authSession->expects($this->once())->method('isLoggedIn')->willReturn(true); $this->authSession->expects($this->any())->method('__call')->with(...['getUser'])->willReturn( $this->createConfiguredMock(User::class, ['getId' => 'test_admin1']) ); $this->configProvider->expects($this->any())->method('isEnabledLogAllAdmins')->willReturn(false); $this->configProvider->expects($this->any())->method('getAdminUsers')->willReturn(['test_admin1']); $this->assertTrue($this->isLoggingAllowed->execute()); } }