diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e2951595..3247fc22 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -1,52 +1,59 @@ name: run-tests on: - push: - pull_request: - schedule: - - cron: '0 0 * * *' + push: + pull_request: + schedule: + - cron: '0 0 * * *' jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - php: [8.2, 8.1, 8.0] - laravel: [9.*, 10.*] - dependency-version: [prefer-lowest, prefer-stable] - include: - - laravel: 10.* - testbench: 8.* - - laravel: 9.* - testbench: 7.* - exclude: - - laravel: 10.* - php: 8.0 - - name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick - coverage: none - - - name: Create database - run: | - sudo /etc/init.d/mysql start - mysql -u root -proot -e 'CREATE DATABASE IF NOT EXISTS laravel_event_sourcing;' - - - name: Install dependencies - run: | - composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:^2.63" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update - composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest - - - name: Execute tests - run: vendor/bin/pest - env: - DB_PASSWORD: root + test: + runs-on: ubuntu-latest + + strategy: + matrix: + php: [8.2, 8.1, 8.0] + laravel: ['9.*', '10.*', '11.*'] + dependency-version: [prefer-lowest, prefer-stable] + include: + - laravel: 10.* + testbench: 8.* + - laravel: 9.* + testbench: 7.* + - laravel: 11.* + testbench: 9.* + exclude: + - laravel: 10.* + php: 8.0 + - laravel: 11.* + php: 8.1 + - laravel: 11.* + php: 8.0 + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, mysql, mysqli, pdo_mysql, bcmath, soap, intl, gd, exif, iconv, imagick + coverage: none + + - name: Create database + run: | + sudo /etc/init.d/mysql start + mysql -u root -proot -e 'CREATE DATABASE IF NOT EXISTS laravel_event_sourcing;' + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "nesbot/carbon:^2.63" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest + + - name: Execute tests + run: vendor/bin/pest + env: + DB_PASSWORD: root diff --git a/.gitignore b/.gitignore index c655988a..89f4efc4 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ coverage .phpunit.result.cache .php_cs.cache .php-cs-fixer.cache +.phpunit.cache \ No newline at end of file diff --git a/composer.json b/composer.json index 62089363..e215d858 100644 --- a/composer.json +++ b/composer.json @@ -23,28 +23,28 @@ "require": { "php": "^8.0", "ext-json": "*", - "illuminate/console": "^9.0|^10.0", - "illuminate/database": "^9.0|^10.0", - "illuminate/events": "^9.0|^10.0", - "illuminate/support": "^9.0|^10.0", + "illuminate/console": "^9.0|^10.0|^11.0", + "illuminate/database": "^9.0|^10.0|^11.0", + "illuminate/events": "^9.0|^10.0|^11.0", + "illuminate/support": "^9.0|^10.0|^11.0", "phpdocumentor/reflection-docblock": "^5.2", - "spatie/better-types": "^0.1.2", + "spatie/better-types": "^0.2.0", "spatie/laravel-package-tools": "^1.9", "spatie/laravel-schemaless-attributes": "^2.0", - "symfony/finder": "^6.0", - "symfony/property-access": "^6.0", - "symfony/property-info": "^6.0", - "symfony/serializer": "^6.0" + "symfony/finder": "^6.0|^7.0", + "symfony/property-access": "^6.0|^7.0", + "symfony/property-info": "^6.0|^7.0", + "symfony/serializer": "^6.0|^7.0" }, "require-dev": { "laravel/horizon": "^5.7", "mockery/mockery": "^1.4", - "orchestra/testbench": "^7.0|^8.0", - "pestphp/pest": "^1.22", - "phpunit/phpunit": "^9.5.10", + "orchestra/testbench": "^7.0|^8.0|^9.0", + "pestphp/pest": "^1.22|^2.34", + "phpunit/phpunit": "^9.5.10|^10.5", "spatie/fork": "^1.0", - "spatie/pest-plugin-snapshots": "^1.1", - "spatie/phpunit-snapshot-assertions": "^4.0" + "spatie/pest-plugin-snapshots": "^1.1|^2.1", + "spatie/phpunit-snapshot-assertions": "^4.0|^5.1" }, "autoload": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 16487091..59d9e7b4 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,5 @@ - - - - src/ - - + tests @@ -18,4 +13,9 @@ + + + src/ + + diff --git a/src/Support/CarbonNormalizer.php b/src/Support/CarbonNormalizer.php index 0b904bd3..b8c7477f 100644 --- a/src/Support/CarbonNormalizer.php +++ b/src/Support/CarbonNormalizer.php @@ -25,7 +25,7 @@ public function normalize(mixed $object, string $format = null, array $context = /** * @inheritdoc */ - public function supportsNormalization(mixed $data, string $format = null): bool + public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool { return $data instanceof CarbonInterface; } @@ -41,7 +41,7 @@ public function denormalize(mixed $data, string $class, string $format = null, a /** * @inheritDoc */ - public function supportsDenormalization(mixed $data, string $type, string $format = null): bool + public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool { return is_a($type, CarbonInterface::class, true); } diff --git a/src/Support/ModelIdentifierNormalizer.php b/src/Support/ModelIdentifierNormalizer.php index 18d28614..08bfbe2f 100644 --- a/src/Support/ModelIdentifierNormalizer.php +++ b/src/Support/ModelIdentifierNormalizer.php @@ -31,7 +31,7 @@ public function normalize(mixed $object, string $format = null, array $context = /** * @inheritdoc */ - public function supportsNormalization(mixed $data, string $format = null): bool + public function supportsNormalization(mixed $data, string $format = null, array $context = []): bool { return ($data instanceof QueueableEntity || $data instanceof QueueableCollection); } @@ -51,7 +51,7 @@ public function denormalize(mixed $data, string $type, string $format = null, ar /** * @inheritdoc */ - public function supportsDenormalization(mixed $data, string $type, string $format = null): bool + public function supportsDenormalization(mixed $data, string $type, string $format = null, array $context = []): bool { return $this->normalizedDataIsModelIdentifier($data) && $this->isNormalizedToModelIdentifier($type); diff --git a/src/Support/ObjectNormalizer.php b/src/Support/ObjectNormalizer.php index 28a155ed..36fe13f0 100644 --- a/src/Support/ObjectNormalizer.php +++ b/src/Support/ObjectNormalizer.php @@ -8,17 +8,32 @@ use Symfony\Component\Serializer\Mapping\ClassDiscriminatorResolverInterface; use Symfony\Component\Serializer\Mapping\Factory\ClassMetadataFactoryInterface; use Symfony\Component\Serializer\NameConverter\NameConverterInterface; +use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer as SymfonyAbstractObjectNormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer as SymfonyObjectNormalizer; -class ObjectNormalizer extends SymfonyObjectNormalizer +class ObjectNormalizer extends SymfonyAbstractObjectNormalizer { - public function __construct(ClassMetadataFactoryInterface $classMetadataFactory = null, NameConverterInterface $nameConverter = null, PropertyAccessorInterface $propertyAccessor = null, PropertyTypeExtractorInterface $propertyTypeExtractor = null, ClassDiscriminatorResolverInterface $classDiscriminatorResolver = null, callable $objectClassResolver = null, array $defaultContext = []) + protected SymfonyObjectNormalizer $normalizer; + + public function __construct(?ClassMetadataFactoryInterface $classMetadataFactory = null, ?NameConverterInterface $nameConverter = null, ?PropertyAccessorInterface $propertyAccessor = null, ?PropertyTypeExtractorInterface $propertyTypeExtractor = null, ?ClassDiscriminatorResolverInterface $classDiscriminatorResolver = null, ?callable $objectClassResolver = null, array $defaultContext = []) { - parent::__construct( + + $propertyTypeExtractor = $propertyTypeExtractor ?? new PhpDocExtractor(); + + $this->normalizer = new SymfonyObjectNormalizer( $classMetadataFactory, $nameConverter, $propertyAccessor, - $propertyTypeExtractor ?? new PhpDocExtractor(), + $propertyTypeExtractor, + $classDiscriminatorResolver, + $objectClassResolver, + $defaultContext + ); + + parent::__construct( + $classMetadataFactory, + $nameConverter, + $propertyTypeExtractor, $classDiscriminatorResolver, $objectClassResolver, $defaultContext @@ -29,4 +44,24 @@ public function getSupportedTypes(?string $format): array { return ['object' => false]; } + + protected function extractAttributes(object $object, ?string $format = null, array $context = []): array + { + return $this->normalizer->extractAttributes($object, $format, $context); + } + + protected function getAttributeValue(object $object, string $attribute, ?string $format = null, array $context = []): mixed + { + return $this->normalizer->getAttributeValue($object, $attribute, $format, $context); + } + + protected function setAttributeValue(object $object, string $attribute, mixed $value, ?string $format = null, array $context = []): void + { + $this->normalizer->setAttributeValue($object, $attribute, $value, $format, $context); + } + + protected function getAllowedAttributes(string|object $classOrObject, array $context, bool $attributesAsString = false): array|bool + { + return $this->normalizer->getAllowedAttributes($classOrObject, $context, $attributesAsString); + } }