public function testUnsubscribeCustomerById() { $customerId = 1; $customerDataMock = $this->getMockBuilder('\\Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock(); $this->customerRepository->expects($this->atLeastOnce())->method('getById')->with($customerId)->willReturn($customerDataMock); $this->resource->expects($this->atLeastOnce())->method('loadByCustomerData')->with($customerDataMock)->willReturn(['subscriber_id' => 1, 'subscriber_status' => 1]); $customerDataMock->expects($this->atLeastOnce())->method('getId')->willReturn('id'); $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf(); $customerDataMock->expects($this->once())->method('getStoreId')->willReturn('store_id'); $customerDataMock->expects($this->once())->method('getEmail')->willReturn('email'); $this->sendEmailCheck(); $this->subscriber->unsubscribeCustomerById($customerId); }