Skip to content

Commit 18a67e0

Browse files
committed
Update tests for PHPUnit 6
1 parent 3d96751 commit 18a67e0

File tree

4 files changed

+38
-32
lines changed

4 files changed

+38
-32
lines changed

tests/src/Pdp/CheckPublicSuffixTest.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,25 @@
22

33
namespace Pdp;
44

5+
use PHPUnit\Framework\TestCase;
6+
57
/**
68
* This test case is based on the test data linked at
79
* http://publicsuffix.org/list/ and provided by Rob Strading of Comodo.
810
*
911
* @link
1012
* http://mxr.mozilla.org/mozilla-central/source/netwerk/test/unit/data/test_psl.txt?raw=1
1113
*/
12-
class CheckPublicSuffixTest extends \PHPUnit_Framework_TestCase
14+
class CheckPublicSuffixTest extends TestCase
1315
{
1416
/**
15-
* @var Parser
17+
* @var PublicSuffixList
1618
*/
17-
protected $parser;
19+
private $list;
1820

1921
protected function setUp()
2022
{
21-
$file = realpath(dirname(__DIR__) . '/../../data/public-suffix-list.php');
22-
$this->parser = new Parser(new PublicSuffixList($file));
23-
}
24-
25-
protected function tearDown()
26-
{
27-
$this->parser = null;
23+
$this->list = new PublicSuffixList();
2824
}
2925

3026
public function testPublicSuffixSpec()
@@ -142,6 +138,6 @@ public function testPublicSuffixSpec()
142138
*/
143139
public function checkPublicSuffix($input, $expected)
144140
{
145-
$this->assertSame($expected, $this->parser->getRegistrableDomain($input));
141+
$this->assertSame($expected, $this->list->query($input)->getRegistrableDomain());
146142
}
147143
}

tests/src/Pdp/Exception/SeriouslyMalformedUrlExceptionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
namespace Pdp\Exception;
44

5-
class SeriouslyMalformedUrlExceptionTest extends \PHPUnit_Framework_TestCase
5+
use PHPUnit\Framework\TestCase;
6+
7+
class SeriouslyMalformedUrlExceptionTest extends TestCase
68
{
79
public function testInstanceOfPdpException()
810
{
911
$this->assertInstanceOf(
10-
'Pdp\Exception\PdpException',
12+
PdpException::class,
1113
new SeriouslyMalformedUrlException()
1214
);
1315
}
@@ -23,10 +25,8 @@ public function testInstanceOfInvalidArgumentException()
2325
public function testMessage()
2426
{
2527
$url = 'http:///example.com';
26-
$this->setExpectedException(
27-
'Pdp\Exception\SeriouslyMalformedUrlException',
28-
sprintf('"%s" is one seriously malformed url.', $url)
29-
);
28+
$this->expectException(SeriouslyMalformedUrlException::class);
29+
$this->expectExceptionMessage(sprintf('"%s" is one seriously malformed url.', $url));
3030

3131
throw new SeriouslyMalformedUrlException($url);
3232
}

tests/src/Pdp/HttpAdapter/CurlHttpAdapterTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Pdp\HttpAdapter;
44

5+
use PHPUnit\Framework\TestCase;
6+
57
/**
68
* @group internet
79
*/
8-
class CurlHttpAdapterTest extends \PHPUnit_Framework_TestCase
10+
class CurlHttpAdapterTest extends TestCase
911
{
1012
/**
1113
* @var HttpAdapterInterface

tests/src/Pdp/PublicSuffixListManagerTest.php

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
use org\bovigo\vfs\vfsStream;
66
use org\bovigo\vfs\vfsStreamDirectory;
7+
use PHPUnit\Framework\TestCase;
78

8-
class PublicSuffixListManagerTest extends \PHPUnit_Framework_TestCase
9+
class PublicSuffixListManagerTest extends TestCase
910
{
1011
/**
1112
* @var PublicSuffixListManager List manager
@@ -146,7 +147,8 @@ public function testWritePhpCache()
146147

147148
public function testWriteThrowsExceptionIfCanNotWrite()
148149
{
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'");
150152
$manager = new PublicSuffixListManager('/does/not/exist');
151153
$manager->writePhpCache(array());
152154
}
@@ -169,10 +171,10 @@ public function testGetList()
169171
$this->cacheDir . '/' . PublicSuffixListManager::PDP_PSL_PHP_FILE
170172
);
171173
$publicSuffixList = $this->listManager->getList();
172-
$this->assertInstanceOf('\Pdp\PublicSuffixList', $publicSuffixList);
174+
$this->assertInstanceOf(PublicSuffixList::class, $publicSuffixList);
173175
$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);
176178
}
177179

178180
public function testGetListWithoutCache()
@@ -182,11 +184,10 @@ public function testGetListWithoutCache()
182184
);
183185

184186
/** @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();
190191

191192
$dataDir = $this->dataDir;
192193
$cacheDir = $this->cacheDir;
@@ -201,17 +202,24 @@ public function testGetListWithoutCache()
201202
}));
202203

203204
$publicSuffixList = $listManager->getList();
204-
$this->assertInstanceOf('\Pdp\PublicSuffixList', $publicSuffixList);
205+
$this->assertInstanceOf(PublicSuffixList::class, $publicSuffixList);
205206
}
206207

207208
public function testGetProvidedListFromDefaultCacheDir()
208209
{
209210
// By not providing cache I'm forcing use of default cache dir
210211
$listManager = new PublicSuffixListManager();
211212
$publicSuffixList = $listManager->getList();
212-
$this->assertInstanceOf('\Pdp\PublicSuffixList', $publicSuffixList);
213+
$this->assertInstanceOf(PublicSuffixList::class, $publicSuffixList);
213214
$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();
216224
}
217225
}

0 commit comments

Comments
 (0)