Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
All Data Structures Namespaces Files Functions Variables Pages
RefreshCustomerDataTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class RefreshCustomerDataTest extends \PHPUnit\Framework\TestCase
11 {
15  private $observer;
16 
20  private $cookieManager;
21 
25  private $metadataFactory;
26 
30  private $metadata;
31 
35  private $sessionManager;
36 
37  public function setUp()
38  {
39  $this->cookieManager = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\PhpCookieManager::class)
40  ->disableOriginalConstructor()
41  ->getMock();
42  $this->metadataFactory = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory::class)
43  ->disableOriginalConstructor()
44  ->getMock();
45  $this->metadata = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadata::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48  $this->sessionManager = $this->getMockBuilder(\Magento\Framework\Session\SessionManager::class)
49  ->disableOriginalConstructor()
50  ->getMock();
51 
52  $this->observer = new RefreshCustomerData($this->cookieManager, $this->metadataFactory);
53  }
54 
61  public function testBeforeStart($result, $callCount)
62  {
63  $observerMock = $this->createMock(\Magento\Framework\Event\Observer::class);
64  $frontendSessionCookieName = 'mage-cache-sessid';
65  $this->cookieManager->expects($this->once())
66  ->method('getCookie')
67  ->with($frontendSessionCookieName)
68  ->willReturn($result);
69 
70  $this->metadataFactory->expects($this->{$callCount}())
71  ->method('createCookieMetadata')
72  ->willReturn($this->metadata);
73  $this->metadata->expects($this->{$callCount}())
74  ->method('setPath')
75  ->with('/');
76  $this->cookieManager->expects($this->{$callCount}())
77  ->method('deleteCookie')
78  ->with('mage-cache-sessid', $this->metadata);
79 
80  $this->observer->execute($observerMock);
81  }
82 
86  public function beforeStartDataProvider()
87  {
88  return [
89  [true, 'once'],
90  [false, 'never']
91  ];
92  }
93 }