Skip to content

Commit

Permalink
Remove dev dependency
Browse files Browse the repository at this point in the history
Remove previously added --ignore-platform-reqs option from composer
install commands and add composer require crwlr/query-string before
running tests on PHP 8.
  • Loading branch information
otsch committed Jun 1, 2022
1 parent 35a361c commit 4ae532e
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
38 changes: 33 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ jobs:
run: php -v

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest --ignore-platform-reqs
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run PHP CS Fixer
run: composer cs

tests:
tests7x:
name: PHPUnit tests
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1']
php-versions: ['7.2', '7.3', '7.4']

steps:
- name: Checkout code
Expand All @@ -45,7 +45,35 @@ jobs:
run: php -v

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest --ignore-platform-reqs
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run tests
run: composer test

tests8x:
name: PHPUnit tests
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.0', '8.1']

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}

- name: Check PHP Version
run: php -v

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Install query-string package
run: composer require crwlr/query-string

- name: Run tests
run: composer test
Expand All @@ -67,7 +95,7 @@ jobs:
run: php -v

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest --ignore-platform-reqs
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run PHPStan
run: composer stan
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
"require-dev": {
"phpunit/phpunit": "^8.0",
"friendsofphp/php-cs-fixer": "^3.4",
"phpstan/phpstan": "^1.3",
"crwlr/query-string": "dev-main"
"phpstan/phpstan": "^1.3"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 5 additions & 4 deletions src/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Url
private $path;

/**
* @phpstan-ignore-next-line
* @var string|Query|null
*/
private $query;
Expand Down Expand Up @@ -492,7 +493,7 @@ public function path(?string $path = null)
public function query(?string $query = null)
{
if ($query === null) {
return $this->query instanceof Query ? $this->query->toString() : $this->query;
return $this->query instanceof Query ? $this->query->toString() : $this->query; // @phpstan-ignore-line
} elseif ($query === '') {
$this->query = null;
} else {
Expand All @@ -512,8 +513,8 @@ public function query(?string $query = null)
public function queryArray(?array $query = null)
{
if ($query === null) {
if ($this->query instanceof Query) {
return $this->query->toArray();
if ($this->query instanceof Query) { // @phpstan-ignore-line
return $this->query->toArray(); // @phpstan-ignore-line
}

return $this->query ? Helpers::queryStringToArray($this->query) : [];
Expand All @@ -527,7 +528,7 @@ public function queryArray(?array $query = null)
/**
* @throws Exception
*/
public function queryString(): Query
public function queryString(): Query // @phpstan-ignore-line
{
if (version_compare(PHP_VERSION, '8.0.0', '<')) {
throw new Exception(
Expand Down
12 changes: 6 additions & 6 deletions tests/QueryStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function testReturnsAnInstanceOfQueryWhenPhpVersion8OrAboveOtherwiseThrow
{
$url = Url::parse('https://www.example.com/path?foo=bar');

if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
if (version_compare(PHP_VERSION, '8.0.0', '>=') && class_exists(Query::class)) {
$this->assertInstanceOf(Query::class, $url->queryString());
} else {
$this->expectException(Exception::class);
Expand All @@ -24,7 +24,7 @@ public function testTheQueryMethodReturnValueIsInSyncWithQueryStringInstance():
{
$url = Url::parse('https://www.example.com/path?foo=bar');

if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
if (version_compare(PHP_VERSION, '8.0.0', '>=') && class_exists(Query::class)) {
$url->queryString()->set('baz', 'quz');

$this->assertEquals('foo=bar&baz=quz', $url->query());
Expand All @@ -39,7 +39,7 @@ public function testTheQueryArrayMethodReturnValueIsInSyncWithQueryStringInstanc
{
$url = Url::parse('https://www.example.com/path?foo=bar');

if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
if (version_compare(PHP_VERSION, '8.0.0', '>=') && class_exists(Query::class)) {
$url->queryString()->set('baz', 'quz');

$this->assertEquals(['foo' => 'bar', 'baz' => 'quz'], $url->queryArray());
Expand All @@ -54,7 +54,7 @@ public function testTheQueryStringCanBeAccessedViaMagicGetter(): void
{
$url = Url::parse('https://www.example.com/path?foo=bar');

if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
if (version_compare(PHP_VERSION, '8.0.0', '>=') && class_exists(Query::class)) {
$url->queryString->set('baz', 'quz'); // @phpstan-ignore-line

$this->assertEquals(['foo' => 'bar', 'baz' => 'quz'], $url->queryArray());
Expand All @@ -69,7 +69,7 @@ public function testItStillWorksToSetTheQueryViaQueryMethodAfterQueryStringWasUs
{
$url = Url::parse('https://www.example.com/path?foo=bar');

if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
if (version_compare(PHP_VERSION, '8.0.0', '>=') && class_exists(Query::class)) {
$url->queryString()->set('baz', 'quz');

$url->query('yo=lo');
Expand All @@ -88,7 +88,7 @@ public function testItStillWorksToSetTheQueryViaQueryArrayMethodAfterQueryString
{
$url = Url::parse('https://www.example.com/path?foo=bar');

if (version_compare(PHP_VERSION, '8.0.0', '>=')) {
if (version_compare(PHP_VERSION, '8.0.0', '>=') && class_exists(Query::class)) {
$url->queryString()->set('baz', 'quz');

$url->queryArray(['boo' => 'yah']);
Expand Down

0 comments on commit 4ae532e

Please sign in to comment.