Skip to content

#27500 PHPUnit 8 for module DHL #27713

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

Merged
merged 2 commits into from
Apr 15, 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
37 changes: 18 additions & 19 deletions app/code/Magento/Dhl/Test/Unit/Model/CarrierTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
Expand All @@ -10,6 +10,7 @@
use Magento\Dhl\Model\Validator\XmlValidator;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\ProductMetadataInterface;
use Magento\Framework\DataObject;
use Magento\Framework\Filesystem\Directory\Read;
use Magento\Framework\Filesystem\Directory\ReadFactory;
use Magento\Framework\HTTP\ZendClient;
Expand All @@ -24,22 +25,21 @@
use Magento\Quote\Model\Quote\Address\RateResult\ErrorFactory;
use Magento\Quote\Model\Quote\Address\RateResult\Method;
use Magento\Quote\Model\Quote\Address\RateResult\MethodFactory;
use Magento\Sales\Model\Order;
use Magento\Shipping\Helper\Carrier as CarrierHelper;
use Magento\Shipping\Model\Rate\Result;
use Magento\Shipping\Model\Rate\ResultFactory;
use Magento\Shipping\Model\Shipment\Request;
use Magento\Shipping\Model\Simplexml\Element;
use Magento\Shipping\Model\Simplexml\ElementFactory;
use Magento\Store\Model\StoreManager;
use Magento\Store\Model\Website;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\MockObject\MockObject as MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class CarrierTest extends \PHPUnit\Framework\TestCase
class CarrierTest extends TestCase
{
/**
* @var ObjectManager
Expand Down Expand Up @@ -99,7 +99,7 @@ class CarrierTest extends \PHPUnit\Framework\TestCase
/**
* @inheritdoc
*/
protected function setUp()
protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);

Expand Down Expand Up @@ -209,11 +209,11 @@ public function testPrepareShippingLabelContent()
* Prepare shipping label content exception test
*
* @dataProvider prepareShippingLabelContentExceptionDataProvider
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage Unable to retrieve shipping label
*/
public function testPrepareShippingLabelContentException(\SimpleXMLElement $xml)
{
$this->expectException('Magento\Framework\Exception\LocalizedException');
$this->expectExceptionMessage('Unable to retrieve shipping label');
$this->_invokePrepareShippingLabelContent($xml);
}

Expand Down Expand Up @@ -242,7 +242,7 @@ public function prepareShippingLabelContentExceptionDataProvider()
* Invoke prepare shipping label content
*
* @param \SimpleXMLElement $xml
* @return \Magento\Framework\DataObject
* @return DataObject
* @throws \ReflectionException
*/
protected function _invokePrepareShippingLabelContent(\SimpleXMLElement $xml)
Expand Down Expand Up @@ -372,12 +372,11 @@ public function buildMessageReferenceDataProvider()

