Skip to content

Commit b251b25

Browse files
author
Igor Melnikov
committed
MAGETWO-69137: upgrading Magento2 Project PHPUnit version to latest
- refactor tests
1 parent 142340d commit b251b25

File tree

44 files changed

+890
-299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+890
-299
lines changed

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/Column/Renderer/ConcatTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class ConcatTest extends \PHPUnit\Framework\TestCase
1717

1818
protected function setUp()
1919
{
20-
// $this->markTestSkipped('Test needs to be refactored.');
2120
$this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
2221
$this->renderer = $this->objectManagerHelper->getObject(
2322
\Magento\Backend\Block\Widget\Grid\Column\Renderer\Concat::class

app/code/Magento/Bundle/Test/Unit/Model/LinkManagementTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,6 @@ public function testAddChildLinkedProductIsComposite()
392392
*/
393393
public function testAddChildProductAlreadyExistsInOption()
394394
{
395-
$this->markTestSkipped('Test needs to be refactored.');
396395
$productLink = $this->getMockBuilder(\Magento\Bundle\Api\Data\LinkInterface::class)
397396
->setMethods(['getSku', 'getOptionId', 'getSelectionId'])
398397
->disableOriginalConstructor()
@@ -402,11 +401,14 @@ public function testAddChildProductAlreadyExistsInOption()
402401
$productLink->expects($this->any())->method('getSelectionId')->will($this->returnValue(1));
403402

404403
$this->metadataMock->expects($this->once())->method('getLinkField')->willReturn($this->linkField);
405-
$productMock = $this->createPartialMock(\Magento\Catalog\Model\Product::class,
406-
['getTypeId', 'getCopyFromView', 'getData']);
407-
$productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(
404+
$productMock = $this->createPartialMock(
405+
\Magento\Catalog\Model\Product::class,
406+
['getTypeId', 'getCopyFromView', 'getData', 'getTypeInstance', 'getSku']
407+
);
408+
$productMock->expects($this->once())->method('getTypeId')->willReturn(
408409
\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE
409-
));
410+
);
411+
410412
$productMock->expects($this->any())
411413
->method('getData')
412414
->with($this->linkField)

app/code/Magento/Bundle/Test/Unit/Model/Product/OptionListTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,9 @@ protected function setUp()
5555
);
5656
$this->dataObjectHelperMock = $this->createMock(\Magento\Framework\Api\DataObjectHelper::class);
5757
$this->linkListMock = $this->createMock(\Magento\Bundle\Model\Product\LinksList::class);
58-
$this->extensionAttributesFactoryMock = $this->getMockBuilder(
58+
$this->extensionAttributesFactoryMock = $this->createMock(
5959
\Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface::class
60-
)
61-
->setMethods(['process'])
62-
->disableOriginalConstructor()
63-
->getMockforAbstractClass();
60+
);
6461

6562
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
6663
$this->model = $this->objectManager->getObject(
@@ -77,7 +74,6 @@ protected function setUp()
7774

7875
public function testGetItems()
7976
{
80-
$this->markTestSkipped('Test needs to be refactored.');
8177
$optionId = 1;
8278
$optionData = ['title' => 'test title'];
8379
$productSku = 'product_sku';
@@ -90,7 +86,11 @@ public function testGetItems()
9086
['getOptionId', 'getData', 'getTitle', 'getDefaultTitle']
9187
);
9288
$optionsCollMock = $this->getMockBuilder(\Magento\Bundle\Model\ResourceModel\Option\Collection::class)
93-
->setConstructorArgs([$optionMock]);
89+
->disableOriginalConstructor()
90+
->getMock();
91+
$optionsCollMock->expects($this->any())
92+
->method('getIterator')
93+
->willReturn(new \ArrayIterator([$optionMock]));
9494
$this->typeMock->expects($this->once())
9595
->method('getOptionsCollection')
9696
->with($productMock)

app/code/Magento/Customer/Test/Unit/Model/FileUploaderTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ protected function setUp()
5757
->getMockForAbstractClass();
5858
}
5959

60+
protected function tearDown()
61+
{
62+
$_FILES = [];
63+
}
64+
6065
/**
6166
* @param string $entityTypeCode
6267
* @param string $scope

app/code/Magento/Integration/Test/Unit/Model/AdminTokenServiceTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
<?php
22
/**
3-
* Test for \Magento\Integration\Model\AdminTokenService
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/
8-
9-
// @codingStandardsIgnoreFile
10-
116
namespace Magento\Integration\Test\Unit\Model;
127

138
use Magento\Integration\Model\Integration;
149
use Magento\Integration\Model\Oauth\Token;
1510

11+
/**
12+
* @codingStandardsIgnoreFile
13+
*/
1614
class AdminTokenServiceTest extends \PHPUnit\Framework\TestCase
1715
{
1816
/** \Magento\Integration\Model\AdminTokenService */
@@ -50,7 +48,7 @@ protected function setUp()
5048

5149
$this->_tokenMock = $this->getMockBuilder(\Magento\Integration\Model\Oauth\Token::class)
5250
->disableOriginalConstructor()
53-
->setMethods(['getToken', 'loadByAdminId', '__wakeup', 'delete'])->getMock();
51+
->setMethods(['getToken', 'loadByAdminId', 'delete', '__wakeup'])->getMock();
5452

5553
$this->_tokenModelCollectionMock = $this->getMockBuilder(
5654
\Magento\Integration\Model\ResourceModel\Oauth\Token\Collection::class

app/code/Magento/Integration/Test/Unit/Model/CustomerTokenServiceTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22
/**
3-
* Test for \Magento\Integration\Model\CustomerTokenService
4-
*
53
* Copyright © Magento, Inc. All rights reserved.
64
* See COPYING.txt for license details.
75
*/

app/code/Magento/Theme/Test/Unit/Controller/Adminhtml/Design/Config/FileUploader/SaveTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@ public function setUp()
4747
$this->controller = new Save($this->context, $this->fileProcessor);
4848
}
4949

50+
protected function tearDown()
51+
{
52+
$_FILES = [];
53+
}
54+
5055
public function testExecute()
5156
{
52-
$this->markTestSkipped('Test needs to be refactored.');
5357
$_FILES['test_key'] = [];
5458
$result = [
5559
'file' => '',

dev/tests/integration/framework/Magento/TestFramework/Annotation/AppIsolation.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class AppIsolation
2323
*/
2424
private $_application;
2525

26+
/**
27+
* @var array
28+
*/
29+
private $serverGlobalBackup;
30+
2631
/**
2732
* Constructor
2833
*
@@ -52,9 +57,18 @@ protected function _isolateApp()
5257
*/
5358
public function startTestSuite()
5459
{
60+
$this->serverGlobalBackup = $_SERVER;
5561
$this->_isolateApp();
5662
}
5763

64+
/**
65+
* Isolate application after running test case
66+
*/
67+
public function endTestSuite()
68+
{
69+
$_SERVER = $this->serverGlobalBackup;
70+
}
71+
5872
/**
5973
* Handler for 'endTest' event
6074
*
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\TestFramework\Helper;
7+
8+
class Xpath
9+
{
10+
/**
11+
* Get elements count for XPath
12+
*
13+
* @param string $xpath
14+
* @param string $html
15+
* @return int
16+
*/
17+
public static function getElementsCountForXpath($xpath, $html)
18+
{
19+
$domDocument = new \DOMDocument('1.0', 'UTF-8');
20+
libxml_use_internal_errors(true);
21+
$domDocument->loadHTML($html);
22+
libxml_use_internal_errors(false);
23+
$domXpath = new \DOMXPath($domDocument);
24+
$nodes = $domXpath->query($xpath);
25+
return $nodes->length;
26+
}
27+
}

dev/tests/integration/framework/Magento/TestFramework/TestCase/AbstractController.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,56 @@ protected function getCookieMessages($messageType = null)
289289

290290
return $actualMessages;
291291
}
292+
293+
/**
294+
* Assert count of elements found by XPath in XML/HTML string
295+
*
296+
* @param string $xpath
297+
* @param int $count
298+
* @param string $html
299+
* @param string|null $message
300+
*/
301+
public function assertXpathCount($xpath, $count, $html, $message = '')
302+
{
303+
$this->assertEquals(
304+
$count,
305+
$this->getElementsCountForXpath($xpath, $html),
306+
$message
307+
);
308+
}
309+
310+
/**
311+
* Assert count of elements found by XPath in XML/HTML string greater or equal to specified value
312+
*
313+
* @param string $xpath
314+
* @param int $count
315+
* @param string $html
316+
* @param string|null $message
317+
*/
318+
public function assertXpathCountGreaterThanOrEqual($xpath, $count, $html, $message = '')
319+
{
320+
$this->assertGreaterThanOrEqual(
321+
$count,
322+
$this->getElementsCountForXpath($xpath, $html),
323+
$message
324+
);
325+
}
326+
327+
/**
328+
* Get elements count for XPath
329+
*
330+
* @param string $xpath
331+
* @param string $html
332+
* @return int
333+
*/
334+
private function getElementsCountForXpath($xpath, $html)
335+
{
336+
$domDocument = new \DOMDocument('1.0', 'UTF-8');
337+
libxml_use_internal_errors(true);
338+
$domDocument->loadHTML($html);
339+
libxml_use_internal_errors(false);
340+
$domXpath = new \DOMXPath($domDocument);
341+
$nodes = $domXpath->query($xpath);
342+
return $nodes->length;
343+
}
292344
}

0 commit comments

Comments
 (0)