Skip to content

#27500 Prepare SendFriend module Tests for PHPUnit 8 #27715

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
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,32 +7,36 @@
namespace Magento\SendFriend\Test\Unit\Block\Plugin\Catalog\Product;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\SendFriend\Block\Plugin\Catalog\Product\View;
use Magento\SendFriend\Model\SendFriend;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class ViewTest extends \PHPUnit\Framework\TestCase
class ViewTest extends TestCase
{
/** @var \Magento\SendFriend\Block\Plugin\Catalog\Product\View */
/** @var View */
protected $view;

/** @var ObjectManagerHelper */
protected $objectManagerHelper;

/** @var \Magento\SendFriend\Model\SendFriend|\PHPUnit_Framework_MockObject_MockObject */
/** @var SendFriend|MockObject */
protected $sendfriendModel;

/** @var \Magento\Catalog\Block\Product\View|\PHPUnit_Framework_MockObject_MockObject */
/** @var \Magento\Catalog\Block\Product\View|MockObject */
protected $productView;

protected function setUp()
protected function setUp(): void
{
$this->sendfriendModel = $this->createPartialMock(
\Magento\SendFriend\Model\SendFriend::class,
SendFriend::class,
['__wakeup', 'canEmailToFriend']
);
$this->productView = $this->createMock(\Magento\Catalog\Block\Product\View::class);

$this->objectManagerHelper = new ObjectManagerHelper($this);
$this->view = $this->objectManagerHelper->getObject(
\Magento\SendFriend\Block\Plugin\Catalog\Product\View::class,
View::class,
[
'sendfriend' => $this->sendfriendModel
]
Expand Down
28 changes: 17 additions & 11 deletions app/code/Magento/SendFriend/Test/Unit/Block/SendTest.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\SendFriend\Test\Unit\Block;

use Magento\Framework\App\RequestInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\UrlInterface;
use Magento\SendFriend\Block\Send;
use Magento\SendFriend\Model\SendFriend;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class SendTest extends \PHPUnit\Framework\TestCase
class SendTest extends TestCase
{
/**
* @var \Magento\SendFriend\Block\Send
* @var Send
*/
protected $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\SendFriend\Model\SendFriend
* @var MockObject|SendFriend
*/
protected $sendfriendMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\UrlInterface
* @var MockObject|UrlInterface
*/
protected $urlBuilderMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\RequestInterface
* @var MockObject|RequestInterface
*/
protected $requestMock;

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

$this->sendfriendMock = $this->getMockBuilder(\Magento\SendFriend\Model\SendFriend::class)
$this->sendfriendMock = $this->getMockBuilder(SendFriend::class)
->disableOriginalConstructor()
->getMock();
$this->urlBuilderMock = $this->getMockBuilder(\Magento\Framework\UrlInterface::class)
$this->urlBuilderMock = $this->getMockBuilder(UrlInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->requestMock = $this->getMockBuilder(\Magento\Framework\App\RequestInterface::class)
$this->requestMock = $this->getMockBuilder(RequestInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();

$this->model = $objectManager->getObject(
\Magento\SendFriend\Block\Send::class,
Send::class,
[
'sendfriend' => $this->sendfriendMock,
'urlBuilder' => $this->urlBuilderMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\SendFriend\Model\CaptchaValidator;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use PHPUnit_Framework_MockObject_MockObject;

/**
* Test CaptchaValidatorTest
Expand All @@ -34,39 +34,39 @@ class CaptchaValidatorTest extends TestCase
private $model;

/**
* @var CaptchaStringResolver|PHPUnit_Framework_MockObject_MockObject
* @var CaptchaStringResolver|MockObject
*/
private $captchaStringResolverMock;

/**
* @var UserContextInterface|PHPUnit_Framework_MockObject_MockObject
* @var UserContextInterface|MockObject
*/
private $currentUserMock;

/**
* @var CustomerRepositoryInterface|PHPUnit_Framework_MockObject_MockObject
* @var CustomerRepositoryInterface|MockObject
*/
private $customerRepositoryMock;

/**
* @var Data|PHPUnit_Framework_MockObject_MockObject
* @var Data|MockObject
*/
private $captchaHelperMock;

/**
* @var DefaultModel|PHPUnit_Framework_MockObject_MockObject
* @var DefaultModel|MockObject
*/
private $captchaMock;

/**
* @var RequestInterface|PHPUnit_Framework_MockObject_MockObject
* @var RequestInterface|MockObject
*/
private $requestMock;

/**
* Set Up
*/
protected function setUp()
protected function setUp(): void
{
$objectManager = new ObjectManager($this);

Expand Down Expand Up @@ -120,12 +120,11 @@ public function testCaptchaValidationOnSend(bool $captchaIsRequired, bool $captc

/**
* Testing the wrong used word for captcha
*
* @expectedException \Magento\Framework\Exception\LocalizedException
* @expectedExceptionMessage Incorrect CAPTCHA
*/
public function testWrongCaptcha()
{
$this->expectException('Magento\Framework\Exception\LocalizedException');
$this->expectExceptionMessage('Incorrect CAPTCHA');
$word = 'test-word';
$captchaIsRequired = true;
$captchaWordIsCorrect = false;
Expand Down
27 changes: 16 additions & 11 deletions app/code/Magento/SendFriend/Test/Unit/Model/SendFriendTest.php
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
<?php
<?php declare(strict_types=1);
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\SendFriend\Test\Unit\Model;

use Magento\Framework\Stdlib\CookieManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\SendFriend\Helper\Data;
use Magento\SendFriend\Model\SendFriend;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Test SendFriend
*
*/
class SendFriendTest extends \PHPUnit\Framework\TestCase
class SendFriendTest extends TestCase
{
/**
* @var \Magento\SendFriend\Model\SendFriend
* @var SendFriend
*/
protected $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Stdlib\CookieManagerInterface
* @var MockObject|CookieManagerInterface
*/
protected $cookieManagerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
* @var MockObject
*/
protected $sendfriendDataMock;

protected function setUp()
protected function setUp(): void
{
$objectManager = new ObjectManager($this);
$this->sendfriendDataMock = $this->getMockBuilder(\Magento\SendFriend\Helper\Data::class)
$this->sendfriendDataMock = $this->getMockBuilder(Data::class)
->disableOriginalConstructor()
->getMock();
$this->cookieManagerMock = $this->createMock(\Magento\Framework\Stdlib\CookieManagerInterface::class);
$this->cookieManagerMock = $this->createMock(CookieManagerInterface::class);

$this->model = $objectManager->getObject(
\Magento\SendFriend\Model\SendFriend::class,
SendFriend::class,
[
'sendfriendData' => $this->sendfriendDataMock,
'cookieManager' => $this->cookieManagerMock,
Expand All @@ -50,7 +55,7 @@ public function testGetSentCountWithCheckCookie()
{
$cookieName = 'testCookieName';
$this->sendfriendDataMock->expects($this->once())->method('getLimitBy')->with()->will(
$this->returnValue(\Magento\SendFriend\Helper\Data::CHECK_COOKIE)
$this->returnValue(Data::CHECK_COOKIE)
);
$this->sendfriendDataMock->expects($this->once())->method('getCookieName')->with()->will(
$this->returnValue($cookieName)
Expand All @@ -69,7 +74,7 @@ public function testSentCountByCookies()

$this->cookieManagerMock->expects($this->once())->method('getCookie')->with($cookieName);
$this->cookieManagerMock->expects($this->once())->method('setSensitiveCookie');
$sendFriendClass = new \ReflectionClass(\Magento\SendFriend\Model\SendFriend::class);
$sendFriendClass = new \ReflectionClass(SendFriend::class);
$method = $sendFriendClass->getMethod('_sentCountByCookies');
$method->setAccessible(true);
$method->invokeArgs($this->model, [true]);
Expand Down