Skip to content

Commit

Permalink
Merge pull request #27706 from lbajsarowicz/phpunit8/module-TaxImport…
Browse files Browse the repository at this point in the history
…Export

#27500 PHPUnit 8 for module TaxImportExport
  • Loading branch information
Oleksii Korshenko authored Apr 15, 2020
2 parents a165aad + 25a9132 commit 75e8173
Showing 1 changed file with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,28 +1,40 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\TaxImportExport\Test\Unit\Controller\Adminhtml\Rate;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\Response\Http\FileFactory;
use Magento\Framework\DataObject;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Store\Model\ResourceModel\Store\Collection;
use Magento\Store\Model\Store;
use Magento\Tax\Model\Calculation\Rate\Title;
use Magento\TaxImportExport\Controller\Adminhtml\Rate\ExportPost;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ExportPostTest extends \PHPUnit\Framework\TestCase
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ExportPostTest extends TestCase
{
/**
* @var \Magento\TaxImportExport\Controller\Adminhtml\Rate\ExportPost
* @var ExportPost
*/
private $controller;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
private $fileFactoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
private $objectManagerMock;

Expand All @@ -31,13 +43,13 @@ class ExportPostTest extends \PHPUnit\Framework\TestCase
*/
private $objectManagerHelper;

protected function setUp()
protected function setUp(): void
{
$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->fileFactoryMock = $this->createMock(\Magento\Framework\App\Response\Http\FileFactory::class);
$this->objectManagerMock = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
$this->fileFactoryMock = $this->createMock(FileFactory::class);
$this->objectManagerMock = $this->createMock(ObjectManagerInterface::class);
$this->controller = $this->objectManagerHelper->getObject(
\Magento\TaxImportExport\Controller\Adminhtml\Rate\ExportPost::class,
ExportPost::class,
[
'fileFactory' => $this->fileFactoryMock,
'objectManager' => $this->objectManagerMock
Expand All @@ -47,7 +59,7 @@ protected function setUp()

public function testExecute()
{
$headers = new \Magento\Framework\DataObject(
$headers = new DataObject(
[
'code' => __('Code'),
'country_name' => __('Country'),
Expand All @@ -63,9 +75,9 @@ public function testExecute()
',"{{zip_is_range}}","{{zip_from}}","{{zip_to}}"';
$content = $headers->toString($template);
$content .= "\n";
$storeMock = $this->createMock(\Magento\Store\Model\Store::class);
$storeMock = $this->createMock(Store::class);
$storeCollectionMock = $this->objectManagerHelper->getCollectionMock(
\Magento\Store\Model\ResourceModel\Store\Collection::class,
Collection::class,
[]
);
$rateCollectionMock = $this->objectManagerHelper->getCollectionMock(
Expand All @@ -78,12 +90,12 @@ public function testExecute()
[]
);
$storeCollectionMock->expects($this->once())->method('setLoadDefault')->willReturnSelf();
$rateTitleMock = $this->createMock(\Magento\Tax\Model\Calculation\Rate\Title::class);
$rateTitleMock = $this->createMock(Title::class);
$rateTitleMock->expects($this->once())->method('getCollection')->willReturn($taxCollectionMock);
$storeMock->expects($this->once())->method('getCollection')->willReturn($storeCollectionMock);
$this->objectManagerMock->expects($this->any())->method('create')->willReturnMap([
[\Magento\Store\Model\Store::class, [], $storeMock],
[\Magento\Tax\Model\Calculation\Rate\Title::class, [], $rateTitleMock],
[Store::class, [], $storeMock],
[Title::class, [], $rateTitleMock],
[\Magento\Tax\Model\ResourceModel\Calculation\Rate\Collection::class, [], $rateCollectionMock]
]);
$rateCollectionMock->expects($this->once())->method('joinCountryTable')->willReturnSelf();
Expand Down

0 comments on commit 75e8173

Please sign in to comment.