4
4
5
5
use org \bovigo \vfs \vfsStream ;
6
6
use org \bovigo \vfs \vfsStreamDirectory ;
7
- use PHPUnit \Framework \TestCase ;
8
7
use Pdp \HttpAdapter \CurlHttpAdapter ;
9
8
use Pdp \HttpAdapter \HttpAdapterInterface ;
9
+ use PHPUnit \Framework \TestCase ;
10
10
11
11
class PublicSuffixListManagerTest extends TestCase
12
12
{
@@ -46,18 +46,18 @@ class PublicSuffixListManagerTest extends TestCase
46
46
protected $ publicSuffixListUrl = 'https://publicsuffix.org/list/effective_tld_names.dat ' ;
47
47
48
48
/**
49
- * @var \Pdp\HttpAdapter\ HttpAdapterInterface Http adapter
49
+ * @var HttpAdapterInterface|\PHPUnit_Framework_MockObject_MockObject Http adapter
50
50
*/
51
51
protected $ httpAdapter ;
52
52
53
53
protected function setUp ()
54
54
{
55
55
parent ::setUp ();
56
56
57
- $ this ->dataDir = realpath ( dirname (__DIR__ ) . '/../../ data ' ) ;
57
+ $ this ->dataDir = dirname (__DIR__ , 3 ) . '/data ' ;
58
58
59
59
$ this ->root = vfsStream::setup ('pdp ' );
60
- vfsStream::create (array ( 'cache ' => array ()) , $ this ->root );
60
+ vfsStream::create ([ 'cache ' => []] , $ this ->root );
61
61
$ this ->cacheDir = vfsStream::url ('pdp/cache ' );
62
62
63
63
$ this ->listManager = new PublicSuffixListManager ($ this ->cacheDir );
@@ -134,22 +134,14 @@ public function testWritePhpCache()
134
134
$ this ->dataDir . '/ ' . PublicSuffixListManager::PDP_PSL_TEXT_FILE
135
135
);
136
136
$ this ->assertGreaterThanOrEqual (230000 , $ this ->listManager ->writePhpCache ($ array ));
137
- $ this ->assertFileExists (
138
- $ this ->cacheDir . '/ ' . PublicSuffixListManager::PDP_PSL_PHP_FILE
139
- );
140
- $ publicSuffixList = include $ this ->cacheDir . '/ ' . PublicSuffixListManager::PDP_PSL_PHP_FILE ;
141
- $ this ->assertInternalType ('array ' , $ publicSuffixList );
142
- $ this ->assertGreaterThanOrEqual (300 , count ($ publicSuffixList ));
143
- $ this ->assertTrue (array_key_exists ('stuff-4-sale ' , $ publicSuffixList ['org ' ]) !== false );
144
- $ this ->assertTrue (array_key_exists ('net ' , $ publicSuffixList ['ac ' ]) !== false );
145
137
}
146
138
147
139
public function testWriteThrowsExceptionIfCanNotWrite ()
148
140
{
149
141
$ this ->expectException (\Exception::class);
150
142
$ this ->expectExceptionMessage ("Cannot write '/does/not/exist/public-suffix-list.php' " );
151
143
$ manager = new PublicSuffixListManager ('/does/not/exist ' );
152
- $ manager ->writePhpCache (array () );
144
+ $ manager ->writePhpCache ([] );
153
145
}
154
146
155
147
public function testParseListToArray ()
@@ -172,8 +164,8 @@ public function testGetList()
172
164
$ publicSuffixList = $ this ->listManager ->getList ();
173
165
$ this ->assertInstanceOf (PublicSuffixList::class, $ publicSuffixList );
174
166
$ this ->assertGreaterThanOrEqual (300 , count ($ publicSuffixList ->getRules ()));
175
- $ this ->assertTrue ( array_key_exists ( 'stuff-4-sale ' , $ publicSuffixList ->getRules ()['org ' ]) !== false );
176
- $ this ->assertTrue ( array_key_exists ( 'net ' , $ publicSuffixList ->getRules ()['ac ' ]) !== false );
167
+ $ this ->assertArrayHasKey ( 'stuff-4-sale ' , $ publicSuffixList ->getRules ()['org ' ]);
168
+ $ this ->assertArrayHasKey ( 'net ' , $ publicSuffixList ->getRules ()['ac ' ]);
177
169
}
178
170
179
171
public function testGetListWithoutCache ()
@@ -182,7 +174,7 @@ public function testGetListWithoutCache()
182
174
$ this ->cacheDir . '/ ' . PublicSuffixListManager::PDP_PSL_PHP_FILE
183
175
);
184
176
185
- /** @var PublicSuffixListManager $listManager */
177
+ /** @var PublicSuffixListManager|\PHPUnit_Framework_MockObject_MockObject $listManager */
186
178
$ listManager = $ this ->getMockBuilder (PublicSuffixListManager::class)
187
179
->setConstructorArgs ([$ this ->cacheDir ])
188
180
->setMethods (['refreshPublicSuffixList ' ])
@@ -209,10 +201,7 @@ public function testGetProvidedListFromDefaultCacheDir()
209
201
// By not providing cache I'm forcing use of default cache dir
210
202
$ listManager = new PublicSuffixListManager ();
211
203
$ publicSuffixList = $ listManager ->getList ();
212
- $ this ->assertInstanceOf (PublicSuffixList::class, $ publicSuffixList );
213
- $ this ->assertGreaterThanOrEqual (300 , count ($ publicSuffixList ->getRules ()));
214
- $ this ->assertTrue (array_key_exists ('stuff-4-sale ' , $ publicSuffixList ->getRules ()['org ' ]) !== false );
215
- $ this ->assertTrue (array_key_exists ('net ' , $ publicSuffixList ->getRules ()['ac ' ]) !== false );
204
+ $ this ->assertGreaterThanOrEqual (300 , count ($ publicSuffixList ));
216
205
}
217
206
218
207
private function getMock (string $ class )
0 commit comments