AdminLogoutObserverTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Observer;
  6. use Magento\TestFramework\ObjectManager;
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. use Temando\Shipping\Rest\Authentication;
  9. /**
  10. * AdminLogoutObserverTest
  11. *
  12. * @package Temando\Shipping\Test\Integration
  13. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  14. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  15. * @link http://www.temando.com/
  16. */
  17. class AdminLogoutObserverTest extends \PHPUnit\Framework\TestCase
  18. {
  19. /**
  20. * @var ObjectManager
  21. */
  22. private $objectManager;
  23. /**
  24. * @var \Magento\Framework\Event\Invoker\InvokerDefault
  25. */
  26. private $invoker;
  27. /**
  28. * @var \Magento\Framework\Event\Observer
  29. */
  30. private $observer;
  31. /**
  32. * @var Authentication|\PHPUnit_Framework_MockObject_MockObject
  33. */
  34. private $auth;
  35. /**
  36. * Init object manager
  37. */
  38. protected function setUp()
  39. {
  40. parent::setUp();
  41. $this->objectManager = Bootstrap::getObjectManager();
  42. $this->invoker = $this->objectManager->get(\Magento\Framework\Event\InvokerInterface::class);
  43. $this->observer = $this->objectManager->get(\Magento\Framework\Event\Observer::class);
  44. $this->auth = $this->getMockBuilder(Authentication::class)
  45. ->setMethods(['disconnect'])
  46. ->disableOriginalConstructor()
  47. ->getMock();
  48. $this->objectManager->addSharedInstance($this->auth, Authentication::class);
  49. }
  50. protected function tearDown()
  51. {
  52. $this->objectManager->removeSharedInstance(AdminLogoutObserver::class);
  53. $this->objectManager->removeSharedInstance(Authentication::class);
  54. parent::tearDown();
  55. }
  56. /**
  57. * @test
  58. */
  59. public function invalidateSessionToken()
  60. {
  61. $this->auth
  62. ->expects($this->once())
  63. ->method('disconnect');
  64. $config = [
  65. 'instance' => AdminLogoutObserver::class,
  66. 'name' => 'temando_admin_logout',
  67. ];
  68. $this->invoker->dispatch($config, $this->observer);
  69. }
  70. }