Skip to content

Commit

Permalink
Merge pull request #68 from clue-labs/phpunit
Browse files Browse the repository at this point in the history
Forward compatibility with PHPUnit 6
  • Loading branch information
clue authored Dec 12, 2017
2 parents 4ebbec5 + 97a84e0 commit b10a886
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"evenement/evenement": "~3.0|~1.0|~2.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0 || ^4.8",
"phpunit/phpunit": "^6.0 || ^5.7 || ^4.8.35",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"clue/connection-manager-extra": "^1.0 || ^0.7",
"clue/block-react": "^1.1"
Expand Down
10 changes: 10 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ public function setUp()
public function testCtorAcceptsUriWithHostAndPort()
{
$client = new Client('127.0.0.1:9050', $this->connector);

$this->assertTrue(true);
}

public function testCtorAcceptsUriWithScheme()
{
$client = new Client('socks://127.0.0.1:9050', $this->connector);

$this->assertTrue(true);
}

public function testCtorAcceptsUriWithHostOnlyAssumesDefaultPort()
{
$client = new Client('127.0.0.1', $this->connector);

$this->assertTrue(true);
}

/**
Expand All @@ -46,6 +52,8 @@ public function testCtorThrowsForInvalidUri()
public function testValidAuthFromUri()
{
$this->client = new Client('username:[email protected]', $this->connector);

$this->assertTrue(true);
}

/**
Expand All @@ -59,6 +67,8 @@ public function testInvalidAuthInformation()
public function testValidAuthAndVersionFromUri()
{
$this->client = new Client('socks5://username:[email protected]:9050', $this->connector);

$this->assertTrue(true);
}

/**
Expand Down
22 changes: 16 additions & 6 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ public function testConnectionInvalidProtocolDoesNotMatchSocks5()
$this->server->setProtocolVersion(5);
$this->client = new Client('socks4a://127.0.0.1:' . $this->port, $this->connector);

$this->assertRejectPromise($this->client->connect('www.google.com:80'), '', SOCKET_ECONNRESET);
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_ECONNRESET);
}

public function testConnectionInvalidProtocolDoesNotMatchSocks4()
{
$this->server->setProtocolVersion(4);
$this->client = new Client('socks5://127.0.0.1:' . $this->port, $this->connector);

$this->assertRejectPromise($this->client->connect('www.google.com:80'), '', SOCKET_ECONNRESET);
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_ECONNRESET);
}

public function testConnectionInvalidNoAuthentication()
Expand All @@ -198,7 +198,7 @@ public function testConnectionInvalidNoAuthentication()

$this->client = new Client('socks5://127.0.0.1:' . $this->port, $this->connector);

$this->assertRejectPromise($this->client->connect('www.google.com:80'), '', SOCKET_EACCES);
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
}

public function testConnectionInvalidAuthenticationMismatch()
Expand All @@ -207,7 +207,7 @@ public function testConnectionInvalidAuthenticationMismatch()

$this->client = new Client('user:[email protected]:' . $this->port, $this->connector);

$this->assertRejectPromise($this->client->connect('www.google.com:80'), '', SOCKET_EACCES);
$this->assertRejectPromise($this->client->connect('www.google.com:80'), null, SOCKET_EACCES);
}

/** @group internet */
Expand Down Expand Up @@ -310,11 +310,21 @@ private function assertResolveStream($promise)
Block\await($promise, $this->loop, 2.0);
}

private function assertRejectPromise($promise, $message = '', $code = null)
private function assertRejectPromise($promise, $message = null, $code = null)
{
$this->expectPromiseReject($promise);

$this->setExpectedException('Exception', $message, $code);
if (method_exists($this, 'expectException')) {
$this->expectException('Exception');
if ($message !== null) {
$this->expectExceptionMessage($message);
}
if ($code !== null) {
$this->expectExceptionCode($code);
}
} else {
$this->setExpectedException('Exception', $message, $code);
}

Block\await($promise, $this->loop, 2.0);
}
Expand Down
6 changes: 6 additions & 0 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public function testSetProtocolVersion()
$this->server->setProtocolVersion('4a');
$this->server->setProtocolVersion(5);
$this->server->setProtocolVersion(null);

$this->assertTrue(true);
}

/**
Expand All @@ -48,6 +50,8 @@ public function testSetAuthArray()
'name1' => 'password1',
'name2' => 'password2'
));

$this->assertTrue(true);
}

/**
Expand Down Expand Up @@ -390,5 +394,7 @@ public function testUnsetAuth()
{
$this->server->unsetAuth();
$this->server->unsetAuth();

$this->assertTrue(true);
}
}
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(include_once __DIR__.'/../vendor/autoload.php') OR die(PHP_EOL.'ERROR: composer autoloader not found, run "composer install" or see README for instructions'.PHP_EOL);

class TestCase extends PHPUnit_Framework_TestCase
class TestCase extends PHPUnit\Framework\TestCase
{
protected function expectCallableOnce()
{
Expand Down

0 comments on commit b10a886

Please sign in to comment.