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 1 commit
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
11 changes: 4 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,10 @@ 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'])
->disableArgumentCloning()
->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,14 @@ 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()
->disableOriginalClone()
->disableArgumentCloning()
AntonEvers marked this conversation as resolved.
Show resolved Hide resolved
->disallowMockingUnknownTypes()
->onlyMethods(['removeItem', 'getQuote'])
->addMethods(['setTotalQty', 'getTotalQty'])
->getMock();

/** @var Product|MockObject $product */
$product = $this->createMock(Product::class);
Expand Down Expand Up @@ -161,10 +165,13 @@ 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()
->disableOriginalClone()
->disableArgumentCloning()
->disallowMockingUnknownTypes()
AntonEvers marked this conversation as resolved.
Show resolved Hide resolved
->addMethods(['setVirtualAmount', 'setBaseVirtualAmount'])
->getMock();
$total->expects($this->once())->method('setBaseVirtualAmount')->willReturnSelf();
$total->expects($this->once())->method('setVirtualAmount')->willReturnSelf();

Expand All @@ -185,7 +192,10 @@ public function testFetch()
];

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

$this->assertEquals($expectedResult, $this->subtotalModel->fetch($quoteMock, $totalMock));
Expand Down Expand Up @@ -229,13 +239,14 @@ public function testCollectWithInvalidItems()
$address->expects($this->once())
->method('removeItem')
->with($addressItemId);
$addressItem = $this->createPartialMock(
AddressItem::class,
[
'getId',
'getQuoteItemId'
]
);
$addressItem = $this->getMockBuilder(AddressItem::class)
->disableOriginalConstructor()
->disableOriginalClone()
->disableArgumentCloning()
->disallowMockingUnknownTypes()
AntonEvers marked this conversation as resolved.
Show resolved Hide resolved
->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,14 @@ 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()
->disableOriginalClone()
->disableArgumentCloning()
->disallowMockingUnknownTypes()
AntonEvers marked this conversation as resolved.
Show resolved Hide resolved
->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,14 +65,13 @@ function ($code) use ($adjustmentsData) {
return $adjustmentsData[$code];
}
);

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

/**
* @param string[] $adjustments
* @param string[] $expectedResult
*
* @dataProvider getItemsDataProvider
*/
public function testGetItems($adjustments, $expectedResult)
Expand All @@ -92,14 +92,15 @@ public function getItemsDataProvider()
[['adj1'], ['adj1']],
[['adj4'], ['adj4']],
[['adj1', 'adj4'], ['adj1', 'adj4']],
[['adj1', 'adj2', 'adj3', 'adj4'], ['adj3', 'adj1', 'adj2', 'adj4']]
[['adj1', 'adj2', 'adj3', 'adj4'], ['adj3', 'adj1', 'adj2', 'adj4']],
AntonEvers marked this conversation as resolved.
Show resolved Hide resolved
];
}

/**
* @param string[] $adjustments
* @param string $code
* @param $expectedResult
*
* @dataProvider getItemByCodeDataProvider
*/
public function testGetItemByCode($adjustments, $code, $expectedResult)
Expand All @@ -108,7 +109,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 +118,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