Skip to content

Commit d5f70b2

Browse files
committed
Update tests
1 parent 1702662 commit d5f70b2

File tree

9 files changed

+386
-434
lines changed

9 files changed

+386
-434
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 amphp
3+
Copyright (c) 2016-2019 amphp
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"amphp/sql-common": "^1"
2626
},
2727
"require-dev": {
28-
"amphp/phpunit-util": "^1",
29-
"phpunit/phpunit": "^6",
28+
"amphp/phpunit-util": "^1.1.2",
29+
"phpunit/phpunit": "^7 || ^6",
3030
"amphp/php-cs-fixer-config": "dev-master",
3131
"phpstan/phpstan": "^0.9"
3232
},

phpunit.xml.dist

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,4 @@
2222
<directory suffix=".php">src</directory>
2323
</whitelist>
2424
</filter>
25-
<listeners>
26-
<listener class="Amp\PHPUnit\LoopReset"/>
27-
</listeners>
2825
</phpunit>

test/AbstractConnectTest.php

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
use Amp\CancellationToken;
66
use Amp\CancellationTokenSource;
7-
use Amp\Loop;
7+
use Amp\CancelledException;
8+
use Amp\PHPUnit\AsyncTestCase;
89
use Amp\Postgres\Connection;
910
use Amp\Postgres\ConnectionConfig as PostgresConnectionConfig;
1011
use Amp\Promise;
1112
use Amp\Sql\ConnectionConfig;
13+
use Amp\Sql\FailureException;
1214
use Amp\TimeoutCancellationToken;
13-
use PHPUnit\Framework\TestCase;
1415

15-
abstract class AbstractConnectTest extends TestCase
16+
abstract class AbstractConnectTest extends AsyncTestCase
1617
{
1718
/**
1819
* @param ConnectionConfig $connectionConfig
@@ -22,53 +23,47 @@ abstract class AbstractConnectTest extends TestCase
2223
*/
2324
abstract public function connect(ConnectionConfig $connectionConfig, CancellationToken $token = null): Promise;
2425

25-
public function testConnect()
26+
public function testConnect(): \Generator
2627
{
27-
Loop::run(function () {
28-
$connection = yield $this->connect(
29-
PostgresConnectionConfig::fromString('host=localhost user=postgres'),
30-
new TimeoutCancellationToken(100)
31-
);
32-
$this->assertInstanceOf(Connection::class, $connection);
33-
});
28+
$connection = yield $this->connect(
29+
PostgresConnectionConfig::fromString('host=localhost user=postgres'),
30+
new TimeoutCancellationToken(100)
31+
);
32+
$this->assertInstanceOf(Connection::class, $connection);
3433
}
3534

3635
/**
3736
* @depends testConnect
38-
* @expectedException \Amp\CancelledException
3937
*/
40-
public function testConnectCancellationBeforeConnect()
38+
public function testConnectCancellationBeforeConnect(): Promise
4139
{
42-
Loop::run(function () {
43-
$source = new CancellationTokenSource;
44-
$token = $source->getToken();
45-
$source->cancel();
46-
$connection = yield $this->connect(PostgresConnectionConfig::fromString('host=localhost user=postgres'), $token);
47-
});
40+
$this->expectException(CancelledException::class);
41+
42+
$source = new CancellationTokenSource;
43+
$token = $source->getToken();
44+
$source->cancel();
45+
return $this->connect(PostgresConnectionConfig::fromString('host=localhost user=postgres'), $token);
4846
}
4947

5048
/**
5149
* @depends testConnectCancellationBeforeConnect
5250
*/
53-
public function testConnectCancellationAfterConnect()
51+
public function testConnectCancellationAfterConnect(): \Generator
5452
{
55-
Loop::run(function () {
56-
$source = new CancellationTokenSource;
57-
$token = $source->getToken();
58-
$connection = yield $this->connect(PostgresConnectionConfig::fromString('host=localhost user=postgres'), $token);
59-
$this->assertInstanceOf(Connection::class, $connection);
60-
$source->cancel();
61-
});
53+
$source = new CancellationTokenSource;
54+
$token = $source->getToken();
55+
$connection = yield $this->connect(PostgresConnectionConfig::fromString('host=localhost user=postgres'), $token);
56+
$this->assertInstanceOf(Connection::class, $connection);
57+
$source->cancel();
6258
}
6359

6460
/**
6561
* @depends testConnectCancellationBeforeConnect
66-
* @expectedException \Amp\Sql\FailureException
6762
*/
68-
public function testConnectInvalidUser()
63+
public function testConnectInvalidUser(): Promise
6964
{
70-
Loop::run(function () {
71-
$connection = yield $this->connect(PostgresConnectionConfig::fromString('host=localhost user=invalid'), new TimeoutCancellationToken(100));
72-
});
65+
$this->expectException(FailureException::class);
66+
67+
return $this->connect(PostgresConnectionConfig::fromString('host=localhost user=invalid'), new TimeoutCancellationToken(100));
7368
}
7469
}

0 commit comments

Comments
 (0)