Skip to content

Commit

Permalink
Adapt tests to php 8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
compositephp committed Dec 23, 2024
1 parent 9ea89dd commit 6def72b
Show file tree
Hide file tree
Showing 19 changed files with 90 additions and 167 deletions.
5 changes: 5 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" bootstrap="vendor/autoload.php"
executionOrder="depends,defects" beStrictAboutOutputDuringTests="true" failOnRisky="true" failOnWarning="true"
colors="true" cacheDirectory=".phpunit.cache" requireCoverageMetadata="false"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnPhpunitDeprecations="true"
beStrictAboutCoverageMetadata="true">
<testsuites>
<testsuite name="default">
Expand Down
9 changes: 3 additions & 6 deletions tests/AbstractEntityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Composite\Entity\AbstractEntity;
use Composite\Entity\Helpers\DateTimeHelper;
use Composite\Entity\Tests\TestStand\TestSubEntity;
use PHPUnit\Framework\Attributes\DataProvider;

final class AbstractEntityTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -76,9 +77,7 @@ public function __construct(
];
}

/**
* @dataProvider hydration_dataProvider
*/
#[DataProvider('hydration_dataProvider')]
public function test_hydration(AbstractEntity $entity, array $expected): void
{
$actual = $entity->toArray();
Expand Down Expand Up @@ -131,9 +130,7 @@ public static function changedColumns_dataProvider(): array
];
}

/**
* @dataProvider changedColumns_dataProvider
*/
#[DataProvider('changedColumns_dataProvider')]
public function test_changedColumns(array $createData, array $expectedChangedColumns): void
{
$entity = TestStand\TestAutoIncrementEntity::fromArray($createData);
Expand Down
75 changes: 27 additions & 48 deletions tests/ColumnBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Composite\Entity\Attributes\SkipSerialization;
use Composite\Entity\Columns\AbstractColumn;
use Composite\Entity\Tests\TestStand\TestSubEntity;
use PHPUnit\Framework\Attributes\DataProvider;

final class ColumnBuilderTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -51,9 +52,7 @@ public function __construct(
];
}

/**
* @dataProvider visibility_dataProvider
*/
#[DataProvider('visibility_dataProvider')]
public function test_visibility(AbstractEntity $entity, array $expected): void
{
$schema = $entity::schema();
Expand Down Expand Up @@ -90,9 +89,7 @@ public static function type_dataProvider(): array
];
}

/**
* @dataProvider type_dataProvider
*/
#[DataProvider('type_dataProvider')]
public function test_type(AbstractEntity $entity, array $expected): void
{
$schema = $entity::schema();
Expand Down Expand Up @@ -124,9 +121,7 @@ public function __construct(
];
}

/**
* @dataProvider hasDefaultValue_dataProvider
*/
#[DataProvider('hasDefaultValue_dataProvider')]
public function test_hasDefaultValue(AbstractEntity $class, array $expected): void
{
$schema = $class::schema();
Expand Down Expand Up @@ -168,9 +163,7 @@ public static function defaultValue_dataProvider(): array
];
}

/**
* @dataProvider defaultValue_dataProvider
*/
#[DataProvider('defaultValue_dataProvider')]
public function test_defaultValue(AbstractEntity $entity, array $expected): void
{
$schema = $entity::schema();
Expand Down Expand Up @@ -214,9 +207,7 @@ public function __construct(
];
}

/**
* @dataProvider isNullable_dataProvider
*/
#[DataProvider('isNullable_dataProvider')]
public function test_isNullable(AbstractEntity $class, array $expected): void
{
$schema = $class::schema();
Expand All @@ -226,29 +217,6 @@ public function test_isNullable(AbstractEntity $class, array $expected): void
}
}

public static function isReadOnly_dataProvider(): array
{
return [
[
'class' => new class extends AbstractEntity {
public string $foo2 = 'foo';
public readonly ?string $bar2;

public function __construct(
public string $foo1 = 'foo',
public readonly ?string $bar1 = null,
) {}
},
'expected' => [
'foo1' => false,
'bar1' => true,
'foo2' => false,
'bar2' => true,
]
],
];
}

