persistentSessionHelperMock = $this->createMock(Session::class); $this->customerViewHelperMock = $this->createMock(View::class); $this->customerRepositoryMock = $this->getMockForAbstractClass(CustomerRepositoryInterface::class); $objectManager = new ObjectManagerHelper($this); $this->customerData = $objectManager->getObject( Persistent::class, [ 'persistentSession' => $this->persistentSessionHelperMock, 'customerViewHelper' => $this->customerViewHelperMock, 'customerRepository' => $this->customerRepositoryMock ] ); } /** * Test getSectionData() when disable persistent */ public function testGetSectionDataWhenDisablePersistent() { $this->persistentSessionHelperMock->method('isPersistent')->willReturn(false); $this->assertEquals([], $this->customerData->getSectionData()); } /** * Test getSectionData() when customer doesn't login */ public function testGetSectionDataWhenCustomerNotLoggedInReturnsEmptyArray() { $this->persistentSessionHelperMock->method('isPersistent')->willReturn(true); $persistentSessionMock = $this->getMockBuilder(PersistentSession::class) ->addMethods(['getCustomerId']) ->disableOriginalConstructor() ->getMock(); $persistentSessionMock->method('getCustomerId')->willReturn(null); $this->persistentSessionHelperMock->method('getSession')->willReturn($persistentSessionMock); $this->assertEquals([], $this->customerData->getSectionData()); } /** * Test getSectionData() when customer login and enable persistent */ public function testGetSectionDataCustomerLoginAndEnablePersistent() { $this->persistentSessionHelperMock->method('isPersistent')->willReturn(true); $persistentSessionMock = $this->getMockBuilder(PersistentSession::class) ->addMethods(['getCustomerId']) ->disableOriginalConstructor() ->getMock(); $persistentSessionMock->method('getCustomerId')->willReturn(self::STUB_CUSTOMER_ID); $this->persistentSessionHelperMock->method('getSession')->willReturn($persistentSessionMock); $customerMock = $this->getMockForAbstractClass(CustomerInterface::class); $this->customerRepositoryMock->method('getById')->with(self::STUB_CUSTOMER_ID)->willReturn($customerMock); $this->customerViewHelperMock->method('getCustomerName')->with($customerMock) ->willReturn(self::STUB_CUSTOMER_NAME); $this->assertEquals( [ 'fullname' => self::STUB_CUSTOMER_NAME ], $this->customerData->getSectionData() ); } }