Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
- 8.1
- 8.2
- 8.3
- 8.4
- 8.5

steps:
- name: Checkout code
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 @@
},
"require-dev": {
"jerodev/code-styles": "dev-master",
"phpunit/phpunit": "^9.4"
"phpunit/phpunit": "^10"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
803 changes: 380 additions & 423 deletions composer.lock

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="DataMapper">
Expand Down
8 changes: 1 addition & 7 deletions src/Objects/ClassResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,8 @@ private function findSourceFile(): ?string
$backtrace = \debug_backtrace(\DEBUG_BACKTRACE_IGNORE_ARGS, 10);
$mapperFileSuffix = \implode(\DIRECTORY_SEPARATOR, ['data-mapper', 'src', 'Mapper.php']);

$foundMapper = false;
foreach ($backtrace as $trace) {
if (\str_ends_with($trace['file'], $mapperFileSuffix)) {
$foundMapper = true;
continue;
}

if ($foundMapper) {
if (\array_key_exists('file', $trace) && \str_ends_with($trace['file'], $mapperFileSuffix)) {
return $trace['file'];
}
}
Expand Down
18 changes: 8 additions & 10 deletions tests/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
use Jerodev\DataMapper\Tests\_Mocks\SuitEnum;
use Jerodev\DataMapper\Tests\_Mocks\SuperUserDto;
use Jerodev\DataMapper\Tests\_Mocks\UserDto;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class MapperTest extends TestCase
{
/**
* @test
* @dataProvider nativeValuesDataProvider
*/
#[Test]
#[DataProvider('nativeValuesDataProvider')]
public function it_should_map_native_values(string $type, mixed $value, mixed $expectation): void
{
$this->assertSame($expectation, (new Mapper())->map($type, $value));
}

/** @test */
#[Test]
public function it_should_map_nullable_objects_from_empty_array(): void
{
$options = new MapperConfig();
Expand All @@ -41,10 +41,8 @@ public function it_should_map_nullable_objects_from_empty_array(): void
$this->assertInstanceOf(Nullable::class, $mapper->map(Nullable::class, []));
}

/**
* @test
* @dataProvider objectValuesDataProvider
*/
#[Test]
#[DataProvider('objectValuesDataProvider')]
public function it_should_map_objects(string $type, mixed $value, mixed $expectation): void
{
$config = new MapperConfig();
Expand All @@ -53,7 +51,7 @@ public function it_should_map_objects(string $type, mixed $value, mixed $expecta
$this->assertEquals($expectation, (new Mapper($config))->map($type, $value));
}

/** @test */
#[Test]
public function it_should_throw_on_unexpected_null_value(): void
{
$config = new MapperConfig();
Expand Down
8 changes: 4 additions & 4 deletions tests/Objects/ClassBluePrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
use Jerodev\DataMapper\Tests\_Mocks\UserDto;
use Jerodev\DataMapper\Types\DataType;
use Jerodev\DataMapper\Types\DataTypeCollection;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class ClassBluePrinterTest extends TestCase
{
/**
* @test
* @dataProvider classBlueprintDataProvider
*/
#[Test]
#[DataProvider('classBlueprintDataProvider')]
public function it_should_blueprint_classes(string $className, array $constructorArguments = [], array $properties = []): void
{
$blueprint = (new ClassBluePrinter())->print($className);
Expand Down
8 changes: 4 additions & 4 deletions tests/Objects/DocBlockParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

use Generator;
use Jerodev\DataMapper\Objects\DocBlockParser;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class DocBlockParserTest extends TestCase
{
/**
* @test
* @dataProvider docBlockDataProvider
*/
#[Test]
#[DataProvider('docBlockDataProvider')]
public function it_should_parse_doc_blocks(string $input, array $paramTypes = [], ?string $returnType = null, ?string $varType = null): void
{
$doc = (new DocBlockParser())->parse($input);
Expand Down
15 changes: 8 additions & 7 deletions tests/Objects/ObjectMapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
use Jerodev\DataMapper\Tests\_Mocks\SelfMapped;
use Jerodev\DataMapper\Tests\_Mocks\SuitEnum;
use Jerodev\DataMapper\Types\DataType;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use ValueError;

class ObjectMapperTest extends TestCase
final class ObjectMapperTest extends TestCase
{
/** @test */
#[Test]
public function it_should_generate_cache_key_based_on_config(): void
{
$classname = 'A' . \uniqid();
Expand Down Expand Up @@ -65,7 +66,7 @@ final class {$classname}
\unlink($filename);
}

/** @test */
#[Test]
public function it_should_let_classes_map_themselves(): void
{
$value = (new ObjectMapper(new Mapper()))->map(
Expand All @@ -81,7 +82,7 @@ public function it_should_let_classes_map_themselves(): void
$this->assertEquals(['John Doe', 'Jane Doe'], $value->users);
}

/** @test */
#[Test]
public function it_should_not_retain_mapper_files_in_debug_mode(): void
{
$config = new MapperConfig();
Expand All @@ -99,7 +100,7 @@ public function it_should_not_retain_mapper_files_in_debug_mode(): void
$this->assertEmpty(\glob($filePattern));
}

/** @test */
#[Test]
public function it_should_parse_enum_using_tryfrom_if_configured(): void
{
$config = new MapperConfig();
Expand All @@ -113,7 +114,7 @@ public function it_should_parse_enum_using_tryfrom_if_configured(): void
$this->assertNull($value);
}

/** @test */
#[Test]
public function it_should_save_mappers_in_cache_directory(): void
{
$config = new MapperConfig();
Expand All @@ -131,7 +132,7 @@ public function it_should_save_mappers_in_cache_directory(): void
\rmdir($config->classMapperDirectory);
}

/** @test */
#[Test]
public function it_should_throw_on_invalid_enum_value(): void
{
$this->expectException(ValueError::class);
Expand Down
20 changes: 8 additions & 12 deletions tests/Types/DataTypeFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,30 @@
use Jerodev\DataMapper\Types\DataType;
use Jerodev\DataMapper\Types\DataTypeCollection;
use Jerodev\DataMapper\Types\DataTypeFactory;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

final class DataTypeFactoryTest extends TestCase
{
/**
* @test
* @dataProvider singleDataTypeProvider
*/
#[Test]
#[DataProvider('singleDataTypeProvider')]
public function it_should_parse_single_data_types(string $input, DataType $expectation): void
{
$this->assertEquals($expectation, (new DataTypeFactory())->fromString($input)->types[0]);
}

/**
* @test
* @dataProvider unexpectedTokenDataProvider
*/
#[Test]
#[DataProvider('unexpectedTokenDataProvider')]
public function it_should_throw_unexpected_token(string $input): void
{
$this->expectException(UnexpectedTokenException::class);

(new DataTypeFactory())->fromString($input);
}

/**
* @test
* @dataProvider typeToStringDataProvider
*/
#[Test]
#[DataProvider('typeToStringDataProvider')]
public function it_should_parse_and_convert_back_to_string(string $input, string $expectation): void
{
$factory = new DataTypeFactory();
Expand Down