Skip to content

Commit

Permalink
Add ReturnTypeWillChange attributes and add workflows for PHP8.0 and …
Browse files Browse the repository at this point in the history
…PHP8.1 (#55)

* Add PHP8.0 and 8.1 to test matrix

* Add ReturnTypeWillChange attributes to methods with incompatible return types to support PHP8.1

* Update phpunit requirement to allow for phpunit to be installed on PHP8.0 and PHP8.1

* Replace deprecated and now removed @ExpectedException annotation necessary for upgrade to new phpunit version
  • Loading branch information
PrinsFrank authored Jun 30, 2022
1 parent e9a1287 commit 2b18a2b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.1, 7.2, 7.3, 7.4]
php: [7.1, 7.2, 7.3, 7.4, 8.0, 8.1]
stability: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.3",
"phpunit/phpunit": ">=7.3",
"friendsofphp/php-cs-fixer": "^2.17",
"justinrainbow/json-schema": "^5.2"
},
Expand Down
4 changes: 4 additions & 0 deletions src/Utilities/Extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Extensions implements ArrayAccess
* @param mixed $offset
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
return isset($this->items[$this->normalizeOffset($offset)]);
Expand All @@ -39,6 +40,7 @@ public function offsetExists($offset)
* @throws \GoldSpecDigital\ObjectOrientedOAS\Exceptions\ExtensionDoesNotExistException
* @return mixed can return all value types
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
if (!$this->offsetExists($offset)) {
Expand All @@ -55,6 +57,7 @@ public function offsetGet($offset)
* @param mixed $offset
* @param mixed $value
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
if ($value === static::X_EMPTY_VALUE) {
Expand All @@ -72,6 +75,7 @@ public function offsetSet($offset, $value)
* @link https://php.net/manual/en/arrayaccess.offsetunset.php
* @param mixed $offset
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
if (!$this->offsetExists($offset)) {
Expand Down
4 changes: 3 additions & 1 deletion tests/Objects/ExtensionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace GoldSpecDigital\ObjectOrientedOAS\Tests\Objects;

use GoldSpecDigital\ObjectOrientedOAS\Exceptions\PropertyDoesNotExistException;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Components;
use GoldSpecDigital\ObjectOrientedOAS\Objects\Operation;
use GoldSpecDigital\ObjectOrientedOAS\Objects\PathItem;
Expand Down Expand Up @@ -69,14 +70,15 @@ public function get_single_extension($schema)

/**
* @test
* @expectedException \GoldSpecDigital\ObjectOrientedOAS\Exceptions\PropertyDoesNotExistException
* @dataProvider schemasDataProvider
* @param string|\GoldSpecDigital\ObjectOrientedOAS\Objects\Schema $schema
*/
public function get_single_extension_does_not_exist($schema)
{
$object = $schema::create()->x('foo', 'bar');

$this->expectException(PropertyDoesNotExistException::class);
$this->expectExceptionMessage('[x-key] is not a valid property');
$this->assertEquals('bar', $object->{'x-key'});
}

Expand Down

0 comments on commit 2b18a2b

Please sign in to comment.