diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..32f6a5f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,51 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + test: + name: PHP ${{ matrix.php-version }} + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + php-version: + - '8.2' + - '8.3' + - '8.4' + - '8.5' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: dom, libxml, simplexml + coverage: none + + - name: Validate composer.json + run: composer validate --strict --no-check-lock + + - name: Get Composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache Composer dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --no-suggest + + - name: Run tests + run: vendor/bin/phpunit --no-coverage diff --git a/.gitignore b/.gitignore index 57fd88e..70023f5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build composer.phar +composer.lock vendor/ bin/ diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 61b7113..0000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -language: php -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4 -install: - - composer update diff --git a/README.md b/README.md index 2d67f79..3dabae8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Nocarrier\Hal ============= -[![Build Status](https://secure.travis-ci.org/blongden/hal.png)](http://travis-ci.org/blongden/hal) +[![CI](https://github.com/blongden/hal/actions/workflows/ci.yml/badge.svg)](https://github.com/blongden/hal/actions/workflows/ci.yml) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/blongden/hal/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/blongden/hal/?branch=master) This is a library for creating documents in the [application/hal+json and application/hal+xml][1] hypermedia formats diff --git a/composer.json b/composer.json index aa0a00f..841af77 100644 --- a/composer.json +++ b/composer.json @@ -13,13 +13,12 @@ } ], "require": { - "php": ">=5.3.0", - "psr/link": "~1.0" + "php": "^8.2", + "psr/link": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^7.0 || ^6.4 || ^5.7 || ^4.8.35" + "phpunit/phpunit": "^11" }, - "minimum-stability": "dev", "autoload": { "psr-4": { "Nocarrier\\": "src" @@ -29,8 +28,5 @@ "psr-4": { "Nocarrier\\Tests\\": "tests/Hal" } - }, - "config": { - "bin-dir": "bin" } } diff --git a/composer.lock b/composer.lock deleted file mode 100644 index c1982c9..0000000 --- a/composer.lock +++ /dev/null @@ -1,1107 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "a5715fea738eb8ca4fc1f13cba56ca9e", - "packages": [ - { - "name": "psr/link", - "version": "dev-master", - "source": { - "type": "git", - "url": "https://github.com/php-fig/link.git", - "reference": "131b5c337db3599ef922e9d6c22889ad237b80b9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/link/zipball/131b5c337db3599ef922e9d6c22889ad237b80b9", - "reference": "131b5c337db3599ef922e9d6c22889ad237b80b9", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Link\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interfaces for HTTP links", - "homepage": "https://github.com/php-fig/link", - "keywords": [ - "http", - "http-link", - "link", - "psr", - "psr-13", - "rest" - ], - "time": "2016-11-17T00:27:01+00:00" - } - ], - "packages-dev": [ - { - "name": "dflydev/markdown", - "version": "v1.0.0", - "source": { - "type": "git", - "url": "https://github.com/dflydev/dflydev-markdown.git", - "reference": "76501a808522dbe40a5a71d272bd08d54cbae03d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/dflydev/dflydev-markdown/zipball/76501a808522dbe40a5a71d272bd08d54cbae03d", - "reference": "76501a808522dbe40a5a71d272bd08d54cbae03d", - "shasum": "" - }, - "require": { - "php": ">=5.3" - }, - "type": "library", - "autoload": { - "psr-0": { - "dflydev\\markdown": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "New BSD License" - ], - "description": "PHP Markdown & Extra", - "homepage": "http://github.com/dflydev/dflydev-markdown", - "abandoned": "michelf/php-markdown", - "time": "2012-01-02T23:11:32+00:00" - }, - { - "name": "doctrine/instantiator", - "version": "1.0.4", - "source": { - "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/f976e5de371104877ebc89bd8fecb0019ed9c119", - "reference": "f976e5de371104877ebc89bd8fecb0019ed9c119", - "shasum": "" - }, - "require": { - "php": ">=5.3,<8.0-DEV" - }, - "require-dev": { - "athletic/athletic": "~0.1.8", - "ext-pdo": "*", - "ext-phar": "*", - "phpunit/phpunit": "~4.0", - "squizlabs/php_codesniffer": "2.0.*@ALPHA" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Doctrine\\Instantiator\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" - } - ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://github.com/doctrine/instantiator", - "keywords": [ - "constructor", - "instantiate" - ], - "support": { - "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/master" - }, - "time": "2014-10-13T12:58:55+00:00" - }, - { - "name": "phpdocumentor/reflection-docblock", - "version": "2.0.0a1", - "source": { - "type": "git", - "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "841897062442e2a0e8b3def1518caa25f6498dfd" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/841897062442e2a0e8b3def1518caa25f6498dfd", - "reference": "841897062442e2a0e8b3def1518caa25f6498dfd", - "shasum": "" - }, - "require": { - "dflydev/markdown": "1.0.*", - "php": ">=5.3.2" - }, - "require-dev": { - "phpunit/phpunit": "*@stable" - }, - "type": "library", - "autoload": { - "psr-0": { - "phpDocumentor": [ - "src/" - ] - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Mike van Riel", - "email": "mike.vanriel@naenius.com" - } - ], - "support": { - "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", - "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/2.0.0a1" - }, - "time": "2012-11-27T17:52:28+00:00" - }, - { - "name": "phpspec/prophecy", - "version": "v1.3.1", - "source": { - "type": "git", - "url": "https://github.com/phpspec/prophecy.git", - "reference": "9ca52329bcdd1500de24427542577ebf3fc2f1c9" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/9ca52329bcdd1500de24427542577ebf3fc2f1c9", - "reference": "9ca52329bcdd1500de24427542577ebf3fc2f1c9", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "~1.0,>=1.0.2", - "phpdocumentor/reflection-docblock": "~2.0" - }, - "require-dev": { - "phpspec/phpspec": "~2.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "psr-0": { - "Prophecy\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Konstantin Kudryashov", - "email": "ever.zet@gmail.com", - "homepage": "http://everzet.com" - }, - { - "name": "Marcello Duarte", - "email": "marcello.duarte@gmail.com" - } - ], - "description": "Highly opinionated mocking framework for PHP 5.3+", - "homepage": "http://phpspec.org", - "keywords": [ - "Double", - "Dummy", - "fake", - "mock", - "spy", - "stub" - ], - "support": { - "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/v1.3.1" - }, - "time": "2014-11-17T16:23:49+00:00" - }, - { - "name": "phpunit/php-code-coverage", - "version": "2.1.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "ba315f46873fd6e86fdb98685a1a900e7379c886" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/ba315f46873fd6e86fdb98685a1a900e7379c886", - "reference": "ba315f46873fd6e86fdb98685a1a900e7379c886", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "phpunit/php-file-iterator": "~1.3", - "phpunit/php-text-template": "~1.2", - "phpunit/php-token-stream": "~1.3", - "sebastian/environment": "~1.0", - "sebastian/version": "~1.0" - }, - "require-dev": { - "ext-xdebug": ">=2.1.4", - "phpunit/phpunit": "~4" - }, - "suggest": { - "ext-dom": "*", - "ext-xdebug": ">=2.2.1", - "ext-xmlwriter": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.1.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", - "homepage": "https://github.com/sebastianbergmann/php-code-coverage", - "keywords": [ - "coverage", - "testing", - "xunit" - ], - "support": { - "irc": "irc://irc.freenode.net/phpunit", - "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/2.1.0" - }, - "time": "2015-05-30T12:58:40+00:00" - }, - { - "name": "phpunit/php-file-iterator", - "version": "1.4.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a923bb15680d0089e2316f7a4af8f437046e96bb", - "reference": "a923bb15680d0089e2316f7a4af8f437046e96bb", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "FilterIterator implementation that filters files based on a list of suffixes.", - "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", - "keywords": [ - "filesystem", - "iterator" - ], - "support": { - "irc": "irc://irc.freenode.net/phpunit", - "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", - "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/master" - }, - "time": "2015-04-02T05:19:05+00:00" - }, - { - "name": "phpunit/php-text-template", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-text-template.git", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "reference": "206dfefc0ffe9cebf65c413e3d0e809c82fbf00a", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "Text/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "include-path": [ - "" - ], - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Simple template engine.", - "homepage": "https://github.com/sebastianbergmann/php-text-template/", - "keywords": [ - "template" - ], - "support": { - "irc": "irc://irc.freenode.net/phpunit", - "issues": "https://github.com/sebastianbergmann/php-text-template/issues", - "source": "https://github.com/sebastianbergmann/php-text-template/tree/1.2.0" - }, - "time": "2014-01-30T17:20:04+00:00" - }, - { - "name": "phpunit/php-timer", - "version": "1.0.6", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-timer.git", - "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/83fe1bdc5d47658b727595c14da140da92b3d66d", - "reference": "83fe1bdc5d47658b727595c14da140da92b3d66d", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sb@sebastian-bergmann.de", - "role": "lead" - } - ], - "description": "Utility class for timing", - "homepage": "https://github.com/sebastianbergmann/php-timer/", - "keywords": [ - "timer" - ], - "support": { - "irc": "irc://irc.freenode.net/phpunit", - "issues": "https://github.com/sebastianbergmann/php-timer/issues", - "source": "https://github.com/sebastianbergmann/php-timer/tree/1.0.6" - }, - "time": "2015-06-13T07:35:30+00:00" - }, - { - "name": "phpunit/php-token-stream", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/php-token-stream.git", - "reference": "f8d5d08c56de5cfd592b3340424a81733259a876" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-token-stream/zipball/f8d5d08c56de5cfd592b3340424a81733259a876", - "reference": "f8d5d08c56de5cfd592b3340424a81733259a876", - "shasum": "" - }, - "require": { - "ext-tokenizer": "*", - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Wrapper around PHP's tokenizer extension.", - "homepage": "https://github.com/sebastianbergmann/php-token-stream/", - "keywords": [ - "tokenizer" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/php-token-stream/issues", - "source": "https://github.com/sebastianbergmann/php-token-stream/tree/master" - }, - "time": "2014-08-31T06:12:13+00:00" - }, - { - "name": "phpunit/phpunit", - "version": "4.8.35", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "791b1a67c25af50e230f841ee7a9c6eba507dc87" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/791b1a67c25af50e230f841ee7a9c6eba507dc87", - "reference": "791b1a67c25af50e230f841ee7a9c6eba507dc87", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "ext-json": "*", - "ext-pcre": "*", - "ext-reflection": "*", - "ext-spl": "*", - "php": ">=5.3.3", - "phpspec/prophecy": "^1.3.1", - "phpunit/php-code-coverage": "~2.1", - "phpunit/php-file-iterator": "~1.4", - "phpunit/php-text-template": "~1.2", - "phpunit/php-timer": "^1.0.6", - "phpunit/phpunit-mock-objects": "~2.3", - "sebastian/comparator": "~1.2.2", - "sebastian/diff": "~1.2", - "sebastian/environment": "~1.3", - "sebastian/exporter": "~1.2", - "sebastian/global-state": "~1.0", - "sebastian/version": "~1.0", - "symfony/yaml": "~2.1|~3.0" - }, - "suggest": { - "phpunit/php-invoker": "~1.1" - }, - "bin": [ - "phpunit" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.8.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "The PHP Unit Testing framework.", - "homepage": "https://phpunit.de/", - "keywords": [ - "phpunit", - "testing", - "xunit" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/4.8.35" - }, - "time": "2017-02-06T05:18:07+00:00" - }, - { - "name": "phpunit/phpunit-mock-objects", - "version": "2.3.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpunit-mock-objects.git", - "reference": "c63d2367247365f688544f0d500af90a11a44c65" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit-mock-objects/zipball/c63d2367247365f688544f0d500af90a11a44c65", - "reference": "c63d2367247365f688544f0d500af90a11a44c65", - "shasum": "" - }, - "require": { - "doctrine/instantiator": "~1.0,>=1.0.1", - "php": ">=5.3.3", - "phpunit/php-text-template": "~1.2" - }, - "require-dev": { - "phpunit/phpunit": "~4.3" - }, - "suggest": { - "ext-soap": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.3.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "description": "Mock Object library for PHPUnit", - "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", - "abandoned": true, - "time": "2014-10-03T05:12:11+00:00" - }, - { - "name": "sebastian/comparator", - "version": "1.2.2", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "6a1ed12e8b2409076ab22e3897126211ff8b1f7f" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/6a1ed12e8b2409076ab22e3897126211ff8b1f7f", - "reference": "6a1ed12e8b2409076ab22e3897126211ff8b1f7f", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "sebastian/diff": "~1.2", - "sebastian/exporter": "~1.2 || ~2.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides the functionality to compare PHP values for equality", - "homepage": "http://www.github.com/sebastianbergmann/comparator", - "keywords": [ - "comparator", - "compare", - "equality" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/comparator/issues", - "source": "https://github.com/sebastianbergmann/comparator/tree/master" - }, - "time": "2016-11-19T09:18:40+00:00" - }, - { - "name": "sebastian/diff", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/diff.git", - "reference": "5843509fed39dee4b356a306401e9dd1a931fec7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/5843509fed39dee4b356a306401e9dd1a931fec7", - "reference": "5843509fed39dee4b356a306401e9dd1a931fec7", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Kore Nordmann", - "email": "mail@kore-nordmann.de" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Diff implementation", - "homepage": "http://www.github.com/sebastianbergmann/diff", - "keywords": [ - "diff" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/diff/issues", - "source": "https://github.com/sebastianbergmann/diff/tree/master" - }, - "time": "2014-08-15T10:29:00+00:00" - }, - { - "name": "sebastian/environment", - "version": "1.3.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/environment.git", - "reference": "4fe0a44cddd8cc19583a024bdc7374eb2fef0b87" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/4fe0a44cddd8cc19583a024bdc7374eb2fef0b87", - "reference": "4fe0a44cddd8cc19583a024bdc7374eb2fef0b87", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Provides functionality to handle HHVM/PHP environments", - "homepage": "http://www.github.com/sebastianbergmann/environment", - "keywords": [ - "Xdebug", - "environment", - "hhvm" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/environment/issues", - "source": "https://github.com/sebastianbergmann/environment/tree/1.3.0" - }, - "time": "2015-07-26T06:42:57+00:00" - }, - { - "name": "sebastian/exporter", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "84839970d05254c73cde183a721c7af13aede943" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/84839970d05254c73cde183a721c7af13aede943", - "reference": "84839970d05254c73cde183a721c7af13aede943", - "shasum": "" - }, - "require": { - "php": ">=5.3.3", - "sebastian/recursion-context": "~1.0" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Volker Dusch", - "email": "github@wallbash.com" - }, - { - "name": "Bernhard Schussek", - "email": "bschussek@2bepublished.at" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", - "keywords": [ - "export", - "exporter" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/exporter/issues", - "source": "https://github.com/sebastianbergmann/exporter/tree/master" - }, - "time": "2015-01-27T07:23:06+00:00" - }, - { - "name": "sebastian/global-state", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/c7428acdb62ece0a45e6306f1ae85e1c05b09c01", - "reference": "c7428acdb62ece0a45e6306f1ae85e1c05b09c01", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.2" - }, - "suggest": { - "ext-uopz": "*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - } - ], - "description": "Snapshotting of global state", - "homepage": "http://www.github.com/sebastianbergmann/global-state", - "keywords": [ - "global state" - ], - "support": { - "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/master" - }, - "time": "2014-10-06T09:23:50+00:00" - }, - { - "name": "sebastian/recursion-context", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", - "reference": "3989662bbb30a29d20d9faa04a846af79b276252", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "require-dev": { - "phpunit/phpunit": "~4.4" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de" - }, - { - "name": "Adam Harvey", - "email": "aharvey@php.net" - } - ], - "description": "Provides functionality to recursively process PHP variables", - "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "support": { - "issues": "https://github.com/sebastianbergmann/recursion-context/issues", - "source": "https://github.com/sebastianbergmann/recursion-context/tree/1.0.0" - }, - "time": "2015-01-24T09:48:32+00:00" - }, - { - "name": "sebastian/version", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/version.git", - "reference": "16b021aed448b654ae05846e394e057e9a6f04cb" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/16b021aed448b654ae05846e394e057e9a6f04cb", - "reference": "16b021aed448b654ae05846e394e057e9a6f04cb", - "shasum": "" - }, - "type": "library", - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Library that helps with managing the version number of Git-hosted PHP projects", - "homepage": "https://github.com/sebastianbergmann/version", - "support": { - "issues": "https://github.com/sebastianbergmann/version/issues", - "source": "https://github.com/sebastianbergmann/version/tree/1.0.0" - }, - "time": "2013-01-05T14:27:32+00:00" - }, - { - "name": "symfony/yaml", - "version": "v2.1.0", - "target-dir": "Symfony/Component/Yaml", - "source": { - "type": "git", - "url": "https://github.com/symfony/yaml.git", - "reference": "f18e004fc975707bb4695df1dbbe9b0d8c8b7715" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/f18e004fc975707bb4695df1dbbe9b0d8c8b7715", - "reference": "f18e004fc975707bb4695df1dbbe9b0d8c8b7715", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.1-dev" - } - }, - "autoload": { - "psr-0": { - "Symfony\\Component\\Yaml": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Symfony Community", - "homepage": "http://symfony.com/contributors" - }, - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - } - ], - "description": "Symfony Yaml Component", - "homepage": "http://symfony.com", - "support": { - "source": "https://github.com/symfony/yaml/tree/v2.1.2" - }, - "time": "2012-08-22T13:48:41+00:00" - } - ], - "aliases": [], - "minimum-stability": "dev", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": true, - "platform": { - "php": ">=5.3.0" - }, - "platform-dev": [], - "plugin-api-version": "2.0.0" -} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b991b0d..7d0fc95 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,20 +1,26 @@ - - + ./tests/Hal/ - - + + ./src/ - - + + + + + + + + - - - + diff --git a/src/Hal.php b/src/Hal.php index 5b42976..1deb59f 100644 --- a/src/Hal.php +++ b/src/Hal.php @@ -20,13 +20,6 @@ */ class Hal { - /** - * The uri represented by this representation. - * - * @var string - */ - protected $uri; - /** * The data for this resource. An associative array of key value pairs. * @@ -44,7 +37,7 @@ class Hal * * @var array */ - protected $resources = array(); + protected $resources = []; /** * A collection of \Nocarrier\HalLink objects keyed by the link relation to @@ -63,14 +56,14 @@ class Hal * * @var array */ - protected $arrayLinkRels = array(); + protected $arrayLinkRels = []; /** * A list of rel types for links that will force a rel type to array for one element * * @var array */ - protected $arrayResourceRels = array(); + protected $arrayResourceRels = []; /** * Whether xml attribute markers should be stripped when rendering @@ -100,10 +93,11 @@ class Hal * * @throws \RuntimeException */ - public function __construct($uri = null, $data = array()) + public function __construct(/** + * The uri represented by this representation. + */ + protected $uri = null, $data = []) { - $this->uri = $uri; - if (!is_array($data) && !$data instanceof \Traversable) { throw new \RuntimeException( 'The $data parameter must be an array or an object implementing the Traversable interface.'); @@ -151,7 +145,7 @@ public static function fromXml($data, $depth = 0) * @param bool $forceArray whether to force a rel to be an array if it has only one entry * @return \Nocarrier\Hal */ - public function addLink($rel, $uri, array $attributes = array(), $forceArray = false) + public function addLink($rel, $uri, array $attributes = [], $forceArray = false) { return $this->addHalLink($rel, new HalLink($uri, $attributes), $forceArray); } @@ -183,7 +177,7 @@ public function addHalLink($rel, HalLink $link, $forceArray = false) * * @return \Nocarrier\Hal */ - public function addResource($rel, \Nocarrier\Hal $resource = null, $forceArray = true) + public function addResource($rel, null|\Nocarrier\Hal $resource = null, $forceArray = true) { if (!is_string($rel)) { throw new \InvalidArgumentException( @@ -231,7 +225,7 @@ public function setResource($rel, $resource) /** * Set resource's data */ - public function setData(Array $data = null) + public function setData(null|Array $data = null) { $this->data = $data; return $this; @@ -246,7 +240,7 @@ public function setData(Array $data = null) public function getData($key = null) { if ($key) { - return isset($this->data[$key]) ? $this->data[$key] : array(); + return $this->data[$key] ?? []; } return $this->data; @@ -283,9 +277,7 @@ public function getLink($rel) */ public function getResources() { - $resources = array_map(function ($resource) { - return is_array($resource) ? $resource : array($resource); - }, $this->getRawResources()); + $resources = array_map(fn($resource) => is_array($resource) ? $resource : [$resource], $this->getRawResources()); return $resources; } @@ -299,11 +291,7 @@ public function getResource($rel) { $resources = $this->getResources(); - if (isset($resources[$rel])) { - return $resources[$rel]; - } - - return null; + return $resources[$rel] ?? null; } /** @@ -417,7 +405,7 @@ public function asXml($pretty = false) */ public function addCurie($name, $uri) { - return $this->addLink('curies', $uri, array('name' => $name, 'templated' => true)); + return $this->addLink('curies', $uri, ['name' => $name, 'templated' => true]); } /** diff --git a/src/HalJsonRenderer.php b/src/HalJsonRenderer.php index 0398721..5e9f695 100644 --- a/src/HalJsonRenderer.php +++ b/src/HalJsonRenderer.php @@ -53,20 +53,20 @@ public function render(Hal $resource, $pretty, $encode = true) */ protected function linksForJson($uri, $links, $arrayLinkRels) { - $data = array(); + $data = []; if (!is_null($uri)) { - $data['self'] = array('href' => $uri); + $data['self'] = ['href' => $uri]; } foreach ($links as $rel => $links) { if (count($links) === 1 && $rel !== 'curies' && !in_array($rel, $arrayLinkRels)) { - $data[$rel] = array('href' => $links[0]->getUri()); + $data[$rel] = ['href' => $links[0]->getUri()]; foreach ($links[0]->getAttributes() as $attribute => $value) { $data[$rel][$attribute] = $value; } } else { - $data[$rel] = array(); + $data[$rel] = []; foreach ($links as $link) { - $item = array('href' => $link->getUri()); + $item = ['href' => $link->getUri()]; foreach ($link->getAttributes() as $attribute => $value) { $item[$attribute] = $value; } @@ -91,7 +91,7 @@ protected function resourcesForJson($resources) return $this->arrayForJson($resources); } - $data = array(); + $data = []; foreach ($resources as $resource) { $res = $this->arrayForJson($resource); @@ -115,11 +115,11 @@ protected function resourcesForJson($resources) protected function stripAttributeMarker(array $data) { foreach ($data as $key => $value) { - if (substr($key, 0, 5) == '@xml:') { - $data[substr($key, 5)] = $value; + if (str_starts_with((string) $key, '@xml:')) { + $data[substr((string) $key, 5)] = $value; unset ($data[$key]); - } elseif (substr($key, 0, 1) == '@') { - $data[substr($key, 1)] = $value; + } elseif (str_starts_with((string) $key, '@')) { + $data[substr((string) $key, 1)] = $value; unset ($data[$key]); } @@ -138,10 +138,10 @@ protected function stripAttributeMarker(array $data) * @param \Nocarrier\Hal $resource * @return array */ - protected function arrayForJson(Hal $resource = null) + protected function arrayForJson(null|Hal $resource = null) { if ($resource == null) { - return array(); + return []; } $data = $resource->getData(); diff --git a/src/HalLink.php b/src/HalLink.php index 7c76622..7124d80 100644 --- a/src/HalLink.php +++ b/src/HalLink.php @@ -17,32 +17,8 @@ * @package Nocarrier * @author Ben Longden */ -class HalLink +class HalLink implements \Stringable { - /** - * The URI represented by this HalLink. - * - * @var string - */ - protected $uri; - - /** - * Any attributes on this link. - * - * array( - * 'templated' => 0, - * 'type' => 'application/hal+json', - * 'deprecation' => 1, - * 'name' => 'latest', - * 'profile' => 'http://.../profile/order', - * 'title' => 'The latest order', - * 'hreflang' => 'en' - * ) - * - * @var array - */ - protected $attributes; - /** * The \Nocarrier\HalLink object. * @@ -53,10 +29,27 @@ class HalLink * @param array $attributes * Any additional attributes. */ - public function __construct($uri, $attributes) + public function __construct( + /** + * The URI represented by this HalLink. + */ + protected $uri, + /** + * Any attributes on this link. + * + * array( + * 'templated' => 0, + * 'type' => 'application/hal+json', + * 'deprecation' => 1, + * 'name' => 'latest', + * 'profile' => 'http://.../profile/order', + * 'title' => 'The latest order', + * 'hreflang' => 'en' + * ) + */ + protected $attributes + ) { - $this->uri = $uri; - $this->attributes = $attributes; } /** @@ -84,7 +77,7 @@ public function getAttributes() * * return string */ - public function __toString() + public function __toString(): string { return $this->uri; } diff --git a/src/HalLinkContainer.php b/src/HalLinkContainer.php index a432dfe..b7fa070 100644 --- a/src/HalLinkContainer.php +++ b/src/HalLinkContainer.php @@ -37,8 +37,8 @@ public function get($rel) if (isset($this['curies'])) { foreach ($this['curies'] as $link) { - $prefix = strstr($link->getUri(), '{rel}', true); - if (strpos($rel, $prefix) === 0) { + $prefix = strstr((string) $link->getUri(), '{rel}', true); + if (str_starts_with($rel, $prefix)) { // looks like it is $shortrel = substr($rel, strlen($prefix)); $attrs = $link->getAttributes(); diff --git a/src/HalXmlRenderer.php b/src/HalXmlRenderer.php index e505147..f70c476 100644 --- a/src/HalXmlRenderer.php +++ b/src/HalXmlRenderer.php @@ -85,7 +85,7 @@ protected function linksForXml(\SimpleXmlElement $doc, HalLinkContainer $links) protected function arrayToXml($data, \SimpleXmlElement $element, $parent = null) { foreach ($data as $key => $value) { - if (is_array($value) || $value instanceof \Traversable) { + if (is_iterable($value)) { if (!is_numeric($key)) { if (count($value) > 0 && isset($value[0])) { $this->arrayToXml($value, $element, $key); @@ -99,17 +99,17 @@ protected function arrayToXml($data, \SimpleXmlElement $element, $parent = null) } } else { if (!is_numeric($key)) { - if (substr($key, 0, 1) === '@') { + if (str_starts_with($key, '@')) { $element->addAttribute(substr($key, 1), $value); } elseif ($key === 'value' and count($data) === 1) { $element[0] = $value; } elseif (is_bool($value)) { $element->addChild($key, intval($value)); } else { - $element->addChild($key, htmlspecialchars($value, ENT_QUOTES)); + $element->addChild($key, htmlspecialchars((string) $value, ENT_QUOTES)); } } else { - $element->addChild($parent, htmlspecialchars($value, ENT_QUOTES)); + $element->addChild($parent, htmlspecialchars((string) $value, ENT_QUOTES)); } } } @@ -128,7 +128,7 @@ protected function arrayToXml($data, \SimpleXmlElement $element, $parent = null) protected function resourcesForXml(\SimpleXmlElement $doc, $rel, $resources) { if (!is_array($resources)) { - $resources = array($resources); + $resources = [$resources]; } foreach($resources as $resource) { diff --git a/src/JsonHalFactory.php b/src/JsonHalFactory.php index a99cc3a..24d8752 100644 --- a/src/JsonHalFactory.php +++ b/src/JsonHalFactory.php @@ -15,7 +15,7 @@ class JsonHalFactory */ public static function fromJson(Hal $hal, $text, $depth = 0) { - list($uri, $links, $embedded, $data) = self::prepareJsonData($text); + [$uri, $links, $embedded, $data] = self::prepareJsonData($text); $hal->setUri($uri)->setData($data); self::addJsonLinkData($hal, $links); @@ -35,16 +35,16 @@ private static function prepareJsonData($text) if (json_last_error() != JSON_ERROR_NONE) { throw new \RuntimeException('The $text parameter must be valid JSON'); } - $uri = isset($data['_links']['self']['href']) ? $data['_links']['self']['href'] : ""; + $uri = $data['_links']['self']['href'] ?? ""; unset ($data['_links']['self']); - $links = isset($data['_links']) ? $data['_links'] : array(); + $links = $data['_links'] ?? []; unset ($data['_links']); - $embedded = isset($data['_embedded']) ? $data['_embedded'] : array(); + $embedded = $data['_embedded'] ?? []; unset ($data['_embedded']); - return array($uri, $links, $embedded, $data); + return [$uri, $links, $embedded, $data]; } /** @@ -55,7 +55,7 @@ private static function addJsonLinkData($hal, $links) { foreach ($links as $rel => $links) { if (!isset($links[0]) or !is_array($links[0])) { - $links = array($links); + $links = [$links]; } foreach ($links as $link) { @@ -75,7 +75,7 @@ private static function setEmbeddedResources(Hal $hal, $embedded, $depth) { foreach ($embedded as $rel => $embed) { $isIndexed = array_values($embed) === $embed; - $className = get_class($hal); + $className = $hal::class; if (!$isIndexed) { $hal->setResource($rel, self::fromJson(new $className, json_encode($embed), $depth - 1)); } else { diff --git a/src/XmlHalFactory.php b/src/XmlHalFactory.php index 216111b..273e0ee 100644 --- a/src/XmlHalFactory.php +++ b/src/XmlHalFactory.php @@ -21,7 +21,7 @@ public static function fromXml(Hal $hal, $data, $depth = 0) if (!$data instanceof \SimpleXMLElement) { try { $data = new \SimpleXMLElement($data); - } catch (\Exception $e) { + } catch (\Exception) { throw new \RuntimeException('The $data parameter must be valid XML'); } } @@ -37,17 +37,17 @@ public static function fromXml(Hal $hal, $data, $depth = 0) $hal->setData((array) $children); foreach ($links as $links) { if (!is_array($links)) { - $links = array($links); + $links = [$links]; } foreach ($links as $link) { - list($rel, $href, $attributes) = self::extractKnownData($link); + [$rel, $href, $attributes] = self::extractKnownData($link); $hal->addLink($rel, $href, $attributes); } } if ($depth > 0) { foreach ($embedded as $embed) { - list($rel, $href, $attributes) = self::extractKnownData($embed); + [$rel, $href, $attributes] = self::extractKnownData($embed); $hal->addResource($rel, self::fromXml($embed, $depth - 1)); } } @@ -63,6 +63,6 @@ private static function extractKnownData($data) $href = $attributes['href']; unset($attributes['rel'], $attributes['href']); - return array($rel, $href, $attributes); + return [$rel, $href, $attributes]; } } diff --git a/tests/Hal/HalTest.php b/tests/Hal/HalTest.php index 241c297..9e387b5 100644 --- a/tests/Hal/HalTest.php +++ b/tests/Hal/HalTest.php @@ -61,7 +61,7 @@ public function testAddLinkJsonResponse() public function testAddLinkRelAsArrayJsonResponse() { $hal = new Hal('http://example.com/'); - $hal->addLink('test', '/test/1', array(), true); + $hal->addLink('test', '/test/1', [], true); $json = $hal->asJson(); $expectedJson = '{"_links":{"self":{"href":"http:\/\/example.com\/"},"test":[{"href":"\/test\/1"}]}}'; $this->assertEquals($json,$expectedJson); @@ -97,12 +97,12 @@ public function testXmlPrettyPrintResponse() public function testResourceJsonResponse() { $hal = new Hal('http://example.com/'); - $res = new Hal('/resource/1', array('field1' => 'value1', 'field2' => 'value2')); + $res = new Hal('/resource/1', ['field1' => 'value1', 'field2' => 'value2']); $hal->addResource('resource', $res); $resource = json_decode($hal->asJson()); $this->assertInstanceOf('StdClass', $resource->_embedded); - $this->assertInternalType('array', $resource->_embedded->resource); + $this->assertIsArray($resource->_embedded->resource); $this->assertEquals($resource->_embedded->resource[0]->_links->self->href, '/resource/1'); $this->assertEquals($resource->_embedded->resource[0]->field1, 'value1'); $this->assertEquals($resource->_embedded->resource[0]->field2, 'value2'); @@ -111,7 +111,7 @@ public function testResourceJsonResponse() public function testResourceJsonResponseForceAsNoArray() { $hal = new Hal('http://example.com/'); - $res = new Hal('/resource/1', array('field1' => 'value1', 'field2' => 'value2')); + $res = new Hal('/resource/1', ['field1' => 'value1', 'field2' => 'value2']); $hal->addResource('resource', $res, false); $resource = json_decode($hal->asJson()); @@ -125,7 +125,7 @@ public function testResourceJsonResponseForceAsNoArray() public function testResourceXmlResponse() { $hal = new Hal('http://example.com/'); - $res = new Hal('/resource/1', array('field1' => 'value1', 'field2' => 'value2')); + $res = new Hal('/resource/1', ['field1' => 'value1', 'field2' => 'value2']); $hal->addResource('resource', $res); $result = new \SimpleXmlElement($hal->asXml()); @@ -137,20 +137,20 @@ public function testResourceXmlResponse() public function testEmbeddedResourceInResourceJsonResponse() { $hal = new Hal('http://example.com/'); - $res = new Hal('/resource/1', array('field1' => 'value1', 'field2' => 'value2')); + $res = new Hal('/resource/1', ['field1' => 'value1', 'field2' => 'value2']); $res->addResource( 'item', new Hal( '/resource/1/item/1', - array( + [ 'itemField1' => 'itemValue1' - ) + ] ) ); $hal->addResource('resource', $res); $result = json_decode($hal->asJson()); - $this->assertInternalType('array', $result->_embedded->resource[0]->_embedded->item); + $this->assertIsArray($result->_embedded->resource[0]->_embedded->item); $this->assertEquals('/resource/1/item/1', $result->_embedded->resource[0]->_embedded->item[0]->_links->self->href); $this->assertEquals('itemValue1', $result->_embedded->resource[0]->_embedded->item[0]->itemField1); } @@ -158,18 +158,18 @@ public function testEmbeddedResourceInResourceJsonResponse() public function testEmbeddedResourceInResourceXmlResponse() { $hal = new Hal('http://example.com/'); - $res = new Hal('/resource/1', array('field1' => 'value1', 'field2' => 'value2')); + $res = new Hal('/resource/1', ['field1' => 'value1', 'field2' => 'value2']); $res->addResource( 'item', new Hal( '/resource/1/item/1', - array( - 'items' => array( - array( + [ + 'items' => [ + [ 'itemField1' => 'itemValue1' - ) - ) - ) + ] + ] + ] ) ); @@ -188,18 +188,18 @@ public function testResourceWithListRendersCorrectlyInXmlResponse() $resource = new Hal( '/orders/123', - array( - 'tests' => array( - array( + [ + 'tests' => [ + [ 'total' => 30.00, 'currency' => 'USD' - ), - array( + ], + [ 'total' => 40.00, 'currency' => 'GBP' - ) - ) - ) + ] + ] + ] ); $resource->addLink('customer', '/customer/bob'); $hal->addResource('order', $resource); @@ -214,10 +214,10 @@ public function testAddingDataToRootResource() { $hal = new Hal( '/root', - array( + [ 'firstname' => 'Ben', 'surname' => 'Longden' - ) + ] ); $result = json_decode($hal->asJson(true)); @@ -252,13 +252,13 @@ public function testAttributesInXmlRepresentation() { $hal = new Hal( '/', - array( - 'error' => array( + [ + 'error' => [ '@id' => 6, '@xml:lang' => 'en', 'message' => 'This is a message' - ) - ) + ] + ] ); $xml = new \SimpleXMLElement($hal->asXml()); @@ -272,15 +272,10 @@ public function testAttributesInXmlRepresentation() $this->assertEquals('This is a message', $json->error->message); } - /** - * @covers \Nocarrier\Hal::addLink - * @covers \Nocarrier\Hal::addHalLink - * @covers \Nocarrier\HalJsonRenderer::linksForJson - */ public function testLinkAttributesInJson() { $hal = new Hal('http://example.com/'); - $hal->addLink('test', '/test/{?id}', array( + $hal->addLink('test', '/test/{?id}', [ 'anchor' => '#foo', 'rev' => 'canonical', 'hreflang' => 'en', @@ -289,7 +284,7 @@ public function testLinkAttributesInJson() 'templated' => 'true', 'name' => 'ex', 'title' => 'My Test' - )); + ]); $result = json_decode($hal->asJson()); $this->assertEquals('#foo', $result->_links->test->anchor); @@ -303,13 +298,12 @@ public function testLinkAttributesInJson() } /** - * @covers \Nocarrier\HalJsonRenderer::linksForJson * Provided for code coverage */ public function testLinkAttributesInJsonWithArrayOfLinks() { $hal = new Hal('http://example.com/'); - $hal->addLink('test', '/test/{?id}', array( + $hal->addLink('test', '/test/{?id}', [ 'anchor' => '#foo1', 'rev' => 'canonical1', 'hreflang' => 'en1', @@ -317,8 +311,8 @@ public function testLinkAttributesInJsonWithArrayOfLinks() 'type' => 'text/html1', 'templated' => 'true1', 'name' => 'ex1', - )); - $hal->addLink('test', '/test/{?id}', array( + ]); + $hal->addLink('test', '/test/{?id}', [ 'anchor' => '#foo2', 'rev' => 'canonical2', 'hreflang' => 'en2', @@ -326,7 +320,7 @@ public function testLinkAttributesInJsonWithArrayOfLinks() 'type' => 'text/html2', 'templated' => 'true2', 'name' => 'ex2', - )); + ]); $result = json_decode($hal->asJson()); $i = 1; @@ -342,15 +336,10 @@ public function testLinkAttributesInJsonWithArrayOfLinks() } } - /** - * @covers \Nocarrier\Hal::addLink - * @covers \Nocarrier\Hal::addHalLink - * @covers \Nocarrier\HalXmlRenderer::linksForXml - */ public function testLinkAttributesInXml() { $hal = new Hal('http://example.com/'); - $hal->addLink('test', '/test/{?id}', array( + $hal->addLink('test', '/test/{?id}', [ 'anchor' => '#foo', 'rev' => 'canonical', 'hreflang' => 'en', @@ -358,7 +347,7 @@ public function testLinkAttributesInXml() 'type' => 'text/html', 'templated' => 'true', 'name' => 'ex', - )); + ]); $result = new \SimpleXmlElement($hal->asXml()); $data = $result->link->attributes(); @@ -372,13 +361,12 @@ public function testLinkAttributesInXml() } /** - * @covers \Nocarrier\HalXmlRenderer::linksForXml * Provided for code coverage. */ public function testLinkAttributesInXmlWithArrayOfLinks() { $hal = new Hal('http://example.com/'); - $hal->addLink('test', '/test/{?id}', array( + $hal->addLink('test', '/test/{?id}', [ 'anchor' => '#foo1', 'rev' => 'canonical1', 'hreflang' => 'en1', @@ -386,8 +374,8 @@ public function testLinkAttributesInXmlWithArrayOfLinks() 'type' => 'text/html1', 'templated' => 'true1', 'name' => 'ex1', - )); - $hal->addLink('test', '/test/{?id}', array( + ]); + $hal->addLink('test', '/test/{?id}', [ 'anchor' => '#foo2', 'rev' => 'canonical2', 'hreflang' => 'en2', @@ -395,7 +383,7 @@ public function testLinkAttributesInXmlWithArrayOfLinks() 'type' => 'text/html2', 'templated' => 'true2', 'name' => 'ex2', - )); + ]); $result = new \SimpleXmlElement($hal->asXml()); $i = 1; @@ -414,12 +402,12 @@ public function testLinkAttributesInXmlWithArrayOfLinks() public function testNumericKeysUseParentAsXmlElementName() { - $hal = new Hal('/', array( - 'foo' => array( + $hal = new Hal('/', [ + 'foo' => [ 'bar', 'baz', - ), - )); + ], + ]); $result = new \SimpleXmlElement($hal->asXml()); @@ -428,7 +416,7 @@ public function testNumericKeysUseParentAsXmlElementName() $json = json_decode($hal->asJson(), true); - $this->assertEquals(array('bar', 'baz'), $json['foo']); + $this->assertEquals(['bar', 'baz'], $json['foo']); } public function testMinimalHalJsonDecoding() @@ -461,7 +449,7 @@ public function testHalXmlDecodeWithData() public function testHalJsonDecodeWithLinks() { - $x = new Hal('/test', array('name' => "Ben Longden")); + $x = new Hal('/test', ['name' => "Ben Longden"]); $x->addLink('a', '/a'); $y = Hal::fromJson($x->asJson()); @@ -470,7 +458,7 @@ public function testHalJsonDecodeWithLinks() public function testHalXmlDecodeWithLinks() { - $x = new Hal('/test', array('name' => "Ben Longden")); + $x = new Hal('/test', ['name' => "Ben Longden"]); $x->addLink('a', '/a'); $y = Hal::fromXml($x->asXml()); $this->assertEquals($x->asXml(), $y->asXml()); @@ -478,7 +466,7 @@ public function testHalXmlDecodeWithLinks() public function testHalXmlEntitySetWhenValueSpecifiedInData() { - $x = new Hal('/', array('x' => array('value' => 'test'))); + $x = new Hal('/', ['x' => ['value' => 'test']]); $xml = new \SimpleXMLElement($x->asXml()); $this->assertEquals('test', (string)$xml->x); @@ -486,7 +474,7 @@ public function testHalXmlEntitySetWhenValueSpecifiedInData() public function testHalXmlEntitySetWhenValueSpecifiedInMultiData() { - $x = new Hal('/', array('x' => array('key' => 'test', 'value' => 'test'))); + $x = new Hal('/', ['x' => ['key' => 'test', 'value' => 'test']]); $xml = new \SimpleXMLElement($x->asXml()); $this->assertEquals('test', (string)$xml->x->key); @@ -494,10 +482,10 @@ public function testHalXmlEntitySetWhenValueSpecifiedInMultiData() } public function testBooleanOutput() { - $hal = new Hal('/', array( + $hal = new Hal('/', [ 'foo' => true, 'bar' => false - )); + ]); $xml = new \SimpleXMLElement($hal->asXml()); $this->assertSame('1', (string)$xml->foo); @@ -513,7 +501,7 @@ public function testAddCurieConformsToSpecification() $x = new Hal('/orders'); $x->addCurie('acme', 'http://docs.acme.com/relations/{rel}'); $obj = json_decode($x->asJson()); - $this->assertInternalType('array', $obj->_links->curies); + $this->assertIsArray($obj->_links->curies); $this->assertTrue($obj->_links->curies[0]->templated); $this->assertEquals('acme', $obj->_links->curies[0]->name); $this->assertEquals('http://docs.acme.com/relations/{rel}', $obj->_links->curies[0]->href); @@ -598,7 +586,7 @@ public function testResourceWithNullSelfLinkRendersLinksInJson() public function testDataCanBeTraversable() { - $it = new \ArrayIterator(array('traversable' => new \ArrayIterator(array('key' => 'value')))); + $it = new \ArrayIterator(['traversable' => new \ArrayIterator(['key' => 'value'])]); $x = new Hal('', $it); $response = <<assertSame(array(), $hal->asJson(false, false)); + $this->assertSame([], $hal->asJson(false, false)); } public function testSetResourceWithArrayOfResources() { $hal = new Hal('http://example.com/'); - $res1 = new Hal('/resource/1', array('field1' => '1')); - $res2 = new Hal('/resource/2', array('field1' => '2')); - $hal->setResource('resource', array($res1, $res2)); + $res1 = new Hal('/resource/1', ['field1' => '1']); + $res2 = new Hal('/resource/2', ['field1' => '2']); + $hal->setResource('resource', [$res1, $res2]); $resource = json_decode($hal->asJson()); $this->assertInstanceOf('StdClass', $resource->_embedded); - $this->assertInternalType('array', $resource->_embedded->resource); + $this->assertIsArray($resource->_embedded->resource); $this->assertEquals($resource->_embedded->resource[0]->field1, '1'); $this->assertEquals($resource->_embedded->resource[1]->field1, '2'); } @@ -639,7 +627,7 @@ public function testSetResourceThrowsIfNotPassedAHalOrArray() public function testSetResourceJsonResponse() { $hal = new Hal('http://example.com/'); - $res = new Hal('/resource/1', array('field1' => 'value1', 'field2' => 'value2')); + $res = new Hal('/resource/1', ['field1' => 'value1', 'field2' => 'value2']); $hal->setResource('resource', $res); $resource = json_decode($hal->asJson()); @@ -653,7 +641,7 @@ public function testSetResourceJsonResponse() public function testSetResourceXmlResponse() { $hal = new Hal('http://example.com/'); - $res = new Hal('/resource/1', array('field1' => 'value1', 'field2' => 'value2')); + $res = new Hal('/resource/1', ['field1' => 'value1', 'field2' => 'value2']); $hal->setResource('resource', $res); $result = new \SimpleXmlElement($hal->asXml()); @@ -710,7 +698,7 @@ public function testHalJsonDecodeWithSingleEmbeddedItem() } JSON; $resources = Hal::fromJson($sample, 1)->getResources(); - $this->assertInstanceOf('Nocarrier\Hal', $resources['item'][0]); + $this->assertInstanceOf(\Nocarrier\Hal::class, $resources['item'][0]); $data = $resources['item'][0]->getData(); $this->assertEquals('value', $data['key']); } @@ -718,7 +706,7 @@ public function testHalJsonDecodeWithSingleEmbeddedItem() public function testGetFirstResourceReturnsSingleItem() { $hal = new Hal('http://example.com/'); - $res = new Hal('/resource/1', array('field1' => 'value1', 'field2' => 'value2')); + $res = new Hal('/resource/1', ['field1' => 'value1', 'field2' => 'value2']); $hal->setResource('resource', $res); $this->assertEquals($res, $hal->getFirstResource("resource")); @@ -727,19 +715,17 @@ public function testGetFirstResourceReturnsSingleItem() public function testGetFirstResourceReturnsFirstOfMultipleItems() { $hal = new Hal('http://example.com/'); - $res1 = new Hal('/resource/1', array('field1' => 'value1', 'field2' => 'value2')); - $res2 = new Hal('/resource/2', array('field2' => 'value2', 'field2' => 'value2')); + $res1 = new Hal('/resource/1', ['field1' => 'value1', 'field2' => 'value2']); + $res2 = new Hal('/resource/2', ['field2' => 'value2']); $hal->addResource('resource', $res1); $hal->addResource('resource', $res2); $this->assertEquals($res1, $hal->getFirstResource("resource")); } - /** - * @expectedException RuntimeException - */ public function testHalFromJsonThrowsExceptionOnInvalidJSON() { + $this->expectException(\RuntimeException::class); $invalidJson = 'foo'; Hal::fromJson($invalidJson); } @@ -753,7 +739,7 @@ public function testCanDefineThatAttributesShouldNotBeStripped() public function testStripAttributeMarkersIsNotCalledWhenRenderingWithStripAttributesSetToFalse() { - $hal = new Hal('http://example.com/', array('@xml:key' => 'value')); + $hal = new Hal('http://example.com/', ['@xml:key' => 'value']); $hal->setShouldStripAttributes(false); $json = json_decode($hal->asJson(true)); $this->assertEquals('value', $json->{'@xml:key'}); @@ -786,7 +772,7 @@ public function testEmbeddingResourceWithSingleElement() ); $json = json_decode($hal->asJson()); - $this->assertInternalType('array', $json->_embedded->foo->_embedded->bar); + $this->assertIsArray($json->_embedded->foo->_embedded->bar); } public function testErrorAddResource()