File tree Expand file tree Collapse file tree 3 files changed +34
-1
lines changed
Module/I18n/Parser/Adapter/Php
Test/Unit/Module/I18n/Parser/Adapter/Php Expand file tree Collapse file tree 3 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -68,7 +68,11 @@ public function isMatchingClass($className)
68
68
$ state = 1 ;
69
69
$ classString = '' ;
70
70
while ($ token = $ this ->getNextRealToken ()) {
71
- if ($ token ->isNamespaceSeparator () && $ state != 2 ) {
71
+ if ($ token ->isFullQualifiedName ()) {
72
+ // In PHP 8.0, it can be already a full name e.g. \Magento\Framework\Phrase.
73
+ $ classString = $ token ->getValue ();
74
+ $ state = 3 ;
75
+ } elseif ($ token ->isNamespaceSeparator () && $ state != 2 ) {
72
76
$ classString .= $ token ->getValue ();
73
77
$ state = 2 ;
74
78
} elseif ($ token ->isIdentifier () && $ state != 3 ) {
Original file line number Diff line number Diff line change @@ -85,6 +85,16 @@ public function isNew()
85
85
return $ this ->getName () == T_NEW ;
86
86
}
87
87
88
+ /**
89
+ * Check if a token has a Qualified Name type, which was introduced in PHP 8.
90
+ *
91
+ * @return bool
92
+ */
93
+ public function isFullQualifiedName (): bool
94
+ {
95
+ return $ this ->getName () === T_NAME_FULLY_QUALIFIED ;
96
+ }
97
+
88
98
/**
89
99
* Whenever token is equal function
90
100
*
Original file line number Diff line number Diff line change @@ -58,8 +58,26 @@ public function testIsMatchingClass()
58
58
$ this ->assertFalse ($ this ->tokenizer ->isMatchingClass ($ class )); // ;
59
59
}
60
60
61
+ /**
62
+ * Test getting next Real token for PHP > 8, where namespaced names are treated as single token.
63
+ *
64
+ * @requires PHP >= 8.0
65
+ * @return void
66
+ */
67
+ public function testGetNextRealTokenWhenNamespaceIsSingleToken (): void
68
+ {
69
+ $ this ->parseFile ();
70
+ $ this ->assertEquals ('new ' , $ this ->tokenizer ->getNextRealToken ()->getValue ());
71
+ $ this ->assertEquals ('\\Magento \\Framework \\Phrase ' , $ this ->tokenizer ->getNextRealToken ()->getValue ());
72
+ $ this ->assertEquals ('( ' , $ this ->tokenizer ->getNextRealToken ()->getValue ());
73
+ $ this ->assertEquals ('\'Testing \'' , $ this ->tokenizer ->getNextRealToken ()->getValue ());
74
+ $ this ->assertEquals (') ' , $ this ->tokenizer ->getNextRealToken ()->getValue ());
75
+ $ this ->assertEquals ('; ' , $ this ->tokenizer ->getNextRealToken ()->getValue ());
76
+ }
77
+
61
78
/**
62
79
* @covers \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer::getNextRealToken
80
+ * @requires PHP < 8.0
63
81
*/
64
82
public function testGetNextRealToken ()
65
83
{
@@ -79,6 +97,7 @@ public function testGetNextRealToken()
79
97
80
98
/**
81
99
* @covers \Magento\Setup\Module\I18n\Parser\Adapter\Php\Tokenizer::isEndOfLoop
100
+ * @requires PHP < 8.0
82
101
*/
83
102
public function testIsEndOfLoop ()
84
103
{
You can’t perform that action at this time.
0 commit comments