/**
* Tests that an exception is thrown when an invalid service prefix is provided.
*
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage Invalid service prefix
*/
public function testBuildMessageReferenceInvalidPrefix()
{
$this->expectException('Magento\Framework\Exception\LocalizedException');
$this->expectExceptionMessage('Invalid service prefix');
$method = new \ReflectionMethod($this->model, 'buildMessageReference');
$method->setAccessible(true);

Expand Down Expand Up @@ -495,7 +494,7 @@ public function getGatewayURLProvider()
*
* @return ElementFactory|MockObject
*/
private function getXmlFactory(): MockObject
private function getXmlFactory(): \PHPUnit\Framework\MockObject\MockObject
{
$xmlElFactory = $this->getMockBuilder(ElementFactory::class)
->disableOriginalConstructor()
Expand All @@ -521,7 +520,7 @@ function ($data) {
*
* @return ResultFactory|MockObject
*/
private function getRateFactory(): MockObject
private function getRateFactory(): \PHPUnit\Framework\MockObject\MockObject
{
$rateFactory = $this->getMockBuilder(ResultFactory::class)
->disableOriginalConstructor()
Expand All @@ -542,7 +541,7 @@ private function getRateFactory(): MockObject
*
* @return MethodFactory|MockObject
*/
private function getRateMethodFactory(): MockObject
private function getRateMethodFactory(): \PHPUnit\Framework\MockObject\MockObject
{
$rateMethodFactory = $this->getMockBuilder(MethodFactory::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -571,7 +570,7 @@ function () {
*
* @return MockObject
*/
private function getConfigReader(): MockObject
private function getConfigReader(): \PHPUnit\Framework\MockObject\MockObject
{
$configReader = $this->getMockBuilder(Reader::class)
->disableOriginalConstructor()
Expand All @@ -587,7 +586,7 @@ private function getConfigReader(): MockObject
*
* @return MockObject
*/
private function getReadFactory(): MockObject
private function getReadFactory(): \PHPUnit\Framework\MockObject\MockObject
{
$modulesDirectory = $this->getMockBuilder(Read::class)
->disableOriginalConstructor()
Expand All @@ -607,7 +606,7 @@ private function getReadFactory(): MockObject
*
* @return MockObject
*/
private function getStoreManager(): MockObject
private function getStoreManager(): \PHPUnit\Framework\MockObject\MockObject
{
$storeManager = $this->getMockBuilder(StoreManager::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -650,7 +649,7 @@ private function getCarrierHelper(): CarrierHelper
*
* @return MockObject
*/
private function getHttpClientFactory(): MockObject
private function getHttpClientFactory(): \PHPUnit\Framework\MockObject\MockObject
{
$this->httpResponse = $this->getMockBuilder(\Zend_Http_Response::class)
->disableOriginalConstructor()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
Expand All @@ -7,10 +7,11 @@
namespace Magento\Dhl\Test\Unit\Model\Validator;

use Magento\Dhl\Model\Validator\ResponseErrorProcessor;
use Magento\Shipping\Model\Simplexml\Element;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Shipping\Model\Simplexml\Element;
use PHPUnit\Framework\TestCase;

class ResponseErrorProcessorTest extends \PHPUnit\Framework\TestCase
class ResponseErrorProcessorTest extends TestCase
{
/**
* @var ObjectManager
Expand All @@ -22,7 +23,7 @@ class ResponseErrorProcessorTest extends \PHPUnit\Framework\TestCase
*/
private $responseErrorProcessor;

protected function setUp()
protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);

Expand Down
21 changes: 11 additions & 10 deletions app/code/Magento/Dhl/Test/Unit/Model/Validator/XmlValidatorTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Dhl\Test\Unit\Model\Validator;

use Magento\Sales\Exception\DocumentValidationException;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use Magento\Framework\Xml\Security;
use Magento\Dhl\Model\Validator\ResponseErrorProcessor;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Dhl\Model\Validator\XmlValidator;
use Magento\Shipping\Model\Simplexml\Element;
use Magento\Framework\Phrase;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\Xml\Security;
use Magento\Sales\Exception\DocumentValidationException;
use PHPUnit\Framework\MockObject\MockObject as MockObject;
use PHPUnit\Framework\TestCase;

class XmlValidatorTest extends \PHPUnit\Framework\TestCase
class XmlValidatorTest extends TestCase
{
/**
* @var ObjectManager
Expand All @@ -39,7 +40,7 @@ class XmlValidatorTest extends \PHPUnit\Framework\TestCase
/**
* @return void
*/
protected function setUp()
protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);

Expand Down Expand Up @@ -84,7 +85,7 @@ public function testValidateValidXml()
*/
public function testValidateInvalidXml($data)
{
$phrase = new \Magento\Framework\Phrase('Error #%1 : %2', ['111', 'Error in parsing request XML']);
$phrase = new Phrase('Error #%1 : %2', ['111', 'Error in parsing request XML']);
$rawXml = file_get_contents(__DIR__ . '/_files/' . $data['file']);
$this->xmlSecurityMock->expects($this->any())
->method('scan')
Expand All @@ -96,7 +97,7 @@ public function testValidateInvalidXml($data)

try {
$this->xmlValidator->validate($rawXml);
} catch (\Magento\Sales\Exception\DocumentValidationException $exception) {
} catch (DocumentValidationException $exception) {
$this->assertEquals($data['errorMessage'], $exception->getMessage());
if (isset($data['code'])) {
$this->assertEquals($data['code'], $exception->getCode());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
Expand Down