From 8174673120a9caa1a5952a3292d4cea798e9a1c4 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Fri, 14 Apr 2017 12:29:50 +0200 Subject: [PATCH] Store IANA's RNG files in the repository (#24) * rename function * update readme * rename function (#11) (#15) * rename function * update readme * fixes #14 | added missing MisdirectedRequestException for error code 421 (#17) * fixes #14, fixes #13 and added missing MisdirectedRequestException for error code 421 * Issue 16 (#20) fixes #16 * Store IANA's RNG files in the repository * Updated readme style | added CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 74 +++++++++++ README.md | 51 ++++---- phpunit.xml.dist | 2 +- tests/HttpStatusTest.php | 39 ++++-- tests/schema/http-status-codes.rng | 31 +++++ tests/schema/iana-registry.rng | 198 +++++++++++++++++++++++++++++ 6 files changed, 361 insertions(+), 34 deletions(-) create mode 100644 CODE_OF_CONDUCT.md create mode 100644 tests/schema/http-status-codes.rng create mode 100644 tests/schema/iana-registry.rng diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..94dfcc1 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,74 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at [d.bannert@anolilab.de](mailto:d.bannert@anolilab.de). All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/README.md b/README.md index 1e30536..631bf74 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,26 @@ -# http-status - -[![Author](http://img.shields.io/badge/author-@anolilab-blue.svg?style=flat-square)](https://twitter.com/anolilab) -[![Total Downloads](https://img.shields.io/packagist/dt/narrowspark/http-status.svg?style=flat-square)](https://packagist.org/packages/narrowspark/http-status) -[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) - -## Master - -[![Build Status](https://img.shields.io/travis/narrowspark/http-status/master.svg?style=flat-square)](https://travis-ci.org/narrowspark/http-status) -[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/narrowspark/http-status.svg?style=flat-square)](https://scrutinizer-ci.com/g/narrowspark/http-status/code-structure) -[![Quality Score](https://img.shields.io/scrutinizer/g/narrowspark/http-status.svg?style=flat-square)](https://scrutinizer-ci.com/g/narrowspark/http-status) - -## Install +

Http Status

+

A package for working with HTTP statuses.

+

+ + + + + + + +

+ +Installation +------------ Via Composer -``` bash +```bash $ composer require narrowspark/http-status ``` -## Usage +Use +------------ ``` php use Narrowspark\HttpStatus\HttpStatus; @@ -132,24 +134,27 @@ Code | Message | RFC 511 | Network Authentication Required | [RFC6585] 512-599 | *Unassigned* | -## Change log +Change log +------------ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. -## Testing +Testing +------------ ``` bash $ vendor/bin/phpunit ``` -## Contributing +Contributing +------------ -Please see [CONTRIBUTING](CONTRIBUTING.md) for details. +If you would like to help take a look at the [list of issues](http://github.com/narrowspark/http-emitter/issues) and check our [Contributing](CONTRIBUTING.md) guild. -## Credits +> **Note:** Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. -- [All Contributors](../../contributors) -## License +License +--------------- -The MIT License (MIT). Please see [License File](LICENSE.md) for more information. +The Narrowspark http-emitter is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 24a505a..f159bd5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -22,7 +22,7 @@ - + ./tests/ diff --git a/tests/HttpStatusTest.php b/tests/HttpStatusTest.php index ee93321..0dfb569 100644 --- a/tests/HttpStatusTest.php +++ b/tests/HttpStatusTest.php @@ -327,34 +327,53 @@ public function testGetReasonExceptionAgainstIana($code, $reasonPhrase) } } + /** + * @link http://github.com/zendframework/zend-diactoros for the canonical source repository + * + * @author Fábio Pacheco + * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com) + * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License + */ public function ianaCodesReasonPhrasesProvider(): array { + if (! in_array('https', stream_get_wrappers(), true)) { + $this->markTestSkipped('The "https" wrapper is not available'); + } + $ianaHttpStatusCodes = new DOMDocument(); - $ianaHttpStatusCodes->loadXML(file_get_contents('https://www.iana.org/assignments/http-status-codes/http-status-codes.xml')); - $ianaCodesReasonPhrases = []; + libxml_set_streams_context(stream_context_create([ + 'http' => [ + 'method' => 'GET', + 'timeout' => 30, + ], + ])); - $xpath = new DomXPath($ianaHttpStatusCodes); - $xpath->registerNamespace('ns', 'http://www.iana.org/assignments'); + $ianaHttpStatusCodes->load('https://www.iana.org/assignments/http-status-codes/http-status-codes.xml'); + + if (! $ianaHttpStatusCodes->relaxNGValidate(__DIR__ . '/schema/http-status-codes.rng')) { + self::fail('Invalid IANA\'s HTTP status code list.'); + } + $ianaCodesReasonPhrases = []; + $xpath = new DomXPath($ianaHttpStatusCodes); + $xpath->registerNamespace('ns', 'http://www.iana.org/assignments'); $records = $xpath->query('//ns:record'); foreach ($records as $record) { $value = $xpath->query('.//ns:value', $record)->item(0)->nodeValue; $description = $xpath->query('.//ns:description', $record)->item(0)->nodeValue; - if ($description === 'Unassigned' | $description === '(Unused)') { + if (in_array($description, ['Unassigned', '(Unused)'], true)) { continue; } - $range = preg_match('/^([0-9]+)\s*\-\s*([0-9]+)$/', $value, $matches); - - if (! $range) { - $ianaCodesReasonPhrases[] = [$value, $description]; - } else { + if (preg_match('/^([0-9]+)\s*\-\s*([0-9]+)$/', $value, $matches)) { for ($value = $matches[1]; $value <= $matches[2]; ++$value) { $ianaCodesReasonPhrases[] = [$value, $description]; } + } else { + $ianaCodesReasonPhrases[] = [$value, $description]; } } diff --git a/tests/schema/http-status-codes.rng b/tests/schema/http-status-codes.rng new file mode 100644 index 0000000..73708ca --- /dev/null +++ b/tests/schema/http-status-codes.rng @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/schema/iana-registry.rng b/tests/schema/iana-registry.rng new file mode 100644 index 0000000..b9c3ca9 --- /dev/null +++ b/tests/schema/iana-registry.rng @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + uri + + + + rfc + + + (rfc|bcp|std)\d+ + + + + + rfc-errata + + + + draft + + + (draft|RFC)(-[a-zA-Z0-9]+)+ + + + + + registry + + + + person + + + + text + + + note + + + + unicode + + + ucd\d+\.\d+\.\d+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + (\d+|0x[\da-fA-F]+)(\s*-\s*(\d+|0x[\da-fA-F]+))? + + + + + + + + + + + + + 0x[0-9]{8} + + + + + + [0-1]+ + + + + + + + + + + + + + + + + + + + + + + legacy + mib + template + json + + + + + + + + + +