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

#27500 PHPUnit 8 for module TaxImportExport #27706

Merged
Merged
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
@@ -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