4
4
5
5
use org \bovigo \vfs \vfsStream ;
6
6
use org \bovigo \vfs \vfsStreamDirectory ;
7
+ use PHPUnit \Framework \TestCase ;
7
8
8
- class PublicSuffixListManagerTest extends \PHPUnit_Framework_TestCase
9
+ class PublicSuffixListManagerTest extends TestCase
9
10
{
10
11
/**
11
12
* @var PublicSuffixListManager List manager
@@ -146,7 +147,8 @@ public function testWritePhpCache()
146
147
147
148
public function testWriteThrowsExceptionIfCanNotWrite ()
148
149
{
149
- $ this ->setExpectedException ('\Exception ' , "Cannot write '/does/not/exist/public-suffix-list.php' " );
150
+ $ this ->expectException (\Exception::class);
151
+ $ this ->expectExceptionMessage ("Cannot write '/does/not/exist/public-suffix-list.php' " );
150
152
$ manager = new PublicSuffixListManager ('/does/not/exist ' );
151
153
$ manager ->writePhpCache (array ());
152
154
}
@@ -169,10 +171,10 @@ public function testGetList()
169
171
$ this ->cacheDir . '/ ' . PublicSuffixListManager::PDP_PSL_PHP_FILE
170
172
);
171
173
$ publicSuffixList = $ this ->listManager ->getList ();
172
- $ this ->assertInstanceOf (' \Pdp\ PublicSuffixList' , $ publicSuffixList );
174
+ $ this ->assertInstanceOf (PublicSuffixList::class , $ publicSuffixList );
173
175
$ this ->assertGreaterThanOrEqual (300 , count ($ publicSuffixList ));
174
- $ this ->assertTrue (array_key_exists ('stuff-4-sale ' , $ publicSuffixList ['org ' ]) !== false );
175
- $ this ->assertTrue (array_key_exists ('net ' , $ publicSuffixList ['ac ' ]) !== false );
176
+ $ this ->assertTrue (array_key_exists ('stuff-4-sale ' , $ publicSuffixList-> getRules () ['org ' ]) !== false );
177
+ $ this ->assertTrue (array_key_exists ('net ' , $ publicSuffixList-> getRules () ['ac ' ]) !== false );
176
178
}
177
179
178
180
public function testGetListWithoutCache ()
@@ -182,11 +184,10 @@ public function testGetListWithoutCache()
182
184
);
183
185
184
186
/** @var PublicSuffixListManager $listManager */
185
- $ listManager = $ this ->getMock (
186
- '\Pdp\PublicSuffixListManager ' ,
187
- array ('refreshPublicSuffixList ' ),
188
- array ($ this ->cacheDir )
189
- );
187
+ $ listManager = $ this ->getMockBuilder (PublicSuffixListManager::class)
188
+ ->setConstructorArgs ([$ this ->cacheDir ])
189
+ ->setMethods (['refreshPublicSuffixList ' ])
190
+ ->getMock ();
190
191
191
192
$ dataDir = $ this ->dataDir ;
192
193
$ cacheDir = $ this ->cacheDir ;
@@ -201,17 +202,24 @@ public function testGetListWithoutCache()
201
202
}));
202
203
203
204
$ publicSuffixList = $ listManager ->getList ();
204
- $ this ->assertInstanceOf (' \Pdp\ PublicSuffixList' , $ publicSuffixList );
205
+ $ this ->assertInstanceOf (PublicSuffixList::class , $ publicSuffixList );
205
206
}
206
207
207
208
public function testGetProvidedListFromDefaultCacheDir ()
208
209
{
209
210
// By not providing cache I'm forcing use of default cache dir
210
211
$ listManager = new PublicSuffixListManager ();
211
212
$ publicSuffixList = $ listManager ->getList ();
212
- $ this ->assertInstanceOf (' \Pdp\ PublicSuffixList' , $ publicSuffixList );
213
+ $ this ->assertInstanceOf (PublicSuffixList::class , $ publicSuffixList );
213
214
$ this ->assertGreaterThanOrEqual (300 , count ($ publicSuffixList ));
214
- $ this ->assertTrue (array_key_exists ('stuff-4-sale ' , $ publicSuffixList ['org ' ]) !== false );
215
- $ this ->assertTrue (array_key_exists ('net ' , $ publicSuffixList ['ac ' ]) !== false );
215
+ $ this ->assertTrue (array_key_exists ('stuff-4-sale ' , $ publicSuffixList ->getRules ()['org ' ]) !== false );
216
+ $ this ->assertTrue (array_key_exists ('net ' , $ publicSuffixList ->getRules ()['ac ' ]) !== false );
217
+ }
218
+
219
+ private function getMock (string $ class )
220
+ {
221
+ return $ this ->getMockBuilder ($ class )
222
+ ->disableOriginalConstructor ()
223
+ ->getMock ();
216
224
}
217
225
}
0 commit comments