Skip to content

Commit 9484d85

Browse files
author
silinmykola
committed
33294 eliminate aspectMock from allureHelperTest
1 parent 0a77327 commit 9484d85

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Allure/AllureHelperTest.php

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
use Magento\FunctionalTestingFramework\Allure\AllureHelper;
99
use Magento\FunctionalTestingFramework\Allure\Event\AddUniqueAttachmentEvent;
10+
use PHPUnit\Framework\TestCase;
1011
use Yandex\Allure\Adapter\Allure;
11-
use Yandex\Allure\Adapter\Event\AddAttachmentEvent;
12+
use Yandex\Allure\Adapter\AllureException;
1213
use Yandex\Allure\Adapter\Event\StepFinishedEvent;
1314
use Yandex\Allure\Adapter\Event\StepStartedEvent;
1415
use Yandex\Allure\Adapter\Model\Attachment;
15-
use AspectMock\Test as AspectMock;
16-
use PHPUnit\Framework\TestCase;
1716

1817
class AllureHelperTest extends TestCase
1918
{
@@ -25,12 +24,11 @@ class AllureHelperTest extends TestCase
2524
public function tearDown(): void
2625
{
2726
Allure::setDefaultLifecycle();
28-
AspectMock::clean();
2927
}
3028

3129
/**
32-
* AddAtachmentToStep should add an attachment to the current step
33-
* @throws \Yandex\Allure\Adapter\AllureException
30+
* AddAttachmentToStep should add an attachment to the current step
31+
* @throws AllureException
3432
*/
3533
public function testAddAttachmentToStep()
3634
{
@@ -52,7 +50,7 @@ public function testAddAttachmentToStep()
5250

5351
/**
5452
* AddAttachmentToLastStep should add an attachment only to the last step
55-
* @throws \Yandex\Allure\Adapter\AllureException
53+
* @throws AllureException
5654
*/
5755
public function testAddAttachmentToLastStep()
5856
{
@@ -88,14 +86,15 @@ public function testAddAttachmentToLastStep()
8886

8987
/**
9088
* AddAttachment actions should have files with different attachment names
91-
* @throws \Yandex\Allure\Adapter\AllureException
89+
* @throws AllureException
9290
*/
9391
public function testAddAttachementUniqueName()
9492
{
95-
$this->mockCopyFile();
9693
$expectedData = "string";
9794
$expectedCaption = "caption";
9895

96+
$this->mockCopyFile($expectedData, $expectedCaption);
97+
9998
//Prepare Allure lifecycle
10099
Allure::lifecycle()->fire(new StepStartedEvent('firstStep'));
101100

@@ -112,23 +111,26 @@ public function testAddAttachementUniqueName()
112111

113112
/**
114113
* Mock entire attachment writing mechanisms
115-
* @throws \Exception
116114
*/
117115
public function mockAttachmentWriteEvent()
118116
{
119-
AspectMock::double(AddUniqueAttachmentEvent::class, [
120-
"getAttachmentFileName" => self::MOCK_FILENAME
121-
]);
117+
$this->createMock(AddUniqueAttachmentEvent::class)
118+
->expects($this->any())
119+
->method('getAttachmentFileName')
120+
->willReturn(self::MOCK_FILENAME);
122121
}
123122

124123
/**
125124
* Mock only file writing mechanism
126-
* @throws \Exception
125+
* @throws \ReflectionException
127126
*/
128-
public function mockCopyFile()
127+
public function mockCopyFile(string $expectedData, string $expectedCaption)
129128
{
130-
AspectMock::double(AddUniqueAttachmentEvent::class, [
131-
"copyFile" => true
132-
]);
129+
$addUniqueAttachmentEvent = new AddUniqueAttachmentEvent($expectedData, $expectedCaption);
130+
$reflection = new \ReflectionClass(AddUniqueAttachmentEvent::class);
131+
$reflectionMethod = $reflection->getMethod('copyFile');
132+
$reflectionMethod->setAccessible(true);
133+
$output = $reflectionMethod->invoke($addUniqueAttachmentEvent);
134+
$this->assertEquals(true, $output);
133135
}
134136
}

0 commit comments

Comments
 (0)