Skip to content

Commit 7972b0c

Browse files
committed
add unit tests for Server::setFlag()
add proper phpunit configuration
1 parent 5e62f87 commit 7972b0c

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

phpunit.xml.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
bootstrap="tests/bootstrap.php"
13+
>
14+
15+
<testsuites>
16+
<testsuite name="Fetch Test Suite">
17+
<directory>./tests</directory>
18+
</testsuite>
19+
</testsuites>
20+
</phpunit>

tests/Fetch/Test/ServerTest.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,47 @@
1111

1212
namespace Fetch\Test;
1313

14+
use Fetch\Server;
1415

1516
/**
1617
* @package Fetch
1718
* @author Robert Hafner <tedivm@tedivm.com>
1819
*/
1920
class ServerTest extends \PHPUnit_Framework_TestCase
2021
{
21-
22+
/**
23+
* @dataProvider flagsDataProvider
24+
* @param string $expected server string with %host% placeholder
25+
* @param integer $port to use (needed to test behavior on port 143 and 993 from constructor)
26+
* @param array $flags to set/unset ($flag => $value)
27+
*/
28+
public function testFlags($expected, $port, $flags)
29+
{
30+
$host = 'example.com';
31+
$server = new Server($host, $port);
32+
33+
foreach ($flags as $flag => $value) {
34+
$server->setFlag($flag, $value);
35+
}
36+
37+
$this->assertEquals(str_replace('%host%', $host, $expected), $server->getServerString());
38+
}
39+
40+
public function flagsDataProvider() {
41+
return array(
42+
array('{%host%:143/novalidate-cert}', 143, array()),
43+
array('{%host%:143/validate-cert}', 143, array('validate-cert' => true)),
44+
array('{%host%:143}', 143, array('novalidate-cert' => false)),
45+
array('{%host%:993/ssl}', 993, array()),
46+
array('{%host%:993}', 993, array('ssl' => false)),
47+
array('{%host%:100/tls}', 100, array('tls' => true)),
48+
array('{%host%:100/tls}', 100, array('tls' => true, 'tls' => true)),
49+
array('{%host%:100/notls}', 100, array('tls' => true, 'notls' => true)),
50+
array('{%host%:100}', 100, array('ssl' => true, 'ssl' => false)),
51+
array('{%host%:100/user=foo}', 100, array('user' => 'foo')),
52+
array('{%host%:100/user=foo}', 100, array('user' => 'foo', 'user' => 'foo')),
53+
array('{%host%:100/user=bar}', 100, array('user' => 'foo', 'user' => 'bar')),
54+
array('{%host%:100}', 100, array('user' => 'foo', 'user' => false)),
55+
);
56+
}
2257
}

0 commit comments

Comments
 (0)