From 910700bf4a3684e94a4e48e0c3caad38579678fd Mon Sep 17 00:00:00 2001 From: Danny van der Sluijs Date: Tue, 12 Dec 2023 09:48:59 +0100 Subject: [PATCH] refactor: Require PHP 8.0 (#194) * refactor: Require PHP 8.0; Bump all dependencies; Update workflow for PHP 8 requirement including newer versions PHP * refactor: Update code to PHP 8.0 using rector; Upgrade progressbar to show current url * refactor: Improving for PHP 8.0 support * fix: Add missing entry in known endpoints to avoid losing ProjectProjectProgressReports --- .github/workflows/build.yaml | 41 ++++++++--------- .../Command/MetaDataBuilderCommand.php | 27 +++++++----- MetaDataTool/Config/EndpointCrawlerConfig.php | 6 +-- MetaDataTool/Crawlers/EndpointCrawler.php | 40 ++++++++--------- MetaDataTool/Crawlers/MainPageCrawler.php | 8 +--- MetaDataTool/Enum/KnownEntities.php | 1 + MetaDataTool/JsonFileWriter.php | 9 +--- MetaDataTool/PageRegistry.php | 2 +- MetaDataTool/ValueObjects/Endpoint.php | 44 ++++--------------- MetaDataTool/ValueObjects/HttpMethodMask.php | 6 +-- MetaDataTool/ValueObjects/Property.php | 39 ++++------------ .../ValueObjects/PropertyCollection.php | 2 +- .../ValueObjects/PropertyRowParserConfig.php | 19 ++------ composer.json | 23 +++++----- exact-online-meta-data-tool | 4 +- rector.php | 18 ++++++++ tests/Integration/EndpointCrawlerTest.php | 9 +--- .../ValueObjects/EndpointCollectionTest.php | 8 ++-- tests/Unit/ValueObjects/EndpointTest.php | 12 ++--- .../Unit/ValueObjects/HttpMethodMaskTest.php | 6 +-- .../ValueObjects/PropertyCollectionTest.php | 6 +-- tests/Unit/ValueObjects/PropertyTest.php | 8 ++-- 22 files changed, 141 insertions(+), 197 deletions(-) create mode 100644 rector.php diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 950b793..929e94f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -13,27 +13,6 @@ jobs: strategy: matrix: include: - - php: 7.2 - allow_fail: false - name: 'PHP 7.2 with latest deps' - - php: 7.2 - allow_fail: false - composer_update_flags: '--prefer-lowest --prefer-stable' - name: 'PHP 7.2 with lowest stable deps' - - php: 7.3 - allow_fail: false - name: 'PHP 7.3 with latest deps' - - php: 7.3 - allow_fail: false - composer_update_flags: '--prefer-lowest --prefer-stable' - name: 'PHP 7.3 with lowest stable deps' - - php: 7.4 - allow_fail: false - name: 'PHP 7.4 with latest deps' - - php: 7.4 - allow_fail: false - composer_update_flags: '--prefer-lowest --prefer-stable' - name: 'PHP 7.4 with lowest stable deps' - php: 8.0 allow_fail: false php_ini: 'xdebug.coverage_enable=On' @@ -52,11 +31,29 @@ jobs: composer_update_flags: '--prefer-lowest --prefer-stable' php_ini: 'xdebug.coverage_enable=On' name: 'PHP 8.1 with lowest stable deps' + - php: 8.2 + allow_fail: true + php_ini: 'xdebug.coverage_enable=On' + name: 'PHP 8.2 with latest deps' + - php: 8.2 + allow_fail: true + composer_update_flags: '--prefer-lowest --prefer-stable' + php_ini: 'xdebug.coverage_enable=On' + name: 'PHP 8.2 with lowest stable deps' + - php: 8.3 + allow_fail: true + php_ini: 'xdebug.coverage_enable=On' + name: 'PHP 8.3 with latest deps' + - php: 8.3 + allow_fail: true + composer_update_flags: '--prefer-lowest --prefer-stable' + php_ini: 'xdebug.coverage_enable=On' + name: 'PHP 8.3 with lowest stable deps' runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Validate composer.json and composer.lock run: composer validate diff --git a/MetaDataTool/Command/MetaDataBuilderCommand.php b/MetaDataTool/Command/MetaDataBuilderCommand.php index e5afb81..0e981ef 100644 --- a/MetaDataTool/Command/MetaDataBuilderCommand.php +++ b/MetaDataTool/Command/MetaDataBuilderCommand.php @@ -9,8 +9,9 @@ use MetaDataTool\Crawlers\MainPageCrawler; use MetaDataTool\Enum\KnownEntities; use MetaDataTool\JsonFileWriter; -use MetaDataTool\PageRegistry; +use MetaDataTool\ValueObjects\Endpoint; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -18,10 +19,9 @@ class MetaDataBuilderCommand extends Command { - private const MAINPAGE = 'https://start.exactonline.nl/docs/HlpRestAPIResources.aspx'; + private const MAIN_PAGE = 'https://start.exactonline.nl/docs/HlpRestAPIResources.aspx'; protected static $defaultName = 'run'; - protected function configure(): void { $this @@ -52,22 +52,29 @@ protected function execute(InputInterface $input, OutputInterface $output): int die(1); } - $io->info(['Scanning main page', self::MAINPAGE]); - $mainPageCrawler = new MainPageCrawler(self::MAINPAGE); + $io->info(['Scanning main page', self::MAIN_PAGE]); + $mainPageCrawler = new MainPageCrawler(self::MAIN_PAGE); $pages = $mainPageCrawler->run(); foreach (KnownEntities::keys() as $entity) { $pages->add('https://start.exactonline.nl/docs/HlpRestAPIResourcesDetails.aspx?name=' . $entity); } $io->info('Scanning entity pages'); - $io->progressStart($pages->count()); + ProgressBar::setFormatDefinition('custom', ' %current%/%max% -- %message% (%url%)'); + $progressBar = $io->createProgressBar($pages->count()); + $progressBar->setFormat('custom'); + $progressBar->setMessage('Processing documentation'); + $progressBar->start(); $config = new EndpointCrawlerConfig(true); $endpoints = (new EndpointCrawler($config, $pages)) - ->run(static function() use ($io): void { - $io->progressAdvance(1); + ->run(static function(Endpoint $endpoint) use ($progressBar): void { + $progressBar->advance(1); + $progressBar->setMessage($endpoint->getDocumentation(), 'url'); }); - $io->progressFinish(); + $progressBar->finish(); + $progressBar->setMessage(''); + $io->newLine(2); $io->info('Creating meta data file'); $writer = new JsonFileWriter($this->getFullDestinationPath($destination)); @@ -79,7 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int private function getFullDestinationPath(string $destination): string { - if (strpos($destination, DIRECTORY_SEPARATOR) === 0 || strpos($destination, '.') === 0) { + if (str_starts_with($destination, DIRECTORY_SEPARATOR) || str_starts_with($destination, '.')) { return $destination; } diff --git a/MetaDataTool/Config/EndpointCrawlerConfig.php b/MetaDataTool/Config/EndpointCrawlerConfig.php index e993c22..27702aa 100644 --- a/MetaDataTool/Config/EndpointCrawlerConfig.php +++ b/MetaDataTool/Config/EndpointCrawlerConfig.php @@ -6,12 +6,8 @@ class EndpointCrawlerConfig { - /** @var bool */ - private $queueDiscoveredLinks; - - public function __construct(bool $queueDiscoveredLinks) + public function __construct(private bool $queueDiscoveredLinks) { - $this->queueDiscoveredLinks = $queueDiscoveredLinks; } public function shouldQueueDiscoveredLinks(): bool diff --git a/MetaDataTool/Crawlers/EndpointCrawler.php b/MetaDataTool/Crawlers/EndpointCrawler.php index 5d722be..696e2d0 100644 --- a/MetaDataTool/Crawlers/EndpointCrawler.php +++ b/MetaDataTool/Crawlers/EndpointCrawler.php @@ -20,19 +20,12 @@ class EndpointCrawler private const BASE_URL = 'https://start.exactonline.nl/docs/'; private const ATTRIBUTE_HEADER_XPATH = '//table[@id="referencetable"]/tr[1]'; private const ATTRIBUTE_ROWS_XPATH = '//table[@id="referencetable"]/tr[position()>1]'; + private PageRegistry $pagesToVisit; + private PageRegistry $visitedPages; + private ?Crawler $domCrawler = null; - /** @var EndpointCrawlerConfig */ - private $config; - /** @var PageRegistry */ - private $pagesToVisit; - /** @var PageRegistry */ - private $visitedPages; - /** @var Crawler */ - private $domCrawler; - - public function __construct(EndpointCrawlerConfig $config, ?PageRegistry $pagesToVisit = null) + public function __construct(private EndpointCrawlerConfig $config, ?PageRegistry $pagesToVisit = null) { - $this->config = $config; $this->pagesToVisit = $pagesToVisit ?? $this->createDefaultPagesToVisit(); $this->visitedPages = new PageRegistry(); } @@ -83,7 +76,7 @@ private function crawlWebPage(string $url): ?Endpoint $scope = $this->domCrawler->filterXPath('//*[@id="scope"]')->first()->text(); try { $uri = $this->domCrawler->filterXPath('//*[@id="serviceUri"]')->first()->text(); - } catch (\Exception $exception) { + } catch (\Exception) { return null; } $supportedMethodsCrawler = $this->domCrawler->filterXPath('//input[@name="supportedmethods"]'); @@ -107,9 +100,7 @@ private function crawlWebPage(string $url): ?Endpoint return null; } - $columns = array_map(static function ($n) { - return explode(' ', $n->nodeValue)[0]; - }, $header->children()->getIterator()->getArrayCopy()); + $columns = array_map(static fn($n) => explode(' ', $n->nodeValue)[0], $header->children()->getIterator()->getArrayCopy()); $propertyRowParserConfig = new PropertyRowParserConfig( array_search('Type', $columns, true) + 1, @@ -122,7 +113,7 @@ private function crawlWebPage(string $url): ?Endpoint $goodToKnows = $this->domCrawler->filterXPath('//*[@id="goodToKnow"]'); $deprecationMessage = 'This endpoint is redundant and is going to be removed.'; - $isDeprecated = $goodToKnows->count() > 0 && strpos($goodToKnows->first()->text(), $deprecationMessage) !== false; + $isDeprecated = $goodToKnows->count() > 0 && str_contains($goodToKnows->first()->text(), $deprecationMessage); return new Endpoint( $endpoint, $url, @@ -137,7 +128,16 @@ private function crawlWebPage(string $url): ?Endpoint private function fetchHtmlFromUrl(string $url): string { - $html = file_get_contents($url); + [,$basename] = explode('=', $url); + $filename = sys_get_temp_dir() . '/exact-online-meta-data-tool-' . strtolower($basename) . '.html'; + + if (!file_exists($filename)) { + $html = file_get_contents($url); + file_put_contents($filename, $html); + } else { + $html = file_get_contents($filename); + } + $this->visitedPages->add($url); if ($html === false) { @@ -166,16 +166,16 @@ private function getPropertyRowParser(PropertyRowParserConfig $config): \Closure if ($name === 'ID') { $httpMethods = $httpMethods->addDelete(); } - if (strpos($class, 'hideput') === false && strpos($class, 'showget') === false) { + if (!str_contains($class, 'hideput') && !str_contains($class, 'showget')) { $httpMethods = $httpMethods->addPut(); } - if (strpos($class, 'hidepost') === false && strpos($class, 'showget') === false) { + if (!str_contains($class, 'hidepost') && !str_contains($class, 'showget')) { $httpMethods = $httpMethods->addPost(); } if ($name === 'ID') { $httpMethods = HttpMethodMask::all(); } - $hidden = strpos($node->attr('class') ?? '', 'hiderow') !== false; + $hidden = str_contains($node->attr('class') ?? '', 'hiderow'); $mandatory = strtolower(trim($node->filterXpath("//td[{$config->getMandatoryColumnIndex()}]")->text())) === 'true'; return new Property($name, $type, $description, $primaryKey, $httpMethods, $hidden, $mandatory); diff --git a/MetaDataTool/Crawlers/MainPageCrawler.php b/MetaDataTool/Crawlers/MainPageCrawler.php index adf780f..c76a94a 100644 --- a/MetaDataTool/Crawlers/MainPageCrawler.php +++ b/MetaDataTool/Crawlers/MainPageCrawler.php @@ -9,13 +9,7 @@ class MainPageCrawler { - /** @var string */ - private $mainPage; - - public function __construct(string $mainPage) - { - $this->mainPage = $mainPage; - } + public function __construct(private string $mainPage) {} public function run(): PageRegistry { diff --git a/MetaDataTool/Enum/KnownEntities.php b/MetaDataTool/Enum/KnownEntities.php index fc83a39..f6108f3 100644 --- a/MetaDataTool/Enum/KnownEntities.php +++ b/MetaDataTool/Enum/KnownEntities.php @@ -110,6 +110,7 @@ class KnownEntities extends Enum private const ProjectProjectHourBudgets = 'ProjectProjectHourBudgets'; private const ProjectProjectPlanning = 'ProjectProjectPlanning'; private const ProjectProjectPlanningRecurring = 'ProjectProjectPlanningRecurring'; + private const ProjectProjectProgressReports = 'ProjectProjectProgressReports'; private const ProjectProjectRestrictionEmployees = 'ProjectProjectRestrictionEmployees'; private const ProjectProjectRestrictionItems = 'ProjectProjectRestrictionItems'; private const ProjectProjectRestrictionRebillings = 'ProjectProjectRestrictionRebillings'; diff --git a/MetaDataTool/JsonFileWriter.php b/MetaDataTool/JsonFileWriter.php index 59d0490..60df1ab 100644 --- a/MetaDataTool/JsonFileWriter.php +++ b/MetaDataTool/JsonFileWriter.php @@ -11,22 +11,17 @@ class JsonFileWriter { private const FILE_NAME = '/meta-data.json'; - /** @var string */ - private $path; - /** * JsonFileWriter constructor. - * @param string $path */ - public function __construct(string $path) + public function __construct(private string $path) { - $this->path = $path; $this->ensureDirectoryAvailability($path); } public function write(EndpointCollection $endpoints): void { - file_put_contents($this->getFullFileName(), json_encode($endpoints, JSON_PRETTY_PRINT)); + file_put_contents($this->getFullFileName(), json_encode($endpoints, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT)); } public function getFullFileName(): string diff --git a/MetaDataTool/PageRegistry.php b/MetaDataTool/PageRegistry.php index 9b9f788..aa5d715 100644 --- a/MetaDataTool/PageRegistry.php +++ b/MetaDataTool/PageRegistry.php @@ -9,7 +9,7 @@ class PageRegistry implements \Countable, \IteratorAggregate { /** @var string[] */ - private $pages = []; + private array $pages; public function __construct(string ...$pages) { diff --git a/MetaDataTool/ValueObjects/Endpoint.php b/MetaDataTool/ValueObjects/Endpoint.php index 6889cfd..7c8be87 100644 --- a/MetaDataTool/ValueObjects/Endpoint.php +++ b/MetaDataTool/ValueObjects/Endpoint.php @@ -8,42 +8,16 @@ class Endpoint implements JsonSerializable { - /** @var string */ - private $endpoint; - /** @var string */ - private $documentation; - /** @var string */ - private $scope; - /** @var string */ - private $uri; - /** @var HttpMethodMask */ - private $supportedHttpMethods; - /** @var string */ - private $example; - /** @var PropertyCollection */ - private $properties; - /** @var bool */ - private $isDeprecated; - public function __construct( - string $endpoint, - string $documentation, - string $scope, - string $uri, - HttpMethodMask $supportedHttpMethods, - string $example, - PropertyCollection $properties, - bool $isDeprecated = false - ) { - $this->endpoint = $endpoint; - $this->documentation = $documentation; - $this->scope = $scope; - $this->uri = $uri; - $this->supportedHttpMethods = $supportedHttpMethods; - $this->example = $example; - $this->properties = $properties; - $this->isDeprecated = $isDeprecated; - } + private string $endpoint, + private string $documentation, + private string $scope, + private string $uri, + private HttpMethodMask $supportedHttpMethods, + private string $example, + private PropertyCollection $properties, + private bool $isDeprecated = false + ) {} public function getEndpoint(): string { diff --git a/MetaDataTool/ValueObjects/HttpMethodMask.php b/MetaDataTool/ValueObjects/HttpMethodMask.php index 172c587..03cc118 100644 --- a/MetaDataTool/ValueObjects/HttpMethodMask.php +++ b/MetaDataTool/ValueObjects/HttpMethodMask.php @@ -15,12 +15,8 @@ class HttpMethodMask implements JsonSerializable private const DELETE = 8; private const ALL = 15; - /** @var int */ - private $mask; - - private function __construct(int $mask) + private function __construct(private int $mask) { - $this->mask = $mask; } public static function none(): self diff --git a/MetaDataTool/ValueObjects/Property.php b/MetaDataTool/ValueObjects/Property.php index 53f1d20..7c072e4 100644 --- a/MetaDataTool/ValueObjects/Property.php +++ b/MetaDataTool/ValueObjects/Property.php @@ -9,38 +9,15 @@ class Property implements JsonSerializable { - /** @var string */ - private $name; - /** @var string */ - private $type; - /** @var string */ - private $description; - /** @var bool */ - private $primaryKey; - /** @var HttpMethodMask */ - private $supportedHttpMethods; - /** @var boolean */ - private $hidden; - /** @var boolean */ - private $mandatory; - public function __construct( - string $name, - string $type, - string $description, - bool $primaryKey, - HttpMethodMask $supportedHttpMethods, - bool $hidden, - bool $mandatory - ) { - $this->name = $name; - $this->type = $type; - $this->description = $description; - $this->primaryKey = $primaryKey; - $this->supportedHttpMethods = $supportedHttpMethods; - $this->hidden = $hidden; - $this->mandatory = $mandatory; - } + private string $name, + private string $type, + private string $description, + private bool $primaryKey, + private HttpMethodMask $supportedHttpMethods, + private bool $hidden, + private bool $mandatory + ) {} public function getName(): string { diff --git a/MetaDataTool/ValueObjects/PropertyCollection.php b/MetaDataTool/ValueObjects/PropertyCollection.php index 26df7d7..d4c8a8f 100644 --- a/MetaDataTool/ValueObjects/PropertyCollection.php +++ b/MetaDataTool/ValueObjects/PropertyCollection.php @@ -11,7 +11,7 @@ class PropertyCollection implements IteratorAggregate, JsonSerializable { /** @var Property[] */ - private $properties; + private array $properties; public function __construct(Property ...$properties) { diff --git a/MetaDataTool/ValueObjects/PropertyRowParserConfig.php b/MetaDataTool/ValueObjects/PropertyRowParserConfig.php index 8fb2b1b..05a19a1 100644 --- a/MetaDataTool/ValueObjects/PropertyRowParserConfig.php +++ b/MetaDataTool/ValueObjects/PropertyRowParserConfig.php @@ -6,22 +6,11 @@ class PropertyRowParserConfig { - /** @var int */ - private $typeColumnIndex; - /** @var int */ - private $documentationColumnIndex; - /** @var int */ - private $mandatoryColumnIndex; - public function __construct( - $typeColumnIndex, - $documentationColumnIndex, - $mandatoryColumnIndex - ) { - $this->typeColumnIndex = $typeColumnIndex; - $this->documentationColumnIndex = $documentationColumnIndex; - $this->mandatoryColumnIndex = $mandatoryColumnIndex; - } + private int $typeColumnIndex, + private int $documentationColumnIndex, + private int $mandatoryColumnIndex + ) {} public function getTypeColumnIndex(): int { diff --git a/composer.json b/composer.json index d7cd5dc..02dd9e8 100644 --- a/composer.json +++ b/composer.json @@ -11,20 +11,21 @@ ], "minimum-stability": "stable", "require": { - "php": "^7.2 || ^8.0", + "php": "^8.0", "ext-json": "*", - "symfony/console": "^5.0", - "symfony/dom-crawler": "^5.0", - "myclabs/php-enum": "^1.7" + "myclabs/php-enum": "^1.8", + "symfony/console": "^5.4", + "symfony/dom-crawler": "^5.4" }, "require-dev": { - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-strict-rules": "^0.12", - "squizlabs/php_codesniffer": "^3.5", - "phpunit/phpunit": "^8.5 || ^9.0", - "php-coveralls/php-coveralls": "^2.4", - "fakerphp/faker": "^1.14", - "guzzlehttp/guzzle": "^6.5 || ^7.0" + "fakerphp/faker": "^1.23", + "guzzlehttp/guzzle": "^6.5 || ^7.0", + "php-coveralls/php-coveralls": "^2.7", + "phpcsstandards/php_codesniffer": "^3.7", + "phpstan/phpstan": "^1.10", + "phpstan/phpstan-strict-rules": "^1.5", + "phpunit/phpunit": "^9.6", + "rector/rector": "^0.18.12" }, "autoload": { "psr-4": { diff --git a/exact-online-meta-data-tool b/exact-online-meta-data-tool index f323fb0..0cb81e9 100755 --- a/exact-online-meta-data-tool +++ b/exact-online-meta-data-tool @@ -16,7 +16,9 @@ require $autoloadFile; use MetaDataTool\Command\MetaDataBuilderCommand; use Symfony\Component\Console\Application; +$command = new MetaDataBuilderCommand(); $application = new Application(); -$application->add(new MetaDataBuilderCommand()); +$application->add($command); +$application->setDefaultCommand($command->getName()); $application->run(); \ No newline at end of file diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..89d7182 --- /dev/null +++ b/rector.php @@ -0,0 +1,18 @@ +paths([ + __DIR__ . '/MetaDataTool', + __DIR__ . '/tests', + ]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_80, + ]); +}; diff --git a/tests/Integration/EndpointCrawlerTest.php b/tests/Integration/EndpointCrawlerTest.php index b75bef8..7bf5c32 100644 --- a/tests/Integration/EndpointCrawlerTest.php +++ b/tests/Integration/EndpointCrawlerTest.php @@ -6,7 +6,6 @@ use MetaDataTool\Config\EndpointCrawlerConfig; use MetaDataTool\Crawlers\EndpointCrawler; -use MetaDataTool\DocumentationCrawler; use MetaDataTool\PageRegistry; use MetaDataTool\ValueObjects\Endpoint; use MetaDataTool\ValueObjects\Property; @@ -32,9 +31,7 @@ public function testItCanParseCrmAccountPage(): void /** @var Endpoint $account */ $account = array_shift($endpoints); $propertyNames = array_map( - static function (Property $p) { - return $p->getName(); - }, + static fn(Property $p) => $p->getName(), $account->getProperties()->getIterator()->getArrayCopy() ); self::assertEquals('Accounts', $account->getEndpoint()); @@ -61,9 +58,7 @@ public function testItCanDetectHiddenIsSerialNumberProperty(): void $itemEndpoint = array_shift($endpoints); /** @var Property[] $properties */ $properties = $itemEndpoint->getProperties()->getIterator()->getArrayCopy(); - $matches = array_filter($properties, function ($prop) { - return $prop->getName() === 'IsSerialNumberItem'; - }); + $matches = array_filter($properties, fn($prop) => $prop->getName() === 'IsSerialNumberItem'); $isSerialNumberProperty = array_shift($matches); self::assertNotNull($isSerialNumberProperty); diff --git a/tests/Unit/ValueObjects/EndpointCollectionTest.php b/tests/Unit/ValueObjects/EndpointCollectionTest.php index 282a696..8c9f175 100644 --- a/tests/Unit/ValueObjects/EndpointCollectionTest.php +++ b/tests/Unit/ValueObjects/EndpointCollectionTest.php @@ -68,8 +68,8 @@ public function testCollectionCanBeCorrectlySerialised(): void $collection = new EndpointCollection($endpoint); self::assertSame( - json_encode([$endpoint->getUri() => $endpoint]), - json_encode($collection) + json_encode([$endpoint->getUri() => $endpoint], JSON_THROW_ON_ERROR), + json_encode($collection, JSON_THROW_ON_ERROR) ); } @@ -87,7 +87,7 @@ public function testCollectionCanBeCorrectlyDeserialised(): void $exampleUrl = $this->faker()->url, $properties = new PropertyCollection(), $deprecated = $this->faker()->boolean() - ))); + )), JSON_THROW_ON_ERROR); self::assertEquals( new EndpointCollection(new Endpoint( @@ -100,7 +100,7 @@ public function testCollectionCanBeCorrectlyDeserialised(): void $properties, $deprecated )), - EndpointCollection::jsonDeserialize(json_decode($json, false)) + EndpointCollection::jsonDeserialize(json_decode($json, false, 512, JSON_THROW_ON_ERROR)) ); } } diff --git a/tests/Unit/ValueObjects/EndpointTest.php b/tests/Unit/ValueObjects/EndpointTest.php index c4dbd4b..5a80838 100644 --- a/tests/Unit/ValueObjects/EndpointTest.php +++ b/tests/Unit/ValueObjects/EndpointTest.php @@ -23,7 +23,8 @@ public function testValueObjectHoldsAttributes(): void $url = $this->faker()->url, $methods = HttpMethodMask::all(), $exampleUrl = $this->faker()->url, - $properties = new PropertyCollection() + $properties = new PropertyCollection(), + $deprecated = $this->faker()->boolean, ); self::assertSame($endpointUrl, $endpoint->getEndpoint()); @@ -33,6 +34,7 @@ public function testValueObjectHoldsAttributes(): void self::assertEquals($methods, $endpoint->getSupportedHttpMethods()); self::assertSame($exampleUrl, $endpoint->getExample()); self::assertEquals($properties, $endpoint->getProperties()); + self::assertEquals($deprecated, $endpoint->isDeprecated()); } /** @@ -61,8 +63,8 @@ public function testPropertyCanBeCorrectlySerialised(): void 'example' => $exampleUrl, 'properties' => $properties, 'deprecated' => $isDeprecated - ]), - json_encode($endpoint) + ], JSON_THROW_ON_ERROR), + json_encode($endpoint, JSON_THROW_ON_ERROR) ); } @@ -79,7 +81,7 @@ public function testPropertyCanBeCorrectlyDeserialised(): void $methods = HttpMethodMask::all(), $exampleUrl = $this->faker()->url, $properties = new PropertyCollection() - )); + ), JSON_THROW_ON_ERROR); self::assertEquals( new Endpoint( @@ -91,7 +93,7 @@ public function testPropertyCanBeCorrectlyDeserialised(): void $exampleUrl, $properties ), - Endpoint::jsonDeserialize(json_decode($json, false)) + Endpoint::jsonDeserialize(json_decode($json, false, 512, JSON_THROW_ON_ERROR)) ); } } diff --git a/tests/Unit/ValueObjects/HttpMethodMaskTest.php b/tests/Unit/ValueObjects/HttpMethodMaskTest.php index 33c6e48..1f3ab0e 100644 --- a/tests/Unit/ValueObjects/HttpMethodMaskTest.php +++ b/tests/Unit/ValueObjects/HttpMethodMaskTest.php @@ -89,7 +89,7 @@ public function testPropertyCanBeCorrectlySerialised(): void 'put' => true, 'delete' => true, ]), - json_encode($methods) + json_encode($methods, JSON_THROW_ON_ERROR) ); } @@ -98,11 +98,11 @@ public function testPropertyCanBeCorrectlySerialised(): void */ public function testPropertyCanBeCorrectlyDeserialised(): void { - $json = (string) json_encode(HttpMethodMask::all()); + $json = (string) json_encode(HttpMethodMask::all(), JSON_THROW_ON_ERROR); self::assertEquals( HttpMethodMask::all(), - HttpMethodMask::jsonDeserialize(json_decode($json, false)) + HttpMethodMask::jsonDeserialize(json_decode($json, false, 512, JSON_THROW_ON_ERROR)) ); } } diff --git a/tests/Unit/ValueObjects/PropertyCollectionTest.php b/tests/Unit/ValueObjects/PropertyCollectionTest.php index abd3ce7..2c9b0d5 100644 --- a/tests/Unit/ValueObjects/PropertyCollectionTest.php +++ b/tests/Unit/ValueObjects/PropertyCollectionTest.php @@ -46,7 +46,7 @@ public function testCollectionCanBeCorrectlySerialised(): void self::assertSame( json_encode([$property]), - json_encode($collection) + json_encode($collection, JSON_THROW_ON_ERROR) ); } @@ -63,7 +63,7 @@ public function testCollectionCanBeCorrectlyDeserialised(): void $methods = HttpMethodMask::all(), $hidden = true, $mandatory = true - ))); + )), JSON_THROW_ON_ERROR); self::assertEquals( new PropertyCollection(new Property( @@ -75,7 +75,7 @@ public function testCollectionCanBeCorrectlyDeserialised(): void $hidden, $mandatory )), - PropertyCollection::jsonDeserialize(json_decode($json, true)) + PropertyCollection::jsonDeserialize(json_decode($json, true, 512, JSON_THROW_ON_ERROR)) ); } diff --git a/tests/Unit/ValueObjects/PropertyTest.php b/tests/Unit/ValueObjects/PropertyTest.php index 0c8e23e..13d8527 100644 --- a/tests/Unit/ValueObjects/PropertyTest.php +++ b/tests/Unit/ValueObjects/PropertyTest.php @@ -58,8 +58,8 @@ public function testPropertyCanBeCorrectlySerialised(): void 'supportedMethods' => $methods, 'hidden' => $hidden, 'mandatory' => $mandatory - ]), - json_encode($property) + ], JSON_THROW_ON_ERROR), + json_encode($property, JSON_THROW_ON_ERROR) ); } @@ -76,7 +76,7 @@ public function testPropertyCanBeCorrectlyDeserialised(): void $methods = HttpMethodMask::all(), $hidden = false, $mandatory = true - )); + ), JSON_THROW_ON_ERROR); self::assertEquals( new Property( @@ -88,7 +88,7 @@ public function testPropertyCanBeCorrectlyDeserialised(): void $hidden, $mandatory ), - Property::jsonDeserialize(json_decode($json, false)) + Property::jsonDeserialize(json_decode($json, false, 512, JSON_THROW_ON_ERROR)) ); } }