Skip to content

Commit

Permalink
Add PHPUnit 10 Support (#7)
Browse files Browse the repository at this point in the history
* Add PHPUnit 10 Support

* add no-coverage
  • Loading branch information
sweptsquash authored Feb 16, 2023
1 parent 1f01ff8 commit e7f89b8
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 57 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Check & fix styling
name: Fix PHP code style issues

on: [push]

jobs:
php-cs-fixer:
php-code-styling:
runs-on: ubuntu-latest

steps:
Expand All @@ -12,10 +12,8 @@ jobs:
with:
ref: ${{ github.head_ref }}

- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes
- name: Fix PHP code style issues
uses: aglipanci/[email protected]

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.1, 8.2]
php: [8.2]
stability: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
Expand All @@ -34,4 +34,4 @@ jobs:
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/phpunit
run: vendor/bin/phpunit --no-coverage
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
.php_cs
.php_cs.cache
.phpunit.cache
.phpunit.result.cache
build
composer.lock
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
],
"homepage": "https://github.com/antoninmasek/simple-hydrator",
"require": {
"php": "^8.1|^8.2",
"phpunit/phpunit": "^10.0"
"php": "^8.2",
"phpunit/phpunit": "^9.5 || ^10.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"spatie/ray": "^1.28"
"laravel/pint": "^1.5",
"spatie/ray": "^1.32.2"
},
"minimum-stability": "dev",
"minimum-stability": "stable",
"prefer-stable": true,
"autoload": {
"psr-4": {
Expand All @@ -41,8 +41,8 @@
"sort-packages": true
},
"scripts": {
"format": "vendor/bin/php-cs-fixer fix --allow-risky=yes",
"test": "vendor/bin/phpunit",
"lint": "vendor/bin/pint",
"test": "vendor/bin/phpunit --no-coverage",
"test-coverage": "vendor/bin/phpunit --coverage"
}
}
17 changes: 16 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="AntoninMasek Test Suite">
<directory>tests</directory>
Expand Down
5 changes: 3 additions & 2 deletions src/Casters/Caster.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function existsFor(string $className): bool
public static function make(string $className): Caster
{
$casterClassNameOrCallable = ! array_key_exists($className, self::$casters)
? self::CASTERS_NAMESPACE . "\\$className" . self::CASTERS_SUFFIX
? self::CASTERS_NAMESPACE."\\$className".self::CASTERS_SUFFIX
: self::$casters[$className];

if (is_callable($casterClassNameOrCallable)) {
Expand All @@ -70,7 +70,8 @@ public static function make(string $className): Caster

private static function handleCallableCaster($callable): Caster
{
return new class($callable) extends Caster {
return new class($callable) extends Caster
{
public function __construct(private mixed $callable)
{
}
Expand Down
4 changes: 2 additions & 2 deletions src/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public static function collectionFromArray(array $data = []): ?array

public function set(string $propertyName, mixed $value): static
{
$clone = clone $this;
$clone = clone $this;
$reflectionClass = new \ReflectionObject($clone);
$properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);
$properties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);

foreach ($properties as $property) {
$name = $property->getName();
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/InvalidCasterException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class InvalidCasterException extends \Exception
{
public function __construct()
{
parent::__construct('All casters have to extend ' . Caster::class);
parent::__construct('All casters have to extend '.Caster::class);
}
}
2 changes: 1 addition & 1 deletion src/Hydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static function hydrate(string $className, array $data = null): ?object
return null;
}

$reflectionClass = new \ReflectionObject($dto = new $className());
$reflectionClass = new \ReflectionObject($dto = new $className());
$publicProperties = $reflectionClass->getProperties(\ReflectionProperty::IS_PUBLIC);

foreach ($publicProperties as $property) {
Expand Down
70 changes: 35 additions & 35 deletions tests/SimpleHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ protected function setUp(): void
Caster::clearCasters();

$this->data = [
'name' => 'John',
'kids' => 0,
'name' => 'John',
'kids' => 0,
'dateOfBirth' => '1969-07-20',
'money' => 33.3,
'male' => true,
'items' => ['phone', 'wallet', 'keys'],
'car' => null,
'mother' => [
'name' => 'Jane',
'kids' => 2,
'money' => 33.3,
'male' => true,
'items' => ['phone', 'wallet', 'keys'],
'car' => null,
'mother' => [
'name' => 'Jane',
'kids' => 2,
'money' => 66.6,
'male' => false,
'male' => false,
'items' => ['phone', 'keys'],
'car' => [
'type' => '911',
'car' => [
'type' => '911',
'brand' => 'Porsche',
],
],
Expand Down Expand Up @@ -214,7 +214,7 @@ public function testItIsPossibleToWriteAnonymousCaster()

public function testItIsPossibleToOverwriteDefaultCaster()
{
$data = $this->data;
$data = $this->data;
$data['dateOfBirth'] = -14256000;

Caster::registerCaster(\DateTime::class, function ($value) {
Expand All @@ -241,14 +241,14 @@ public function testCastACollectionOfObjects()
{
$data = [
'brand' => 'Chevrolet',
'type' => 'Camaro',
'keys' => [
'type' => 'Camaro',
'keys' => [
[
'name' => 'main',
'name' => 'main',
'is_active' => true,
],
[
'name' => 'secondary',
'name' => 'secondary',
'is_active' => false,
],
],
Expand All @@ -272,8 +272,8 @@ public function testCastedCollectionOfObjectsCanBeSetToNull()
{
$data = [
'brand' => 'Chevrolet',
'type' => 'Camaro',
'keys' => null,
'type' => 'Camaro',
'keys' => null,
];

/** @var Car $camaro */
Expand All @@ -286,14 +286,14 @@ public function testRegisteredCastersAreUsedForCollections()
{
$data = [
'brand' => 'Chevrolet',
'type' => 'Camaro',
'keys' => [
'type' => 'Camaro',
'keys' => [
[
'name' => 'main',
'name' => 'main',
'is_active' => true,
],
[
'name' => 'secondary',
'name' => 'secondary',
'is_active' => false,
],
],
Expand All @@ -319,13 +319,13 @@ public function testItIsPossibleToParseAListArray()
$array = [
$this->data,
[
'name' => 'Jane',
'kids' => 0,
'name' => 'Jane',
'kids' => 0,
'dateOfBirth' => '1969-08-19',
'money' => 35.3,
'male' => true,
'items' => ['phone', 'wallet', 'keys'],
'car' => null,
'money' => 35.3,
'male' => true,
'items' => ['phone', 'wallet', 'keys'],
'car' => null,
],
];

Expand All @@ -340,13 +340,13 @@ public function testItThrowsExceptionWhenListIsUsedWithFromArrayMethod()
$array = [
$this->data,
[
'name' => 'Jane',
'kids' => 0,
'name' => 'Jane',
'kids' => 0,
'dateOfBirth' => '1969-08-19',
'money' => 35.3,
'male' => true,
'items' => ['phone', 'wallet', 'keys'],
'car' => null,
'money' => 35.3,
'male' => true,
'items' => ['phone', 'wallet', 'keys'],
'car' => null,
],
];

Expand Down

0 comments on commit e7f89b8

Please sign in to comment.