public static function isConstructorPromoted_dataProvider(): array
{
return [
Expand All @@ -272,9 +240,7 @@ public function __construct(
];
}

/**
* @dataProvider isConstructorPromoted_dataProvider
*/
#[DataProvider('isConstructorPromoted_dataProvider')]
public function test_isConstructorPromoted(AbstractEntity $entity, array $expected): void
{
$schema = $entity::schema();
Expand All @@ -284,11 +250,26 @@ public function test_isConstructorPromoted(AbstractEntity $entity, array $expect
}
}

/**
* @dataProvider isReadOnly_dataProvider
*/
public function test_isReadOnly(AbstractEntity $entity, array $expected): void
public function test_isReadOnly(): void
{
$entity = new class extends AbstractEntity {
public string $foo2 = 'foo';
public readonly ?string $bar2;

public function __construct(
public string $foo1 = 'foo',
public readonly ?string $bar1 = null,
) {
}
};

$expected = [
'foo1' => false,
'bar1' => true,
'foo2' => false,
'bar2' => true,
];

$schema = $entity::schema();
foreach ($expected as $name => $expectedIsReadOnly) {
$this->assertNotNull($schema->getColumn($name));
Expand Down Expand Up @@ -321,9 +302,7 @@ public static function notSupported_dataProvider(): array
];
}

/**
* @dataProvider notSupported_dataProvider
*/
#[DataProvider('notSupported_dataProvider')]
public function test_notSupported(AbstractEntity $entity): void
{
try {
Expand Down
9 changes: 3 additions & 6 deletions tests/Columns/ArrayColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composite\Entity\AbstractEntity;
use Composite\Entity\Exceptions\EntityException;
use PHPUnit\Framework\Attributes\DataProvider;

final class ArrayColumnTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -45,9 +46,7 @@ public static function cast_dataProvider(): array
];
}

/**
* @dataProvider cast_dataProvider
*/
#[DataProvider('cast_dataProvider')]
public function test_cast(mixed $value, ?array $expected): void
{
$class = new class extends AbstractEntity {
Expand Down Expand Up @@ -81,9 +80,7 @@ public static function uncast_dataProvider(): array
];
}

/**
* @dataProvider uncast_dataProvider
*/
#[DataProvider('uncast_dataProvider')]
public function test_uncast(mixed $value, mixed $expected): void
{
$entity = new class($value) extends AbstractEntity {
Expand Down
9 changes: 3 additions & 6 deletions tests/Columns/BackedEnumColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composite\Entity\AbstractEntity;
use Composite\Entity\Tests\TestStand\TestBackedStringEnum;
use PHPUnit\Framework\Attributes\DataProvider;

final class BackedEnumColumnTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -41,9 +42,7 @@ public static function cast_dataProvider(): array
];
}

/**
* @dataProvider cast_dataProvider
*/
#[DataProvider('cast_dataProvider')]
public function test_cast(mixed $value, ?TestBackedStringEnum $expected): void
{
$class = new class extends AbstractEntity {
Expand Down Expand Up @@ -73,9 +72,7 @@ public static function uncast_dataProvider(): array
];
}

/**
* @dataProvider uncast_dataProvider
*/
#[DataProvider('uncast_dataProvider')]
public function test_uncast(mixed $value, mixed $expected): void
{
$entity = new class($value) extends AbstractEntity {
Expand Down
9 changes: 3 additions & 6 deletions tests/Columns/BackedIntEnumColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composite\Entity\AbstractEntity;
use Composite\Entity\Tests\TestStand\TestBackedIntEnum;
use PHPUnit\Framework\Attributes\DataProvider;

final class BackedIntEnumColumnTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -45,9 +46,7 @@ public static function cast_dataProvider(): array
];
}

/**
* @dataProvider cast_dataProvider
*/
#[DataProvider('cast_dataProvider')]
public function test_cast(mixed $value, ?TestBackedIntEnum $expected): void
{
$class = new class extends AbstractEntity {
Expand Down Expand Up @@ -77,9 +76,7 @@ public static function uncast_dataProvider(): array
];
}

/**
* @dataProvider uncast_dataProvider
*/
#[DataProvider('uncast_dataProvider')]
public function test_uncast(mixed $value, mixed $expected): void
{
$entity = new class($value) extends AbstractEntity {
Expand Down
9 changes: 3 additions & 6 deletions tests/Columns/BackedStringEnumColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composite\Entity\AbstractEntity;
use Composite\Entity\Tests\TestStand\TestBackedStringEnum;
use PHPUnit\Framework\Attributes\DataProvider;

final class BackedStringEnumColumnTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -45,9 +46,7 @@ public static function cast_dataProvider(): array
];
}

/**
* @dataProvider cast_dataProvider
*/
#[DataProvider('cast_dataProvider')]
public function test_cast(mixed $value, ?TestBackedStringEnum $expected): void
{
$class = new class extends AbstractEntity {
Expand Down Expand Up @@ -77,9 +76,7 @@ public static function uncast_dataProvider(): array
];
}

/**
* @dataProvider uncast_dataProvider
*/
#[DataProvider('uncast_dataProvider')]
public function test_uncast(mixed $value, mixed $expected): void
{
$entity = new class($value) extends AbstractEntity {
Expand Down
9 changes: 3 additions & 6 deletions tests/Columns/BoolColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Composite\Entity\Tests\Columns;

use Composite\Entity\AbstractEntity;
use PHPUnit\Framework\Attributes\DataProvider;

final class BoolColumnTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -60,9 +61,7 @@ public static function cast_dataProvider(): array
];
}

/**
* @dataProvider cast_dataProvider
*/
#[DataProvider('cast_dataProvider')]
public function test_cast(mixed $value, ?bool $expected): void
{
$class = new class extends AbstractEntity {
Expand Down Expand Up @@ -92,9 +91,7 @@ public static function uncast_dataProvider(): array
];
}

/**
* @dataProvider uncast_dataProvider
*/
#[DataProvider('uncast_dataProvider')]
public function test_uncast(mixed $value, mixed $expected): void
{
$entity = new class($value) extends AbstractEntity {
Expand Down
9 changes: 3 additions & 6 deletions tests/Columns/CastableColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composite\Entity\AbstractEntity;
use Composite\Entity\Tests\TestStand\TestCastableIntObject;
use PHPUnit\Framework\Attributes\DataProvider;

final class CastableColumnTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -35,9 +36,7 @@ public static function cast_dataProvider(): array
];
}

/**
* @dataProvider cast_dataProvider
*/
#[DataProvider('cast_dataProvider')]
public function test_cast(mixed $value, ?TestCastableIntObject $expected): void
{
$class = new class extends AbstractEntity {
Expand Down Expand Up @@ -65,9 +64,7 @@ public static function uncast_dataProvider(): array
];
}

/**
* @dataProvider uncast_dataProvider
*/
#[DataProvider('uncast_dataProvider')]
public function test_uncast(mixed $value, mixed $expected): void
{
$entity = new class($value) extends AbstractEntity {
Expand Down
Loading

0 comments on commit 6def72b

Please sign in to comment.