3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
6
7
7
8
namespace tests \unit \Util ;
8
9
9
- use AspectMock \Test as AspectMock ;
10
10
use Magento \FunctionalTestingFramework \Util \Logger \LoggingUtil ;
11
11
use Magento \FunctionalTestingFramework \Util \Logger \MftfLogger ;
12
12
use Monolog \Handler \TestHandler ;
13
- use PHPUnit \Framework \Assert ;
13
+ use PHPUnit \Framework \TestCase ;
14
+ use ReflectionProperty ;
14
15
15
- class TestLoggingUtil extends Assert
16
+ class TestLoggingUtil extends TestCase
16
17
{
17
18
/**
18
19
* @var TestLoggingUtil
@@ -25,24 +26,23 @@ class TestLoggingUtil extends Assert
25
26
private $ testLogHandler ;
26
27
27
28
/**
28
- * TestLoggingUtil constructor.
29
+ * Private constructor.
29
30
*/
30
31
private function __construct ()
31
32
{
32
- // private constructor
33
+ parent :: __construct ( null , [], '' );
33
34
}
34
35
35
36
/**
36
- * Static singleton get function
37
+ * Static singleton get function.
37
38
*
38
39
* @return TestLoggingUtil
39
40
*/
40
- public static function getInstance ()
41
+ public static function getInstance (): TestLoggingUtil
41
42
{
42
43
if (self ::$ instance == null ) {
43
44
self ::$ instance = new TestLoggingUtil ();
44
45
}
45
-
46
46
return self ::$ instance ;
47
47
}
48
48
@@ -51,21 +51,28 @@ public static function getInstance()
51
51
*
52
52
* @return void
53
53
*/
54
- public function setMockLoggingUtil ()
54
+ public function setMockLoggingUtil (): void
55
55
{
56
56
$ this ->testLogHandler = new TestHandler ();
57
57
$ testLogger = new MftfLogger ('testLogger ' );
58
58
$ testLogger ->pushHandler ($ this ->testLogHandler );
59
- $ mockLoggingUtil = AspectMock::double (
60
- LoggingUtil::class,
61
- ['getLogger ' => $ testLogger ]
62
- )->make ();
63
- $ property = new \ReflectionProperty (LoggingUtil::class, 'instance ' );
59
+
60
+ $ mockLoggingUtil = $ this ->createMock (LoggingUtil::class);
61
+ $ mockLoggingUtil
62
+ ->method ('getLogger ' )
63
+ ->willReturn ($ testLogger );
64
+
65
+ $ property = new ReflectionProperty (LoggingUtil::class, 'instance ' );
64
66
$ property ->setAccessible (true );
65
67
$ property ->setValue ($ mockLoggingUtil );
66
68
}
67
69
68
- public function validateMockLogEmpty ()
70
+ /**
71
+ * Check if mock log is empty.
72
+ *
73
+ * @return void
74
+ */
75
+ public function validateMockLogEmpty (): void
69
76
{
70
77
$ records = $ this ->testLogHandler ->getRecords ();
71
78
$ this ->assertTrue (empty ($ records ));
@@ -77,9 +84,10 @@ public function validateMockLogEmpty()
77
84
* @param string $type
78
85
* @param string $message
79
86
* @param array $context
87
+ *
80
88
* @return void
81
89
*/
82
- public function validateMockLogStatement ($ type , $ message , $ context )
90
+ public function validateMockLogStatement (string $ type , string $ message , array $ context ): void
83
91
{
84
92
$ records = $ this ->testLogHandler ->getRecords ();
85
93
$ record = $ records [count ($ records )-1 ]; // we assume the latest record is what requires validation
@@ -88,7 +96,16 @@ public function validateMockLogStatement($type, $message, $context)
88
96
$ this ->assertEquals ($ context , $ record ['context ' ]);
89
97
}
90
98
91
- public function validateMockLogStatmentRegex ($ type , $ regex , $ context )
99
+ /**
100
+ * Check mock log statement regular expression.
101
+ *
102
+ * @param string $type
103
+ * @param string $regex
104
+ * @param array $context
105
+ *
106
+ * @return void
107
+ */
108
+ public function validateMockLogStatmentRegex (string $ type , string $ regex , array $ context ): void
92
109
{
93
110
$ records = $ this ->testLogHandler ->getRecords ();
94
111
$ record = $ records [count ($ records )-1 ]; // we assume the latest record is what requires validation
@@ -103,8 +120,10 @@ public function validateMockLogStatmentRegex($type, $regex, $context)
103
120
*
104
121
* @return void
105
122
*/
106
- public function clearMockLoggingUtil ()
123
+ public function clearMockLoggingUtil (): void
107
124
{
108
- AspectMock::clean (LoggingUtil::class);
125
+ $ property = new ReflectionProperty (LoggingUtil::class, 'instance ' );
126
+ $ property ->setAccessible (true );
127
+ $ property ->setValue (null );
109
128
}
110
129
}
0 commit comments