7
7
8
8
use Magento \FunctionalTestingFramework \Allure \AllureHelper ;
9
9
use Magento \FunctionalTestingFramework \Allure \Event \AddUniqueAttachmentEvent ;
10
+ use PHPUnit \Framework \TestCase ;
10
11
use Yandex \Allure \Adapter \Allure ;
11
- use Yandex \Allure \Adapter \Event \ AddAttachmentEvent ;
12
+ use Yandex \Allure \Adapter \AllureException ;
12
13
use Yandex \Allure \Adapter \Event \StepFinishedEvent ;
13
14
use Yandex \Allure \Adapter \Event \StepStartedEvent ;
14
15
use Yandex \Allure \Adapter \Model \Attachment ;
15
- use AspectMock \Test as AspectMock ;
16
- use PHPUnit \Framework \TestCase ;
17
16
18
17
class AllureHelperTest extends TestCase
19
18
{
@@ -25,12 +24,11 @@ class AllureHelperTest extends TestCase
25
24
public function tearDown (): void
26
25
{
27
26
Allure::setDefaultLifecycle ();
28
- AspectMock::clean ();
29
27
}
30
28
31
29
/**
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
34
32
*/
35
33
public function testAddAttachmentToStep ()
36
34
{
@@ -52,7 +50,7 @@ public function testAddAttachmentToStep()
52
50
53
51
/**
54
52
* AddAttachmentToLastStep should add an attachment only to the last step
55
- * @throws \Yandex\Allure\Adapter\ AllureException
53
+ * @throws AllureException
56
54
*/
57
55
public function testAddAttachmentToLastStep ()
58
56
{
@@ -88,14 +86,15 @@ public function testAddAttachmentToLastStep()
88
86
89
87
/**
90
88
* AddAttachment actions should have files with different attachment names
91
- * @throws \Yandex\Allure\Adapter\ AllureException
89
+ * @throws AllureException
92
90
*/
93
91
public function testAddAttachementUniqueName ()
94
92
{
95
- $ this ->mockCopyFile ();
96
93
$ expectedData = "string " ;
97
94
$ expectedCaption = "caption " ;
98
95
96
+ $ this ->mockCopyFile ($ expectedData , $ expectedCaption );
97
+
99
98
//Prepare Allure lifecycle
100
99
Allure::lifecycle ()->fire (new StepStartedEvent ('firstStep ' ));
101
100
@@ -112,23 +111,26 @@ public function testAddAttachementUniqueName()
112
111
113
112
/**
114
113
* Mock entire attachment writing mechanisms
115
- * @throws \Exception
116
114
*/
117
115
public function mockAttachmentWriteEvent ()
118
116
{
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 );
122
121
}
123
122
124
123
/**
125
124
* Mock only file writing mechanism
126
- * @throws \Exception
125
+ * @throws \ReflectionException
127
126
*/
128
- public function mockCopyFile ()
127
+ public function mockCopyFile (string $ expectedData , string $ expectedCaption )
129
128
{
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 );
133
135
}
134
136
}
0 commit comments