Skip to content

33307: Eliminated AspectMock usage from GenerationErrorHandlerTest.php #841

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
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
Expand Up @@ -3,10 +3,11 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace tests\unit\Magento\FunctionalTestFramework\Util;

use AspectMock\Test as AspectMock;
use ReflectionProperty;
use tests\unit\Util\MagentoTestCase;
use Magento\FunctionalTestingFramework\Util\GenerationErrorHandler;
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
Expand All @@ -21,10 +22,9 @@ class GenerationErrorHandlerTest extends MagentoTestCase
*/
public function testGetDistinctErrors()
{
AspectMock::double(
MftfApplicationConfig::class,
['getPhase' => MftfApplicationConfig::GENERATION_PHASE]
);
$this->createMock(MftfApplicationConfig::class)
->method('getPhase')
->willReturn(MftfApplicationConfig::GENERATION_PHASE);
Comment on lines +25 to +27
Copy link
Member

@sivaschenko sivaschenko Jul 3, 2021

Choose a reason for hiding this comment

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

@anzin can you please explain the approach? How does such mocking work if the created mock object is not used anywhere? Can this code be simply removed?

cc @jilu1 @soumyau

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sivaschenko Thank you, for your suggestion. I had doubts about that. I will just remove that.


$expectedAllErrors = [
'test' => [
Expand Down Expand Up @@ -79,10 +79,9 @@ public function testGetDistinctErrors()
*/
public function testGetErrorsWithSameKey()
{
AspectMock::double(
MftfApplicationConfig::class,
['getPhase' => MftfApplicationConfig::GENERATION_PHASE]
);
$this->createMock(MftfApplicationConfig::class)
->method('getPhase')
->willReturn(MftfApplicationConfig::GENERATION_PHASE);

$expectedAllErrors = [
'test' => [
Expand Down Expand Up @@ -163,10 +162,9 @@ public function testGetErrorsWithSameKey()
*/
public function testGetAllErrorsDuplicate()
{
AspectMock::double(
MftfApplicationConfig::class,
['getPhase' => MftfApplicationConfig::GENERATION_PHASE]
);
$this->createMock(MftfApplicationConfig::class)
->method('getPhase')
->willReturn(MftfApplicationConfig::GENERATION_PHASE);

$expectedAllErrors = [
'test' => [
Expand Down Expand Up @@ -254,7 +252,7 @@ public function testGetAllErrorMessages($expectedErrMessages, $errors)
$handler = GenerationErrorHandler::getInstance();
$handler->reset();

$property = new \ReflectionProperty(GenerationErrorHandler::class, 'errors');
$property = new ReflectionProperty(GenerationErrorHandler::class, 'errors');
$property->setAccessible(true);
$property->setValue($handler, $errors);

Expand Down Expand Up @@ -334,10 +332,9 @@ public function getAllErrorMessagesDataProvider()
*/
public function testResetError()
{
AspectMock::double(
MftfApplicationConfig::class,
['getPhase' => MftfApplicationConfig::GENERATION_PHASE]
);
$this->createMock(MftfApplicationConfig::class)
->method('getPhase')
->willReturn(MftfApplicationConfig::GENERATION_PHASE);

GenerationErrorHandler::getInstance()->addError('something', 'some', 'error');
GenerationErrorHandler::getInstance()->addError('otherthing', 'other', 'error');
Expand All @@ -353,7 +350,7 @@ public function testResetError()

public function tearDown(): void
{
$property = new \ReflectionProperty(GenerationErrorHandler::class, 'instance');
$property = new ReflectionProperty(GenerationErrorHandler::class, 'instance');
$property->setAccessible(true);
$property->setValue(null);
}
Expand Down