Skip to content

Commit

Permalink
Refactor Unit Tests too (remove "expects any()")
Browse files Browse the repository at this point in the history
  • Loading branch information
lbajsarowicz committed Aug 18, 2020
1 parent 6b01af9 commit bc5e644
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/code/Magento/Quote/Test/Unit/Model/ChangeQuoteControlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ protected function setUp(): void
public function testIsAllowedIfTheQuoteIsBelongedToCustomer()
{
$quoteCustomerId = 1;
$this->quoteMock->expects($this->any())->method('getCustomerId')
$this->quoteMock->method('getCustomerId')
->willReturn($quoteCustomerId);
$this->userContextMock->expects($this->any())->method('getUserType')
$this->userContextMock->method('getUserType')
->willReturn(UserContextInterface::USER_TYPE_CUSTOMER);
$this->userContextMock->expects($this->any())->method('getUserId')
$this->userContextMock->method('getUserId')
->willReturn($quoteCustomerId);

$this->assertTrue($this->model->isAllowed($this->quoteMock));
Expand All @@ -64,11 +64,11 @@ public function testIsAllowedIfTheQuoteIsNotBelongedToCustomer()
$currentCustomerId = 1;
$quoteCustomerId = 2;

$this->quoteMock->expects($this->any())->method('getCustomerId')
$this->quoteMock->method('getCustomerId')
->willReturn($quoteCustomerId);
$this->userContextMock->expects($this->any())->method('getUserType')
$this->userContextMock->method('getUserType')
->willReturn(UserContextInterface::USER_TYPE_CUSTOMER);
$this->userContextMock->expects($this->any())->method('getUserId')
$this->userContextMock->method('getUserId')
->willReturn($currentCustomerId);

$this->assertFalse($this->model->isAllowed($this->quoteMock));
Expand All @@ -77,33 +77,33 @@ public function testIsAllowedIfTheQuoteIsNotBelongedToCustomer()
public function testIsAllowedIfQuoteIsBelongedToGuestAndContextIsGuest()
{
$quoteCustomerId = null;
$this->quoteMock->expects($this->any())->method('getCustomerId')
$this->quoteMock->method('getCustomerId')
->willReturn($quoteCustomerId);
$this->userContextMock->expects($this->any())->method('getUserType')
$this->userContextMock->method('getUserType')
->willReturn(UserContextInterface::USER_TYPE_GUEST);
$this->assertTrue($this->model->isAllowed($this->quoteMock));
}

public function testIsAllowedIfQuoteIsBelongedToCustomerAndContextIsGuest()
{
$quoteCustomerId = 1;
$this->quoteMock->expects($this->any())->method('getCustomerId')
$this->quoteMock->method('getCustomerId')
->willReturn($quoteCustomerId);
$this->userContextMock->expects($this->any())->method('getUserType')
$this->userContextMock->method('getUserType')
->willReturn(UserContextInterface::USER_TYPE_GUEST);
$this->assertFalse($this->model->isAllowed($this->quoteMock));
}

public function testIsAllowedIfContextIsAdmin()
{
$this->userContextMock->expects($this->any())->method('getUserType')
$this->userContextMock->method('getUserType')
->willReturn(UserContextInterface::USER_TYPE_ADMIN);
$this->assertTrue($this->model->isAllowed($this->quoteMock));
}

public function testIsAllowedIfContextIsIntegration()
{
$this->userContextMock->expects($this->any())->method('getUserType')
$this->userContextMock->method('getUserType')
->willReturn(UserContextInterface::USER_TYPE_INTEGRATION);
$this->assertTrue($this->model->isAllowed($this->quoteMock));
}
Expand Down

0 comments on commit bc5e644

Please sign in to comment.