mirror of
https://github.com/danog/dns.git
synced 2024-11-26 20:14:51 +01:00
Update to PHPUnit 6, update code style
This commit is contained in:
parent
38250dddad
commit
cbac861746
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ build
|
|||||||
composer.lock
|
composer.lock
|
||||||
phpunit.xml
|
phpunit.xml
|
||||||
vendor
|
vendor
|
||||||
|
.php_cs.cache
|
||||||
|
15
.php_cs
15
.php_cs
@ -1,15 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
return Symfony\CS\Config\Config::create()
|
|
||||||
->level(Symfony\CS\FixerInterface::NONE_LEVEL)
|
|
||||||
->fixers([
|
|
||||||
"psr2",
|
|
||||||
"-braces",
|
|
||||||
"-psr0",
|
|
||||||
])
|
|
||||||
->finder(
|
|
||||||
Symfony\CS\Finder\DefaultFinder::create()
|
|
||||||
->in(__DIR__ . "/lib")
|
|
||||||
->in(__DIR__ . "/test")
|
|
||||||
)
|
|
||||||
;
|
|
39
.php_cs.dist
Normal file
39
.php_cs.dist
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return PhpCsFixer\Config::create()
|
||||||
|
->setRiskyAllowed(true)
|
||||||
|
->setRules([
|
||||||
|
"@PSR1" => true,
|
||||||
|
"@PSR2" => true,
|
||||||
|
"braces" => [
|
||||||
|
"allow_single_line_closure" => true,
|
||||||
|
"position_after_functions_and_oop_constructs" => "same",
|
||||||
|
],
|
||||||
|
"array_syntax" => ["syntax" => "short"],
|
||||||
|
"cast_spaces" => true,
|
||||||
|
"combine_consecutive_unsets" => true,
|
||||||
|
"function_to_constant" => true,
|
||||||
|
"no_multiline_whitespace_before_semicolons" => true,
|
||||||
|
"no_unused_imports" => true,
|
||||||
|
"no_useless_else" => true,
|
||||||
|
"no_useless_return" => true,
|
||||||
|
"no_whitespace_before_comma_in_array" => true,
|
||||||
|
"no_whitespace_in_blank_line" => true,
|
||||||
|
"non_printable_character" => true,
|
||||||
|
"normalize_index_brace" => true,
|
||||||
|
"ordered_imports" => true,
|
||||||
|
"php_unit_construct" => true,
|
||||||
|
"php_unit_dedicate_assert" => true,
|
||||||
|
"php_unit_fqcn_annotation" => true,
|
||||||
|
"phpdoc_summary" => true,
|
||||||
|
"phpdoc_types" => true,
|
||||||
|
"psr4" => true,
|
||||||
|
"return_type_declaration" => ["space_before" => "none"],
|
||||||
|
"short_scalar_cast" => true,
|
||||||
|
"single_blank_line_before_namespace" => true,
|
||||||
|
])
|
||||||
|
->setFinder(
|
||||||
|
PhpCsFixer\Finder::create()
|
||||||
|
->in(__DIR__ . "/lib")
|
||||||
|
->in(__DIR__ . "/test")
|
||||||
|
);
|
24
.travis.yml
24
.travis.yml
@ -12,26 +12,18 @@ matrix:
|
|||||||
- php: nightly
|
- php: nightly
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
|
||||||
env:
|
before_script:
|
||||||
- DEPS=lowest
|
# --ignore-platform-reqs, because https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/2722
|
||||||
- DEPS=highest
|
- composer update -n --prefer-dist --ignore-platform-reqs
|
||||||
|
- composer require satooshi/php-coveralls dev-master --ignore-platform-reqs
|
||||||
install:
|
|
||||||
- if [ "$DEPS" = "lowest" ]; then
|
|
||||||
composer update -n --prefer-source --prefer-lowest;
|
|
||||||
else
|
|
||||||
composer update -n --prefer-source;
|
|
||||||
fi;
|
|
||||||
- composer show
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml
|
- phpdbg -qrr vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml
|
||||||
- php vendor/bin/php-cs-fixer --diff --dry-run -v fix
|
- PHP_CS_FIXER_IGNORE_ENV=1 php vendor/bin/php-cs-fixer --diff --dry-run -v fix
|
||||||
|
|
||||||
after_success:
|
after_script:
|
||||||
- composer require satooshi/php-coveralls dev-master
|
- php vendor/bin/coveralls -v
|
||||||
- travis_retry php vendor/bin/coveralls -v
|
|
||||||
|
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- $HOME/.composer/cache
|
- $HOME/.composer/cache/files
|
||||||
|
45
Makefile
Normal file
45
Makefile
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
PHP_BIN := php
|
||||||
|
COMPOSER_BIN := composer
|
||||||
|
|
||||||
|
COVERAGE = coverage
|
||||||
|
SRCS = lib test
|
||||||
|
|
||||||
|
find_php_files = $(shell find $(1) -type f -name "*.php")
|
||||||
|
src = $(foreach d,$(SRCS),$(call find_php_files,$(d)))
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
test: setup phpunit code-style
|
||||||
|
|
||||||
|
.PHONY: clean
|
||||||
|
clean: clean-coverage clean-vendor
|
||||||
|
|
||||||
|
.PHONY: clean-coverage
|
||||||
|
clean-coverage:
|
||||||
|
test ! -e coverage || rm -r coverage
|
||||||
|
|
||||||
|
.PHONY: clean-vendor
|
||||||
|
clean-vendor:
|
||||||
|
test ! -e vendor || rm -r vendor
|
||||||
|
|
||||||
|
.PHONY: setup
|
||||||
|
setup: vendor/autoload.php
|
||||||
|
|
||||||
|
.PHONY: deps-update
|
||||||
|
deps-update:
|
||||||
|
$(COMPOSER_BIN) update
|
||||||
|
|
||||||
|
.PHONY: phpunit
|
||||||
|
phpunit: setup
|
||||||
|
$(PHP_BIN) vendor/bin/phpunit
|
||||||
|
|
||||||
|
.PHONY: code-style
|
||||||
|
code-style: setup
|
||||||
|
PHP_CS_FIXER_IGNORE_ENV=1 $(PHP_BIN) vendor/bin/php-cs-fixer --diff -v fix
|
||||||
|
|
||||||
|
composer.lock: composer.json
|
||||||
|
$(COMPOSER_BIN) install
|
||||||
|
touch $@
|
||||||
|
|
||||||
|
vendor/autoload.php: composer.lock
|
||||||
|
$(COMPOSER_BIN) install
|
||||||
|
touch $@
|
13
appveyor.yml
13
appveyor.yml
@ -5,14 +5,8 @@ clone_folder: c:\projects\php-project-workspace
|
|||||||
|
|
||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
- dependencies: lowest
|
- php_ver_target: 7.0
|
||||||
php_ver_target: 7.0
|
- php_ver_target: 7.1
|
||||||
- dependencies: lowest
|
|
||||||
php_ver_target: 7.1
|
|
||||||
- dependencies: highest
|
|
||||||
php_ver_target: 7.0
|
|
||||||
- dependencies: highest
|
|
||||||
php_ver_target: 7.1
|
|
||||||
|
|
||||||
## Cache composer bits
|
## Cache composer bits
|
||||||
cache:
|
cache:
|
||||||
@ -39,8 +33,7 @@ install:
|
|||||||
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
|
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
|
||||||
- appveyor DownloadFile https://getcomposer.org/composer.phar
|
- appveyor DownloadFile https://getcomposer.org/composer.phar
|
||||||
- cd c:\projects\php-project-workspace
|
- cd c:\projects\php-project-workspace
|
||||||
- IF %dependencies%==lowest appveyor-retry composer update --prefer-lowest --no-progress --profile -n
|
- appveyor-retry composer update --no-progress -n
|
||||||
- IF %dependencies%==highest appveyor-retry composer update --no-progress --profile -n
|
|
||||||
- composer show
|
- composer show
|
||||||
|
|
||||||
## Run the actual test
|
## Run the actual test
|
||||||
|
@ -1,13 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "amphp/dns",
|
"name": "amphp/dns",
|
||||||
"homepage": "https://github.com/amphp/dns",
|
"homepage": "https://github.com/amphp/dns",
|
||||||
"description": "Async DNS resolution built on the amp concurrency framework",
|
"description": "Async DNS resolution for Amp.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"dns",
|
"dns",
|
||||||
"resolve",
|
"resolve",
|
||||||
"client",
|
"client",
|
||||||
"async",
|
"async",
|
||||||
"amp"
|
"amp",
|
||||||
|
"amphp"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"authors": [
|
"authors": [
|
||||||
@ -39,8 +40,9 @@
|
|||||||
"minimum-stability": "dev",
|
"minimum-stability": "dev",
|
||||||
"prefer-stable": true,
|
"prefer-stable": true,
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^5.2.8",
|
"amphp/phpunit-util": "^1",
|
||||||
"friendsofphp/php-cs-fixer": "^1.9"
|
"phpunit/phpunit": "^6",
|
||||||
|
"friendsofphp/php-cs-fixer": "^2.3"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
@ -2,12 +2,22 @@
|
|||||||
|
|
||||||
namespace Amp\Dns;
|
namespace Amp\Dns;
|
||||||
|
|
||||||
use Amp\{ CallableMaker, Deferred, Failure, Loop, MultiReasonException, Promise, Success, TimeoutException, function call };
|
|
||||||
use Amp\Cache\ArrayCache;
|
use Amp\Cache\ArrayCache;
|
||||||
|
use Amp\CallableMaker;
|
||||||
|
use Amp\Deferred;
|
||||||
|
use Amp\Failure;
|
||||||
use Amp\File\FilesystemException;
|
use Amp\File\FilesystemException;
|
||||||
use Amp\WindowsRegistry\{ KeyNotFoundException, WindowsRegistry };
|
use Amp\Loop;
|
||||||
use LibDNS\{ Decoder\DecoderFactory, Encoder\EncoderFactory };
|
use Amp\MultiReasonException;
|
||||||
use LibDNS\Messages\{ MessageFactory, MessageTypes };
|
use Amp\Promise;
|
||||||
|
use Amp\Success;
|
||||||
|
use Amp\TimeoutException;
|
||||||
|
use Amp\WindowsRegistry\KeyNotFoundException;
|
||||||
|
use Amp\WindowsRegistry\WindowsRegistry;
|
||||||
|
use LibDNS\Decoder\DecoderFactory;
|
||||||
|
use LibDNS\Encoder\EncoderFactory;
|
||||||
|
use LibDNS\Messages\MessageFactory;
|
||||||
|
use LibDNS\Messages\MessageTypes;
|
||||||
use LibDNS\Records\QuestionFactory;
|
use LibDNS\Records\QuestionFactory;
|
||||||
|
|
||||||
class DefaultResolver implements Resolver {
|
class DefaultResolver implements Resolver {
|
||||||
@ -243,9 +253,8 @@ class DefaultResolver implements Resolver {
|
|||||||
if (empty($types)) {
|
if (empty($types)) {
|
||||||
if (empty(array_filter($result))) {
|
if (empty(array_filter($result))) {
|
||||||
throw new NoRecordException("No records returned for {$name} (cached result)");
|
throw new NoRecordException("No records returned for {$name} (cached result)");
|
||||||
} else {
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +276,7 @@ class DefaultResolver implements Resolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
list( , $resultArr) = yield Promise\timeout(Promise\some($promises), $timeout);
|
list(, $resultArr) = yield Promise\timeout(Promise\some($promises), $timeout);
|
||||||
foreach ($resultArr as $value) {
|
foreach ($resultArr as $value) {
|
||||||
$result += $value;
|
$result += $value;
|
||||||
}
|
}
|
||||||
@ -276,10 +285,9 @@ class DefaultResolver implements Resolver {
|
|||||||
throw new TimeoutException(
|
throw new TimeoutException(
|
||||||
"Name resolution timed out for {$name}"
|
"Name resolution timed out for {$name}"
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
$options["server"] = \preg_replace("#[a-z.]+://#", "tcp://", $uri);
|
|
||||||
return yield from $this->doResolve($name, $types, $options);
|
|
||||||
}
|
}
|
||||||
|
$options["server"] = \preg_replace("#[a-z.]+://#", "tcp://", $uri);
|
||||||
|
return yield from $this->doResolve($name, $types, $options);
|
||||||
} catch (ResolutionException $e) {
|
} catch (ResolutionException $e) {
|
||||||
if (empty($result)) { // if we have no cached results
|
if (empty($result)) { // if we have no cached results
|
||||||
throw $e;
|
throw $e;
|
||||||
@ -365,7 +373,8 @@ class DefaultResolver implements Resolver {
|
|||||||
while ($nameserver === "" && ($key = \array_shift($keys))) {
|
while ($nameserver === "" && ($key = \array_shift($keys))) {
|
||||||
try {
|
try {
|
||||||
$nameserver = yield $reader->read($key);
|
$nameserver = yield $reader->read($key);
|
||||||
} catch (KeyNotFoundException $e) { }
|
} catch (KeyNotFoundException $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($nameserver === "") {
|
if ($nameserver === "") {
|
||||||
@ -379,7 +388,8 @@ class DefaultResolver implements Resolver {
|
|||||||
if ($nameserver !== "") {
|
if ($nameserver !== "") {
|
||||||
break 2;
|
break 2;
|
||||||
}
|
}
|
||||||
} catch (KeyNotFoundException $e) { }
|
} catch (KeyNotFoundException $e) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -514,13 +524,13 @@ class DefaultResolver implements Resolver {
|
|||||||
if (\substr($uri, 0, 6) == "tcp://") {
|
if (\substr($uri, 0, 6) == "tcp://") {
|
||||||
$deferred = new Deferred;
|
$deferred = new Deferred;
|
||||||
$server->connect = $deferred->promise();
|
$server->connect = $deferred->promise();
|
||||||
$watcher = Loop::onWritable($server->socket, static function($watcher) use ($server, $deferred, &$timer) {
|
$watcher = Loop::onWritable($server->socket, static function ($watcher) use ($server, $deferred, &$timer) {
|
||||||
Loop::cancel($watcher);
|
Loop::cancel($watcher);
|
||||||
Loop::cancel($timer);
|
Loop::cancel($timer);
|
||||||
unset($server->connect);
|
unset($server->connect);
|
||||||
$deferred->resolve();
|
$deferred->resolve();
|
||||||
});
|
});
|
||||||
$timer = Loop::delay(5000, function() use ($id, $deferred, $watcher, $uri) {
|
$timer = Loop::delay(5000, function () use ($id, $deferred, $watcher, $uri) {
|
||||||
Loop::cancel($watcher);
|
Loop::cancel($watcher);
|
||||||
$this->unloadServer($id);
|
$this->unloadServer($id);
|
||||||
$deferred->fail(new TimeoutException("Name resolution timed out, could not connect to server at $uri"));
|
$deferred->fail(new TimeoutException("Name resolution timed out, could not connect to server at $uri"));
|
||||||
@ -660,7 +670,7 @@ class DefaultResolver implements Resolver {
|
|||||||
} else {
|
} else {
|
||||||
foreach ($result as $type => $records) {
|
foreach ($result as $type => $records) {
|
||||||
$minttl = \PHP_INT_MAX;
|
$minttl = \PHP_INT_MAX;
|
||||||
foreach ($records as list( , , $ttl)) {
|
foreach ($records as list(, , $ttl)) {
|
||||||
if ($ttl < $minttl) {
|
if ($ttl < $minttl) {
|
||||||
$minttl = $ttl;
|
$minttl = $ttl;
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
|
|
||||||
namespace Amp\Dns;
|
namespace Amp\Dns;
|
||||||
|
|
||||||
class NoRecordException extends ResolutionException {}
|
class NoRecordException extends ResolutionException {
|
||||||
|
}
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
|
|
||||||
namespace Amp\Dns;
|
namespace Amp\Dns;
|
||||||
|
|
||||||
class Record extends \LibDNS\Records\ResourceQTypes {}
|
class Record extends \LibDNS\Records\ResourceQTypes {
|
||||||
|
}
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
|
|
||||||
namespace Amp\Dns;
|
namespace Amp\Dns;
|
||||||
|
|
||||||
class ResolutionException extends \Exception {}
|
class ResolutionException extends \Exception {
|
||||||
|
}
|
||||||
|
@ -14,4 +14,4 @@ interface Resolver {
|
|||||||
* @see \Amp\Dns\query
|
* @see \Amp\Dns\query
|
||||||
*/
|
*/
|
||||||
public function query(string $name, $type, array $options = []): Promise;
|
public function query(string $name, $type, array $options = []): Promise;
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,5 @@
|
|||||||
|
|
||||||
namespace Amp\Dns;
|
namespace Amp\Dns;
|
||||||
|
|
||||||
class TimeoutException extends ResolutionException {}
|
class TimeoutException extends ResolutionException {
|
||||||
|
}
|
||||||
|
@ -8,7 +8,7 @@ use Amp\Promise;
|
|||||||
const LOOP_STATE_IDENTIFIER = Resolver::class;
|
const LOOP_STATE_IDENTIFIER = Resolver::class;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the application-wide dns resolver instance
|
* Retrieve the application-wide dns resolver instance.
|
||||||
*
|
*
|
||||||
* @param \Amp\Dns\Resolver $resolver Optionally specify a new default dns resolver instance
|
* @param \Amp\Dns\Resolver $resolver Optionally specify a new default dns resolver instance
|
||||||
* @return \Amp\Dns\Resolver Returns the application-wide dns resolver instance
|
* @return \Amp\Dns\Resolver Returns the application-wide dns resolver instance
|
||||||
@ -30,7 +30,7 @@ function resolver(Resolver $resolver = null): Resolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new dns resolver best-suited for the current environment
|
* Create a new dns resolver best-suited for the current environment.
|
||||||
*
|
*
|
||||||
* @return \Amp\Dns\Resolver
|
* @return \Amp\Dns\Resolver
|
||||||
*/
|
*/
|
||||||
@ -40,7 +40,7 @@ function driver(): Resolver {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve a hostname name to an IP address
|
* Resolve a hostname name to an IP address
|
||||||
* [hostname as defined by RFC 3986]
|
* [hostname as defined by RFC 3986].
|
||||||
*
|
*
|
||||||
* Upon success the returned promise resolves to an indexed array of the form:
|
* Upon success the returned promise resolves to an indexed array of the form:
|
||||||
*
|
*
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<phpunit
|
<phpunit
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
|
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.0/phpunit.xsd"
|
||||||
backupGlobals="false"
|
backupGlobals="false"
|
||||||
backupStaticAttributes="false"
|
backupStaticAttributes="false"
|
||||||
bootstrap="vendor/autoload.php"
|
bootstrap="vendor/autoload.php"
|
||||||
@ -13,7 +13,7 @@
|
|||||||
stopOnFailure="false"
|
stopOnFailure="false"
|
||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Amp DNS">
|
<testsuite name="Main">
|
||||||
<directory>test</directory>
|
<directory>test</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
@ -22,7 +22,7 @@
|
|||||||
<directory suffix=".php">lib</directory>
|
<directory suffix=".php">lib</directory>
|
||||||
</whitelist>
|
</whitelist>
|
||||||
</filter>
|
</filter>
|
||||||
<logging>
|
<listeners>
|
||||||
<log type="coverage-html" target="build/coverage" title="Amp" highlight="true"/>
|
<listener class="Amp\PHPUnit\LoopReset"/>
|
||||||
</logging>
|
</listeners>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
@ -3,8 +3,9 @@
|
|||||||
namespace Amp\Dns\Test;
|
namespace Amp\Dns\Test;
|
||||||
|
|
||||||
use Amp\Loop;
|
use Amp\Loop;
|
||||||
|
use Amp\PHPUnit\TestCase;
|
||||||
|
|
||||||
class IntegrationTest extends \PHPUnit_Framework_TestCase {
|
class IntegrationTest extends TestCase {
|
||||||
/**
|
/**
|
||||||
* @group internet
|
* @group internet
|
||||||
* @dataProvider provideHostnames
|
* @dataProvider provideHostnames
|
||||||
|
@ -3,9 +3,10 @@
|
|||||||
namespace Amp\Dns\Test;
|
namespace Amp\Dns\Test;
|
||||||
|
|
||||||
use Amp\Coroutine;
|
use Amp\Coroutine;
|
||||||
|
use Amp\PHPUnit\TestCase;
|
||||||
use ReflectionObject;
|
use ReflectionObject;
|
||||||
|
|
||||||
class ResolvConfTest extends \PHPUnit_Framework_TestCase {
|
class ResolvConfTest extends TestCase {
|
||||||
public function test() {
|
public function test() {
|
||||||
$reflector = new ReflectionObject(\Amp\Dns\resolver());
|
$reflector = new ReflectionObject(\Amp\Dns\resolver());
|
||||||
$method = $reflector->getMethod("loadResolvConf");
|
$method = $reflector->getMethod("loadResolvConf");
|
||||||
@ -39,4 +40,4 @@ class ResolvConfTest extends \PHPUnit_Framework_TestCase {
|
|||||||
"attempts" => 2,
|
"attempts" => 2,
|
||||||
], $result);
|
], $result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user