1
0
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:
Niklas Keller 2017-06-17 10:49:54 +02:00
parent 38250dddad
commit cbac861746
17 changed files with 150 additions and 77 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ build
composer.lock
phpunit.xml
vendor
.php_cs.cache

15
.php_cs
View File

@ -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
View 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")
);

View File

@ -12,26 +12,18 @@ matrix:
- php: nightly
fast_finish: true
env:
- DEPS=lowest
- DEPS=highest
install:
- if [ "$DEPS" = "lowest" ]; then
composer update -n --prefer-source --prefer-lowest;
else
composer update -n --prefer-source;
fi;
- composer show
before_script:
# --ignore-platform-reqs, because https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/2722
- composer update -n --prefer-dist --ignore-platform-reqs
- composer require satooshi/php-coveralls dev-master --ignore-platform-reqs
script:
- 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:
- composer require satooshi/php-coveralls dev-master
- travis_retry php vendor/bin/coveralls -v
after_script:
- php vendor/bin/coveralls -v
cache:
directories:
- $HOME/.composer/cache
- $HOME/.composer/cache/files

45
Makefile Normal file
View 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 $@

View File

@ -5,14 +5,8 @@ clone_folder: c:\projects\php-project-workspace
environment:
matrix:
- dependencies: lowest
php_ver_target: 7.0
- dependencies: lowest
php_ver_target: 7.1
- dependencies: highest
php_ver_target: 7.0
- dependencies: highest
php_ver_target: 7.1
- php_ver_target: 7.0
- php_ver_target: 7.1
## Cache composer bits
cache:
@ -39,8 +33,7 @@ install:
- IF %PHP%==1 echo @php %%~dp0composer.phar %%* > composer.bat
- appveyor DownloadFile https://getcomposer.org/composer.phar
- cd c:\projects\php-project-workspace
- IF %dependencies%==lowest appveyor-retry composer update --prefer-lowest --no-progress --profile -n
- IF %dependencies%==highest appveyor-retry composer update --no-progress --profile -n
- appveyor-retry composer update --no-progress -n
- composer show
## Run the actual test

View File

@ -1,13 +1,14 @@
{
"name": "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": [
"dns",
"resolve",
"client",
"async",
"amp"
"amp",
"amphp"
],
"license": "MIT",
"authors": [
@ -39,8 +40,9 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"phpunit/phpunit": "^5.2.8",
"friendsofphp/php-cs-fixer": "^1.9"
"amphp/phpunit-util": "^1",
"phpunit/phpunit": "^6",
"friendsofphp/php-cs-fixer": "^2.3"
},
"autoload": {
"psr-4": {

View File

@ -2,12 +2,22 @@
namespace Amp\Dns;
use Amp\{ CallableMaker, Deferred, Failure, Loop, MultiReasonException, Promise, Success, TimeoutException, function call };
use Amp\Cache\ArrayCache;
use Amp\CallableMaker;
use Amp\Deferred;
use Amp\Failure;
use Amp\File\FilesystemException;
use Amp\WindowsRegistry\{ KeyNotFoundException, WindowsRegistry };
use LibDNS\{ Decoder\DecoderFactory, Encoder\EncoderFactory };
use LibDNS\Messages\{ MessageFactory, MessageTypes };
use Amp\Loop;
use Amp\MultiReasonException;
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;
class DefaultResolver implements Resolver {
@ -243,9 +253,8 @@ class DefaultResolver implements Resolver {
if (empty($types)) {
if (empty(array_filter($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 {
list( , $resultArr) = yield Promise\timeout(Promise\some($promises), $timeout);
list(, $resultArr) = yield Promise\timeout(Promise\some($promises), $timeout);
foreach ($resultArr as $value) {
$result += $value;
}
@ -276,10 +285,9 @@ class DefaultResolver implements Resolver {
throw new TimeoutException(
"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) {
if (empty($result)) { // if we have no cached results
throw $e;
@ -365,7 +373,8 @@ class DefaultResolver implements Resolver {
while ($nameserver === "" && ($key = \array_shift($keys))) {
try {
$nameserver = yield $reader->read($key);
} catch (KeyNotFoundException $e) { }
} catch (KeyNotFoundException $e) {
}
}
if ($nameserver === "") {
@ -379,7 +388,8 @@ class DefaultResolver implements Resolver {
if ($nameserver !== "") {
break 2;
}
} catch (KeyNotFoundException $e) { }
} catch (KeyNotFoundException $e) {
}
}
}
}
@ -514,13 +524,13 @@ class DefaultResolver implements Resolver {
if (\substr($uri, 0, 6) == "tcp://") {
$deferred = new Deferred;
$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($timer);
unset($server->connect);
$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);
$this->unloadServer($id);
$deferred->fail(new TimeoutException("Name resolution timed out, could not connect to server at $uri"));
@ -660,7 +670,7 @@ class DefaultResolver implements Resolver {
} else {
foreach ($result as $type => $records) {
$minttl = \PHP_INT_MAX;
foreach ($records as list( , , $ttl)) {
foreach ($records as list(, , $ttl)) {
if ($ttl < $minttl) {
$minttl = $ttl;
}

View File

@ -2,4 +2,5 @@
namespace Amp\Dns;
class NoRecordException extends ResolutionException {}
class NoRecordException extends ResolutionException {
}

View File

@ -2,4 +2,5 @@
namespace Amp\Dns;
class Record extends \LibDNS\Records\ResourceQTypes {}
class Record extends \LibDNS\Records\ResourceQTypes {
}

View File

@ -2,4 +2,5 @@
namespace Amp\Dns;
class ResolutionException extends \Exception {}
class ResolutionException extends \Exception {
}

View File

@ -2,4 +2,5 @@
namespace Amp\Dns;
class TimeoutException extends ResolutionException {}
class TimeoutException extends ResolutionException {
}

View File

@ -8,7 +8,7 @@ use Amp\Promise;
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
* @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
*/
@ -40,7 +40,7 @@ function driver(): Resolver {
/**
* 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:
*

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
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"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
@ -13,7 +13,7 @@
stopOnFailure="false"
>
<testsuites>
<testsuite name="Amp DNS">
<testsuite name="Main">
<directory>test</directory>
</testsuite>
</testsuites>
@ -22,7 +22,7 @@
<directory suffix=".php">lib</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="build/coverage" title="Amp" highlight="true"/>
</logging>
<listeners>
<listener class="Amp\PHPUnit\LoopReset"/>
</listeners>
</phpunit>

View File

@ -3,8 +3,9 @@
namespace Amp\Dns\Test;
use Amp\Loop;
use Amp\PHPUnit\TestCase;
class IntegrationTest extends \PHPUnit_Framework_TestCase {
class IntegrationTest extends TestCase {
/**
* @group internet
* @dataProvider provideHostnames

View File

@ -3,9 +3,10 @@
namespace Amp\Dns\Test;
use Amp\Coroutine;
use Amp\PHPUnit\TestCase;
use ReflectionObject;
class ResolvConfTest extends \PHPUnit_Framework_TestCase {
class ResolvConfTest extends TestCase {
public function test() {
$reflector = new ReflectionObject(\Amp\Dns\resolver());
$method = $reflector->getMethod("loadResolvConf");