Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit tests with PHPUnit 9 errors #29244

Merged
merged 2 commits into from
Aug 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AjaxLoginTest extends TestCase
/**
* @var array
*/
protected $formIds;
protected $formIds = ['user_login'];

/**
* @var AjaxLogin
Expand Down Expand Up @@ -97,7 +97,6 @@ protected function setUp(): void
->method('getCaptcha')
->willReturn($this->captchaMock);

$this->formIds = ['user_login'];
$this->serializerMock = $this->createMock(Json::class);

$this->model = new AjaxLogin(
Expand Down Expand Up @@ -194,7 +193,10 @@ public function testAroundExecuteCaptchaIsNotRequired($username, $requestContent

$this->captchaMock->expects($this->once())->method('isRequired')->with($username)
->willReturn(false);
$this->captchaMock->expects($this->never())->method('logAttempt')->with($username);
$expectLogAttempt = $requestContent['captcha_form_id'] ?? false;
$this->captchaMock
->expects($expectLogAttempt ? $this->once() : $this->never())
->method('logAttempt')->with($username);
$this->captchaMock->expects($this->never())->method('isCorrect');

$closure = function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function testExecuteVsCodeFormat()
->with(
$this->equalTo(['urn:magento:framework:Module/etc/module.xsd' => $fixtureXmlFile]),
$this->equalTo('test')
)->willReturn(null);
);

$formats = ['vscode' => $vscodeFormatMock];
$readFactory = $this->createMock(ReadFactory::class);
Expand Down
10 changes: 3 additions & 7 deletions app/code/Magento/Persistent/Test/Unit/Model/QuoteManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,9 @@ public function testSetGuest()
->method('removePersistentCookie')->willReturn($this->sessionMock);
$this->quoteMock->expects($this->once())->method('isVirtual')->willReturn(false);
$this->quoteMock->expects($this->once())->method('getItemsQty')->willReturn(1);
$extensionAttributes = $this->createPartialMock(
CartExtensionInterface::class,
[
'setShippingAssignments',
'getShippingAssignments'
]
);
$extensionAttributes = $this->getMockBuilder(CartExtensionInterface::class)
->addMethods(['getShippingAssignments', 'setShippingAssignments'])
->getMockForAbstractClass();
$shippingAssignment = $this->createMock(ShippingAssignmentInterface::class);
$extensionAttributes->expects($this->once())
->method('setShippingAssignments')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function setUp(): void

$this->stockRegistry = $this->createPartialMock(
StockRegistry::class,
['getStockItem', '__wakeup']
['getStockItem']
);
$this->stockItemMock = $this->createPartialMock(
\Magento\CatalogInventory\Model\Stock\Item::class,
Expand Down Expand Up @@ -110,10 +110,11 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri
]
);
/** @var Address|MockObject $address */
$address = $this->createPartialMock(
Address::class,
['setTotalQty', 'getTotalQty', 'removeItem', 'getQuote']
);
$address = $this->getMockBuilder(Address::class)
->disableOriginalConstructor()
->onlyMethods(['removeItem', 'getQuote'])
->addMethods(['setTotalQty', 'getTotalQty'])
->getMock();

/** @var Product|MockObject $product */
$product = $this->createMock(Product::class);
Expand Down Expand Up @@ -161,10 +162,10 @@ public function testCollect($price, $originalPrice, $itemHasParent, $expectedPri
$shippingAssignmentMock->expects($this->exactly(2))->method('getShipping')->willReturn($shipping);
$shippingAssignmentMock->expects($this->once())->method('getItems')->willReturn([$quoteItem]);

$total = $this->createPartialMock(
Total::class,
['setBaseVirtualAmount', 'setVirtualAmount']
);
$total = $this->getMockBuilder(Total::class)
->disableOriginalConstructor()
->addMethods(['setVirtualAmount', 'setBaseVirtualAmount'])
->getMock();
$total->expects($this->once())->method('setBaseVirtualAmount')->willReturnSelf();
$total->expects($this->once())->method('setVirtualAmount')->willReturnSelf();

Expand All @@ -185,7 +186,9 @@ public function testFetch()
];

$quoteMock = $this->createMock(Quote::class);
$totalMock = $this->createPartialMock(Total::class, ['getSubtotal']);
$totalMock = $this->getMockBuilder(Total::class)
->addMethods(['getSubtotal'])
->getMockForAbstractClass();
$totalMock->expects($this->once())->method('getSubtotal')->willReturn(100);

$this->assertEquals($expectedResult, $this->subtotalModel->fetch($quoteMock, $totalMock));
Expand Down Expand Up @@ -229,13 +232,11 @@ public function testCollectWithInvalidItems()
$address->expects($this->once())
->method('removeItem')
->with($addressItemId);
$addressItem = $this->createPartialMock(
AddressItem::class,
[
'getId',
'getQuoteItemId'
]
);
$addressItem = $this->getMockBuilder(AddressItem::class)
->disableOriginalConstructor()
->onlyMethods(['getId'])
->addMethods(['getQuoteItemId'])
->getMock();
$addressItem->setAddress($address);
$addressItem->method('getId')
->willReturn($addressItemId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ class CreditmemoFactoryTest extends TestCase
*/
protected function setUp(): void
{
$this->orderItemMock = $this->createPartialMock(
Item::class,
['getChildrenItems', 'isDummy', 'getHasChildren', 'getId', 'getParentItemId']
);
$this->orderItemMock = $this->getMockBuilder(Item::class)
->disableOriginalConstructor()
->onlyMethods(['getChildrenItems', 'isDummy', 'getId', 'getParentItemId'])
->addMethods(['getHasChildren'])
->getMock();
$this->orderChildItemOneMock = $this->createPartialMock(
Item::class,
['getQtyToRefund', 'getId']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected function setUp(): void
'adj3' => $adj3,
'adj4' => $adj4,
];
$this->adjustmentsData = $adjustmentsData;

/** @var Pool|MockObject $adjustmentPool */
$adjustmentPool = $this->getMockBuilder(Pool::class)
Expand All @@ -64,9 +65,7 @@ function ($code) use ($adjustmentsData) {
return $adjustmentsData[$code];
}
);

$this->adjustmentPool = $adjustmentPool;
$this->adjustmentsData = $adjustmentsData;
}

/**
Expand Down Expand Up @@ -108,7 +107,7 @@ public function testGetItemByCode($adjustments, $code, $expectedResult)

$item = $collection->getItemByCode($code);

$this->assertEquals($expectedResult, $item->getAdjustmentCode());
$this->assertEquals($expectedResult, $item->getSortOrder());
}

/**
Expand All @@ -117,11 +116,11 @@ public function testGetItemByCode($adjustments, $code, $expectedResult)
public function getItemByCodeDataProvider()
{
return [
[['adj1'], 'adj1', $this->adjustmentsData['adj1']],
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj1', $this->adjustmentsData['adj1']],
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj2', $this->adjustmentsData['adj2']],
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj3', $this->adjustmentsData['adj3']],
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj4', $this->adjustmentsData['adj4']],
[['adj1'], 'adj1', 10],
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj1', 10],
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj2', 20],
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj3', 5],
[['adj1', 'adj2', 'adj3', 'adj4'], 'adj4', Pool::DEFAULT_SORT_ORDER],
];
}

Expand Down