@@ -26,28 +26,7 @@ class PhpVersionTest extends TestCase
26
26
*/
27
27
public function testUsesPhpPlatformFromComposerJsonFileForCanUseAttributes (string $ version , bool $ expectedResult ): void
28
28
{
29
- $ json = sprintf ('{"platform-overrides": {"php": "%s"}} ' , $ version );
30
-
31
- $ mockFileManager = $ this ->createMock (FileManager::class);
32
- $ mockFileManager
33
- ->expects (self ::once ())
34
- ->method ('getRootDirectory ' )
35
- ->willReturn ('/test ' )
36
- ;
37
-
38
- $ mockFileManager
39
- ->expects (self ::once ())
40
- ->method ('fileExists ' )
41
- ->with ('/test/composer.lock ' )
42
- ->willReturn (true )
43
- ;
44
-
45
- $ mockFileManager
46
- ->expects (self ::once ())
47
- ->method ('getFileContents ' )
48
- ->with ('/test/composer.lock ' )
49
- ->willReturn ($ json )
50
- ;
29
+ $ mockFileManager = $ this ->mockFileManager (sprintf ('{"platform-overrides": {"php": "%s"}} ' , $ version ));
51
30
52
31
$ version = new PhpCompatUtil ($ mockFileManager );
53
32
@@ -110,28 +89,7 @@ public function testFallBackToPhpVersionWithoutLockFile(): void
110
89
111
90
public function testWithoutPlatformVersionSet (): void
112
91
{
113
- $ json = '{"platform-overrides": {}} ' ;
114
-
115
- $ mockFileManager = $ this ->createMock (FileManager::class);
116
- $ mockFileManager
117
- ->expects (self ::once ())
118
- ->method ('getRootDirectory ' )
119
- ->willReturn ('/test ' )
120
- ;
121
-
122
- $ mockFileManager
123
- ->expects (self ::once ())
124
- ->method ('fileExists ' )
125
- ->with ('/test/composer.lock ' )
126
- ->willReturn (true )
127
- ;
128
-
129
- $ mockFileManager
130
- ->expects (self ::once ())
131
- ->method ('getFileContents ' )
132
- ->with ('/test/composer.lock ' )
133
- ->willReturn ($ json )
134
- ;
92
+ $ mockFileManager = $ this ->mockFileManager ('{"platform-overrides": {}} ' );
135
93
136
94
$ util = new PhpCompatUtilTestFixture ($ mockFileManager );
137
95
@@ -145,8 +103,58 @@ public function testWithoutPlatformVersionSet(): void
145
103
*/
146
104
public function testCanUseTypedProperties (string $ version , bool $ expectedResult ): void
147
105
{
148
- $ json = sprintf ('{"platform-overrides": {"php": "%s"}} ' , $ version );
106
+ $ mockFileManager = $ this ->mockFileManager (sprintf ('{"platform-overrides": {"php": "%s"}} ' , $ version ));
107
+
108
+ $ version = new PhpCompatUtil ($ mockFileManager );
109
+
110
+ $ result = $ version ->canUseTypedProperties ();
111
+
112
+ self ::assertSame ($ expectedResult , $ result );
113
+ }
114
+
115
+ public function phpVersionForTypedPropertiesDataProvider (): \Generator
116
+ {
117
+ yield ['8 ' , true ];
118
+ yield ['8.0.1 ' , true ];
119
+ yield ['8RC1 ' , true ];
120
+ yield ['7.4 ' , true ];
121
+ yield ['7.4.6 ' , true ];
122
+ yield ['7 ' , false ];
123
+ yield ['7.0 ' , false ];
124
+ yield ['5.7 ' , false ];
125
+ }
126
+
127
+ /**
128
+ * @dataProvider phpVersionForUnionTypesDataProvider
129
+ */
130
+ public function testCanUseUnionTypes (string $ version , bool $ expectedResult ): void
131
+ {
132
+ $ mockFileManager = $ this ->mockFileManager (sprintf ('{"platform-overrides": {"php": "%s"}} ' , $ version ));
133
+
134
+ $ version = new PhpCompatUtil ($ mockFileManager );
135
+
136
+ $ result = $ version ->canUseUnionTypes ();
137
+
138
+ self ::assertSame ($ expectedResult , $ result );
139
+ }
140
+
141
+ public function phpVersionForUnionTypesDataProvider (): \Generator
142
+ {
143
+ yield ['8 ' , true ];
144
+ yield ['8.0.1 ' , true ];
145
+ yield ['8RC1 ' , true ];
146
+ yield ['7.4 ' , false ];
147
+ yield ['7.4.6 ' , false ];
148
+ yield ['7 ' , false ];
149
+ yield ['7.0 ' , false ];
150
+ yield ['5.7 ' , false ];
151
+ }
149
152
153
+ /**
154
+ * @return \PHPUnit\Framework\MockObject\MockObject|FileManager
155
+ */
156
+ private function mockFileManager (string $ json )
157
+ {
150
158
$ mockFileManager = $ this ->createMock (FileManager::class);
151
159
$ mockFileManager
152
160
->expects (self ::once ())
@@ -168,23 +176,7 @@ public function testCanUseTypedProperties(string $version, bool $expectedResult)
168
176
->willReturn ($ json )
169
177
;
170
178
171
- $ version = new PhpCompatUtil ($ mockFileManager );
172
-
173
- $ result = $ version ->canUseTypedProperties ();
174
-
175
- self ::assertSame ($ expectedResult , $ result );
176
- }
177
-
178
- public function phpVersionForTypedPropertiesDataProvider (): \Generator
179
- {
180
- yield ['8 ' , true ];
181
- yield ['8.0.1 ' , true ];
182
- yield ['8RC1 ' , true ];
183
- yield ['7.4 ' , true ];
184
- yield ['7.4.6 ' , true ];
185
- yield ['7 ' , false ];
186
- yield ['7.0 ' , false ];
187
- yield ['5.7 ' , false ];
179
+ return $ mockFileManager ;
188
180
}
189
181
}
190
182
0 commit comments