Skip to content

Commit 3bf3648

Browse files
33294: Code refactoring after code review
1 parent 4bcfac1 commit 3bf3648

File tree

2 files changed

+19
-39
lines changed

2 files changed

+19
-39
lines changed

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public function testAddAttachmentUniqueName(): void
106106
{
107107
$expectedData = 'string';
108108
$expectedCaption = 'caption';
109-
$this->mockCopyFile($expectedData, $expectedCaption);
110109

111110
//Prepare Allure lifecycle
112111
Allure::lifecycle()->fire(new StepStartedEvent('firstStep'));
@@ -146,29 +145,4 @@ private function mockAttachmentWriteEvent(string $filePathOrContents, string $ca
146145
$instanceProperty->setAccessible(true);
147146
$instanceProperty->setValue($mockInstance, $mockInstance);
148147
}
149-
150-
/**
151-
* Mock only file writing mechanism.
152-
*
153-
* @param string $filePathOrContents
154-
* @param string $caption
155-
*
156-
* @return void
157-
*/
158-
private function mockCopyFile(string $filePathOrContents, string $caption): void
159-
{
160-
$mockInstance = $this->getMockBuilder(AddUniqueAttachmentEvent::class)
161-
->setConstructorArgs([$filePathOrContents, $caption])
162-
->disallowMockingUnknownTypes()
163-
->onlyMethods(['copyFile'])
164-
->getMock();
165-
166-
$mockInstance
167-
->method('copyFile')
168-
->willReturn(true);
169-
170-
$instanceProperty = new ReflectionProperty(AddUniqueAttachmentEvent::class, 'instance');
171-
$instanceProperty->setAccessible(true);
172-
$instanceProperty->setValue($mockInstance, $mockInstance);
173-
}
174148
}

src/Magento/FunctionalTestingFramework/Allure/Event/AddUniqueAttachmentEvent.php

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\FunctionalTestingFramework\Allure\Event;
99

10+
use Magento\FunctionalTestingFramework\Config\MftfApplicationConfig;
11+
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
1012
use Symfony\Component\Mime\MimeTypes;
1113
use Yandex\Allure\Adapter\AllureException;
1214
use Yandex\Allure\Adapter\Event\AddAttachmentEvent;
@@ -56,19 +58,6 @@ public function getAttachmentFileName($filePathOrContents, $type): string
5658
return $this->getOutputFileName($fileSha1, $fileExtension);
5759
}
5860

59-
/**
60-
* Copies file from one path to another. Wrapper for mocking in unit test.
61-
*
62-
* @param string $filePath
63-
* @param string $outputPath
64-
*
65-
* @return boolean
66-
*/
67-
public function copyFile(string $filePath, string $outputPath): bool
68-
{
69-
return copy($filePath, $outputPath);
70-
}
71-
7261
/**
7362
* Unit test helper function.
7463
*
@@ -93,6 +82,23 @@ public static function getInstance(
9382
return self::$instance;
9483
}
9584

85+
/**
86+
* Copies file from one path to another. Wrapper for mocking in unit test.
87+
*
88+
* @param string $filePath
89+
* @param string $outputPath
90+
*
91+
* @return boolean
92+
* @throws TestFrameworkException
93+
*/
94+
private function copyFile(string $filePath, string $outputPath): bool
95+
{
96+
if (MftfApplicationConfig::getConfig()->getPhase() === MftfApplicationConfig::UNIT_TEST_PHASE) {
97+
return true;
98+
}
99+
return copy($filePath, $outputPath);
100+
}
101+
96102
/**
97103
* Copy of parent private function.
98104
*

0 commit comments

Comments
 (0)