Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,53 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Captcha\Test\Unit\Observer;

use Magento\Captcha\Model\ResourceModel\Log;
use Magento\Captcha\Model\ResourceModel\LogFactory;
use Magento\Captcha\Observer\ResetAttemptForBackendObserver;
use Magento\Framework\Event;
use Magento\Framework\Event\Observer;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Unit test for \Magento\Captcha\Observer\ResetAttemptForBackendObserver
*/
class ResetAttemptForBackendObserverTest extends TestCase
{
/**
* Test that the method resets attempts for Backend
*/
public function testExecuteExpectsDeleteUserAttemptsCalled()
{
$logMock = $this->createMock(Log::class);
$logMock->expects($this->once())->method('deleteUserAttempts');

$resLogFactoryMock = $this->createMock(LogFactory::class);
$resLogFactoryMock->expects($this->once())
->method('create')
->willReturn($logMock);

/** @var MockObject|Observer $eventObserverMock */
$eventObserverMock = $this->createPartialMock(Observer::class, ['getUser']);
$eventMock = $this->createMock(Event::class);
$eventObserverMock->expects($this->once())
->method('getUser')
->willReturn($eventMock);

$objectManager = new ObjectManagerHelper($this);
/** @var ResetAttemptForBackendObserver $observer */
$observer = $objectManager->getObject(
ResetAttemptForBackendObserver::class,
['resLogFactory' => $resLogFactoryMock]
);
$observer->execute($eventObserverMock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the execute method returns a value, it makes sense to add the corresponding assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, done

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Captcha\Test\Unit\Observer;

use Magento\Captcha\Model\ResourceModel\Log;
use Magento\Captcha\Model\ResourceModel\LogFactory;
use Magento\Captcha\Observer\ResetAttemptForFrontendObserver;
use Magento\Customer\Model\Customer;
use Magento\Framework\Event\Observer;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

/**
* Unit test for \Magento\Captcha\Observer\ResetAttemptForFrontendObserver
*/
class ResetAttemptForFrontendObserverTest extends TestCase
{
/**
* Test that the method resets attempts for Frontend
*/
public function testExecuteExpectsDeleteUserAttemptsCalled()
{
$logMock = $this->createMock(Log::class);
$logMock->expects($this->once())->method('deleteUserAttempts');

$resLogFactoryMock = $this->createMock(LogFactory::class);
$resLogFactoryMock->expects($this->once())
->method('create')
->willReturn($logMock);

/** @var MockObject|Observer $eventObserverMock */
$eventObserverMock = $this->createPartialMock(Observer::class, ['getModel']);
$eventObserverMock->expects($this->once())
->method('getModel')
->willReturn($this->createMock(Customer::class));

$objectManager = new ObjectManagerHelper($this);
/** @var ResetAttemptForFrontendObserver $observer */
$observer = $objectManager->getObject(
ResetAttemptForFrontendObserver::class,
['resLogFactory' => $resLogFactoryMock]
);
$observer->execute($eventObserverMock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the execute method returns a value, it makes sense to add the corresponding assertion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
}