33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+ declare (strict_types=1 );
67
78namespace tests \unit \Util ;
89
9- use AspectMock \Test as AspectMock ;
1010use Magento \FunctionalTestingFramework \Util \Logger \LoggingUtil ;
1111use Magento \FunctionalTestingFramework \Util \Logger \MftfLogger ;
1212use Monolog \Handler \TestHandler ;
13- use PHPUnit \Framework \Assert ;
13+ use PHPUnit \Framework \TestCase ;
14+ use ReflectionProperty ;
1415
15- class TestLoggingUtil extends Assert
16+ class TestLoggingUtil extends TestCase
1617{
1718 /**
1819 * @var TestLoggingUtil
@@ -25,24 +26,23 @@ class TestLoggingUtil extends Assert
2526 private $ testLogHandler ;
2627
2728 /**
28- * TestLoggingUtil constructor.
29+ * Private constructor.
2930 */
3031 private function __construct ()
3132 {
32- // private constructor
33+ parent :: __construct ( null , [], '' );
3334 }
3435
3536 /**
36- * Static singleton get function
37+ * Static singleton get function.
3738 *
3839 * @return TestLoggingUtil
3940 */
40- public static function getInstance ()
41+ public static function getInstance (): TestLoggingUtil
4142 {
4243 if (self ::$ instance == null ) {
4344 self ::$ instance = new TestLoggingUtil ();
4445 }
45-
4646 return self ::$ instance ;
4747 }
4848
@@ -51,21 +51,28 @@ public static function getInstance()
5151 *
5252 * @return void
5353 */
54- public function setMockLoggingUtil ()
54+ public function setMockLoggingUtil (): void
5555 {
5656 $ this ->testLogHandler = new TestHandler ();
5757 $ testLogger = new MftfLogger ('testLogger ' );
5858 $ 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 ' );
6466 $ property ->setAccessible (true );
6567 $ property ->setValue ($ mockLoggingUtil );
6668 }
6769
68- public function validateMockLogEmpty ()
70+ /**
71+ * Check if mock log is empty.
72+ *
73+ * @return void
74+ */
75+ public function validateMockLogEmpty (): void
6976 {
7077 $ records = $ this ->testLogHandler ->getRecords ();
7178 $ this ->assertTrue (empty ($ records ));
@@ -77,9 +84,10 @@ public function validateMockLogEmpty()
7784 * @param string $type
7885 * @param string $message
7986 * @param array $context
87+ *
8088 * @return void
8189 */
82- public function validateMockLogStatement ($ type , $ message , $ context )
90+ public function validateMockLogStatement (string $ type , string $ message , array $ context ): void
8391 {
8492 $ records = $ this ->testLogHandler ->getRecords ();
8593 $ record = $ records [count ($ records )-1 ]; // we assume the latest record is what requires validation
@@ -88,7 +96,16 @@ public function validateMockLogStatement($type, $message, $context)
8896 $ this ->assertEquals ($ context , $ record ['context ' ]);
8997 }
9098
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
92109 {
93110 $ records = $ this ->testLogHandler ->getRecords ();
94111 $ record = $ records [count ($ records )-1 ]; // we assume the latest record is what requires validation
@@ -103,8 +120,10 @@ public function validateMockLogStatmentRegex($type, $regex, $context)
103120 *
104121 * @return void
105122 */
106- public function clearMockLoggingUtil ()
123+ public function clearMockLoggingUtil (): void
107124 {
108- AspectMock::clean (LoggingUtil::class);
125+ $ property = new ReflectionProperty (LoggingUtil::class, 'instance ' );
126+ $ property ->setAccessible (true );
127+ $ property ->setValue (null );
109128 }
110129}
0 commit comments