From 43b64bc18748d6ea53e2d2deb0cc085e8d8c78b6 Mon Sep 17 00:00:00 2001 From: Patrick Gugelsberger Date: Mon, 1 Jun 2026 10:25:45 +0200 Subject: [PATCH 1/2] feat!: upgrade all dependencies to current stable versions BREAKING CHANGE: Minimum PHP version raised from 7.4 to 8.2. Multiple major dependency upgrades require consumers to align. Dependencies upgraded: - PHP >=7.4 -> >=8.2 - symfony/* ^5.0|^6.0 -> ^8.0 (console, event-dispatcher, filesystem, finder, http-foundation) - doctrine/dbal ^3.0 -> ^4.0 - doctrine/collections ^2.2 -> ^3.0 - monolog/monolog ^2.0|^3.0 -> ^3.0 - php-di/php-di ^6.0 -> ^7.0 - phpunit/phpunit ^9.0 -> ^11.0 - phpstan/phpstan ^1.0 -> ^2.0 - squizlabs/php_codesniffer ^3.10 -> ^4.0 - slevomat/coding-standard ^8.15 -> ^8.29 - micheh/phpcs-gitlab ^1.1 -> ^2.0 - jtl/connector-cq * -> ^2.0 - mockery/mockery ^1.3 -> ^1.6 Dependencies removed: - doctrine/annotations (zero usage) - doctrine/cache (zero usage) - jtl/unit-test (helpers inlined into tests/src/dbc/TestCase.php) DBAL 4 migration: - Rewrite QueryBuilder to track query type internally (INSERT/UPDATE/DELETE/SELECT) - Replace execute() with executeQuery()/executeStatement() - Replace fetch()/fetchAll() with fetchAssociative()/fetchAllAssociative() - Replace getSchemaManager() with createSchemaManager() - Replace Schema::getMigrateToSql() with Comparator + Platform::getAlterSchemaSQL() - Replace Type::getName() with TypeRegistry::lookupName() - Replace Connection::PARAM_STR_ARRAY with ArrayParameterType::STRING - Replace DBALException with Exception, SchemaException with ColumnDoesNotExist::new() - Replace ConversionException::conversionFailedInvalidType() with InvalidType::new() - Add normalizeIntrospectedSchema() for SQLite type round-trip mismatches - Update platform class references (MySqlPlatform -> MySQLPlatform, SqlitePlatform -> SQLitePlatform) - Update connection params (driver key mandatory, pdo key removed) Symfony 8 migration: - Replace removed Request::get() with Request::request->get() / Request::query->get() - Replace Request mock with real Request in tests (typed property) Monolog 3 / PHP-DI 7: - Remove useAnnotations(true) call - Clean up backward-compat union type hints in logger processors/handlers PHPUnit 11 migration: - Convert 69 @dataProvider annotations to #[DataProvider()] attributes across 27 files - Make all data provider methods static - Convert @depends to #[Depends()], @runInSeparateProcess to #[RunInSeparateProcess] - Replace setMethods() with onlyMethods() - Remove SebastianBergmann\RecursionContext\InvalidArgumentException (85 occurrences, 45 files) - Remove invalid PHPUnit MockObject exception imports and @throws (~260 annotations) - Fix unqualified exception names in @throws to prevent namespace misresolution - Inline jtl/unit-test reflection helpers into tests/src/dbc/TestCase.php - Update phpunit.xml.dist schema to 11.5, replace with PHPStan 2 migration: - Fix ~148 errors across ~47 files at level max - Narrow mixed types before binary ops, casts, foreach, offset access - Remove redundant type checks (instanceof, is_int, is_string, is_array, is_object) - Fix ReflectionClass template covariance (inline instead of property) - Add @var annotations for superglobals and loosely-typed returns - Extract typed variables from method chains for static analysis phpcs 4 / slevomat 8.29: - Auto-fix 364 @throws annotation ordering violations across 77 files - Console command: $defaultName property -> #[AsCommand] attribute --- composer.json | 37 +- phpunit.xml.dist | 12 +- src/Application/Application.php | 99 ++-- src/Config/CoreConfigInterface.php | 2 +- src/Controller/ConnectorController.php | 37 +- src/Definition/Action.php | 2 +- src/Definition/Event.php | 6 +- src/Definition/PaymentType.php | 2 +- src/Http/JsonResponse.php | 6 +- src/Linker/ChecksumLinker.php | 75 +-- src/Linker/IdentityLinker.php | 4 +- src/Logger/Handler/ChunkedHandler.php | 72 ++- src/Logger/LoggerService.php | 62 ++- src/Logger/Processor/RequestProcessor.php | 30 +- src/Logger/Processor/WarningProcessor.php | 16 +- src/Model/AbstractImage.php | 7 +- src/Model/Generator/AbstractModelFactory.php | 18 +- src/Model/Generator/ProductFactory.php | 4 +- src/Model/Generator/ProductPriceFactory.php | 16 +- .../Generator/ProductVariationFactory.php | 6 +- src/Model/Generator/TaxRateFactory.php | 2 +- src/Model/QueryFilter.php | 14 +- src/Model/TranslatableAttribute.php | 6 +- src/Model/TranslatableAttributeI18n.php | 2 +- src/Rpc/Packet.php | 4 +- src/Rpc/RequestPacket.php | 6 +- src/Rpc/ResponsePacket.php | 2 +- src/Serializer/Handler/IdentityHandler.php | 3 +- src/Serializer/SerializerBuilder.php | 2 +- .../Subscriber/CrossSellingSubscriber.php | 13 +- src/Serializer/Subscriber/ImageSubscriber.php | 7 +- .../Subscriber/LanguageIsoSubscriber.php | 8 +- .../ProductStockLevelSubscriber.php | 6 +- src/Session/SessionHelper.php | 5 + src/Session/SqliteSessionHandler.php | 4 +- .../RequestParamsTransformSubscriber.php | 14 +- src/SyncError/SqliteSyncErrorCollector.php | 1 + src/System/Check.php | 3 +- src/Utilities/Money.php | 12 +- src/Utilities/Validator/Validate.php | 4 +- src/Utilities/Validator/Validator.php | 10 +- .../Validator/ValidatorInterface.php | 2 +- src/dbc/AbstractTable.php | 69 +-- src/dbc/Connection.php | 97 ++-- .../Command/UpdateDatabaseSchemaCommand.php | 5 +- src/dbc/DbManager.php | 91 +++- src/dbc/Query/QueryBuilder.php | 172 +++++-- src/dbc/Schema/TableRestriction.php | 8 +- src/dbc/Session/SessionHandler.php | 40 +- src/dbc/TableCollection.php | 2 +- src/dbc/Types/Uuid4Type.php | 50 +- src/mapping-tables/AbstractTable.php | 222 ++++----- src/mapping-tables/TableManager.php | 6 +- src/mapping-tables/TableProxy.php | 43 +- src/mapping-tables/Validator.php | 4 +- tests/bootstrap.php | 4 - tests/src/Application/ApplicationTest.php | 433 ++++-------------- tests/src/Application/RequestTest.php | 5 +- tests/src/Application/ResponseTest.php | 15 +- .../Authentication/TokenValidationTest.php | 11 +- tests/src/Config/ConfigParameterTest.php | 31 +- tests/src/Config/ConfigSchemaTest.php | 35 +- tests/src/Config/FileConfigTest.php | 11 +- tests/src/Controller/ConnectorTest.php | 141 +----- tests/src/Definition/ActionTest.php | 24 +- tests/src/Definition/ControllerTest.php | 14 +- tests/src/Definition/EventTest.php | 29 +- tests/src/Definition/IdentityTypeTest.php | 14 +- tests/src/Definition/ModelTest.php | 46 +- tests/src/Definition/PaymentTypeTest.php | 14 +- tests/src/Definition/RelationTypeTest.php | 59 ++- tests/src/Definition/RpcMethodTest.php | 27 +- tests/src/Linker/IdentityLinkerTest.php | 112 ++--- tests/src/Logger/LoggerServiceTest.php | 62 +-- tests/src/Model/AbstractImageTest.php | 41 +- tests/src/Model/ModelTest.php | 32 +- .../Model/TranslatableAttributeI18nTest.php | 29 +- tests/src/Model/TranslatableAttributeTest.php | 88 ++-- tests/src/Rpc/ErrorTest.php | 5 +- tests/src/Rpc/MethodTest.php | 15 +- tests/src/Rpc/PacketTest.php | 2 +- tests/src/Rpc/RequestPacketTest.php | 42 +- tests/src/Rpc/ResponsePacketTest.php | 11 +- .../Handler/IdentityHandlerTest.php | 6 +- .../Subscriber/CrossSellingSubscriberTest.php | 31 +- .../Subscriber/ImageSubscriberTest.php | 19 +- .../Subscriber/LanguageIsoSubscriberTest.php | 101 ++-- .../ProductAttributeSubscriberTest.php | 11 +- tests/src/Session/SessionHelperTest.php | 40 +- .../src/Session/SqliteSessionHandlerTest.php | 79 ++-- .../src/Subscriber/FeaturesSubscriberTest.php | 13 +- .../RequestParamsTransformSubscriberTest.php | 43 +- .../Subscriber/SyncErrorSubscriberTest.php | 2 +- tests/src/TestCase.php | 9 +- tests/src/Utilities/StrTest.php | 16 +- tests/src/dbc/ConnectionTest.php | 131 ++---- tests/src/dbc/CoordinatesStub.php | 29 +- tests/src/dbc/DbManagerStub.php | 12 +- tests/src/dbc/DbManagerTest.php | 50 +- tests/src/dbc/Mapping/TableTest.php | 140 +++--- tests/src/dbc/Query/QueryBuilderTest.php | 122 +++-- tests/src/dbc/Schema/TableRestrictionTest.php | 21 +- tests/src/dbc/Session/SessionHandlerTest.php | 159 ++----- tests/src/dbc/Table2Stub.php | 6 +- tests/src/dbc/TableCollectionTest.php | 25 +- tests/src/dbc/TableStub.php | 50 +- tests/src/dbc/TestCase.php | 109 +++-- tests/src/dbc/Types/Uuid4TypeTest.php | 116 +---- .../src/mapping-tables/AbstractTableTest.php | 240 ++++------ .../mapping-tables/TableCollectionTest.php | 70 +-- tests/src/mapping-tables/TableDummyTest.php | 41 +- tests/src/mapping-tables/TableManagerTest.php | 59 ++- tests/src/mapping-tables/TableProxyTest.php | 87 ++-- tests/src/mapping-tables/TableStub.php | 10 +- 114 files changed, 1910 insertions(+), 2741 deletions(-) diff --git a/composer.json b/composer.json index df9dbecf..a4c7ad27 100755 --- a/composer.json +++ b/composer.json @@ -12,39 +12,36 @@ "role": "Founder" }], "require": { - "php": ">=8.1", + "php": ">=8.2", "jms/serializer": "*", "hassankhan/config": "^3.0", - "monolog/monolog": "*", - "symfony/finder": "*", - "symfony/event-dispatcher": "*", - "doctrine/collections": "^1.4", - "doctrine/annotations": "^1.10", - "doctrine/cache": "^1.10", + "monolog/monolog": "^3.0", + "symfony/finder": "^8.0", + "symfony/event-dispatcher": "^8.0", + "doctrine/collections": "^3.0", "ext-json": "*", "ext-sqlite3": "*", "ext-zip": "*", - "php-di/php-di": "^6.0", + "php-di/php-di": "^7.0", "jawira/case-converter": "^3.4", - "symfony/http-foundation": "^4.0|^5.0", - "symfony/filesystem": "^4.0|^5.0", - "symfony/console": "^4.3|^5.1", + "symfony/http-foundation": "^8.0", + "symfony/filesystem": "^8.0", + "symfony/console": "^8.0", "fakerphp/faker": "^1.13", "whitecube/lingua": "^1.1", "ext-fileinfo": "*", - "doctrine/dbal": "^2.5", + "doctrine/dbal": "^4.0", "ext-pdo": "*" }, "require-dev": { "mikey179/vfsstream": "^1.6", - "phpunit/phpunit": "^9.5", - "jtl/connector-cq": "*", - "phpstan/phpstan": "^1.11", - "squizlabs/php_codesniffer": "^3.10", - "micheh/phpcs-gitlab": "^1.1", - "slevomat/coding-standard": "^8.15", - "mockery/mockery": "^1.4", - "jtl/unit-test": "^0.1.3" + "phpunit/phpunit": "^11.0", + "jtl/connector-cq": "^2.0", + "phpstan/phpstan": "^2.0", + "squizlabs/php_codesniffer": "^4.0", + "micheh/phpcs-gitlab": "^2.0", + "slevomat/coding-standard": "^8.29", + "mockery/mockery": "^1.6" }, "provide": { "jtl/connector-mapping-tables": "4.0.8", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7c82bed7..ee6b6767 100755 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,16 +1,16 @@ - - + + src - + tests - diff --git a/src/Application/Application.php b/src/Application/Application.php index 1bb26f31..324e90f4 100755 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -10,8 +10,6 @@ use DI\Definition\Exception\InvalidDefinition; use DI\DependencyException; use DI\NotFoundException; -use Doctrine\Common\Annotations\AnnotationException; -use Doctrine\Common\Annotations\AnnotationRegistry; use Jawira\CaseConverter\CaseConverterException; use JMS\Serializer\Exception\LogicException; use JMS\Serializer\Exception\NotAcceptableException; @@ -113,8 +111,8 @@ class Application { - public const PROTOCOL_VERSION = 7; - public const MIN_PHP_VERSION = '7.4'; + public const int PROTOCOL_VERSION = 7; + public const string MIN_PHP_VERSION = '8.2'; /** @var array */ protected static array $mimeTypeToExtensionMappings = [ 'image/bmp' => 'bmp', @@ -165,18 +163,17 @@ class Application * @throws ApplicationException * @throws ConfigException * @throws DependencyException + * @throws EmptyDirectoryException * @throws InvalidArgumentException - * @throws LoggerException - * @throws ReflectionException - * @throws RuntimeException - * @throws InvalidDefinition - * @throws AnnotationException * @throws \InvalidArgumentException + * @throws InvalidDefinition * @throws \JMS\Serializer\Exception\InvalidArgumentException - * @throws LogicException * @throws \JMS\Serializer\Exception\RuntimeException + * @throws LoggerException + * @throws LogicException * @throws \LogicException - * @throws EmptyDirectoryException + * @throws ReflectionException + * @throws RuntimeException * @throws \TypeError * @throws \UnexpectedValueException */ @@ -188,8 +185,6 @@ public function __construct( if (!\is_dir($connectorDir)) { throw ApplicationException::connectorDirNotExists($connectorDir); } - AnnotationRegistry::registerLoader('class_exists'); - if ($configSchema !== null && $config !== null) { if ($config instanceof ConfigSchemaConfigInterface) { $config->setConfigSchema($configSchema); @@ -204,8 +199,7 @@ public function __construct( $serializerCacheDir = null; if ( - $config instanceof CoreConfigInterface - && $config->getBool(ConfigSchema::DEBUG, false) === false + $config->getBool(ConfigSchema::DEBUG, false) === false && $config->getBool(ConfigSchema::SERIALIZER_ENABLE_CACHE, true) === true ) { $serializerCacheDir = $config->getString(ConfigSchema::CACHE_DIR); @@ -215,7 +209,6 @@ public function __construct( $this->config = $config; $this->configSchema = $configSchema; $this->container = (new ContainerBuilder()) - ->useAnnotations(true) ->useAutowiring(true) ->build(); @@ -310,14 +303,14 @@ public function registerController(string $controllerName, object $instance): se * @throws DependencyException * @throws FileNotFoundException * @throws NotFoundException + * @throws \ReflectionException * @throws RpcException * @throws SessionException * @throws Throwable - * @throws \ReflectionException */ public function run(ConnectorInterface $connector): void { - $jtlrpc = Validate::string($this->httpRequest->get('jtlrpc', '')); + $jtlrpc = Validate::string($this->httpRequest->request->get('jtlrpc', '')); $this->httpResponse->setLogger($this->loggerService->get(LoggerService::CHANNEL_RPC)); $this->eventDispatcher->addSubscriber(new RequestParamsTransformSubscriber()); $this->eventDispatcher->addSubscriber(new FeaturesSubscriber()); @@ -413,17 +406,17 @@ public function run(ConnectorInterface $connector): void * * * @return void + * @throws BadRequestException * @throws DatabaseException * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws RuntimeException * @throws SessionException - * @throws \InvalidArgumentException - * @throws BadRequestException * @throws \UnexpectedValueException */ protected function startSession(string $rpcMethod): void { - $sessionId = $this->httpRequest->get('jtlauth'); + $sessionId = $this->httpRequest->query->get('jtlauth'); $sessionName = 'JtlConnector'; if ($sessionId === null && $rpcMethod !== RpcMethod::AUTH) { @@ -454,9 +447,9 @@ protected function startSession(string $rpcMethod): void * @return SessionHandlerInterface * @throws DatabaseException * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws RuntimeException * @throws SessionException - * @throws \InvalidArgumentException * @throws \UnexpectedValueException */ public function getSessionHandler(): SessionHandlerInterface @@ -506,9 +499,7 @@ protected function initSyncErrorCollector(): void $sqlite->connect(['location' => $dbLocation]); $collector = new SqliteSyncErrorCollector($sqlite); - if ($collector instanceof LoggerAwareInterface) { - $collector->setLogger($this->loggerService->get(LoggerService::CHANNEL_GLOBAL)); - } + $collector->setLogger($this->loggerService->get(LoggerService::CHANNEL_GLOBAL)); $this->container->set(SyncErrorCollectorInterface::class, $collector); @@ -527,10 +518,10 @@ protected function initSyncErrorCollector(): void * @return void * @throws DatabaseException * @throws InvalidArgumentException - * @throws RuntimeException - * @throws SessionException * @throws \InvalidArgumentException * @throws \LogicException + * @throws RuntimeException + * @throws SessionException * @throws \UnexpectedValueException */ protected function prepareContainer(ConnectorInterface $connector): void @@ -623,13 +614,13 @@ protected function loadPlugins( * @throws DefinitionException * @throws DependencyException * @throws FileNotFoundException + * @throws \InvalidArgumentException * @throws LinkerException * @throws NotFoundException * @throws ReflectionException * @throws RpcException * @throws RuntimeException * @throws Throwable - * @throws \InvalidArgumentException */ protected function execute( ConnectorInterface $connector, @@ -722,6 +713,9 @@ protected function execute( case Action::CLEAR: case Action::FINISH: case Action::INIT: + if (!\is_bool($result)) { + throw new \RuntimeException('$result must be a bool.'); + } $eventArg = new BoolEvent($result); break; case Action::IDENTIFY: @@ -756,13 +750,13 @@ protected function execute( * @throws DefinitionException * @throws DependencyException * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\RuntimeException * @throws LinkerException * @throws LogicException + * @throws NotAcceptableException * @throws NotFoundException * @throws ReflectionException - * @throws \InvalidArgumentException - * @throws NotAcceptableException - * @throws \JMS\Serializer\Exception\RuntimeException * @throws UnsupportedFormatException */ protected function createHandleRequest( @@ -814,10 +808,16 @@ protected function createHandleRequest( $eventArg = null; switch ($action) { case Action::ACK: + if (!$param instanceof Ack) { + throw new \RuntimeException('$param must be instance of Ack.'); + } $eventArg = new AckEvent($param); break; case Action::PUSH: case Action::DELETE: + if (!$param instanceof AbstractModel) { + throw new \RuntimeException('$param must be instance of AbstractModel.'); + } /** @var IdentityLinker $identityLinker */ $identityLinker = $this->container->get(IdentityLinker::class); $identityLinker->linkModel($param); @@ -828,10 +828,19 @@ protected function createHandleRequest( break; case Action::PULL: case Action::STATISTIC: + if (!$param instanceof QueryFilter) { + throw new \RuntimeException('$param must be instance of QueryFilter.'); + } $eventArg = new QueryFilterEvent($param); break; case Action::CLEAR: + if (!$param instanceof Identities) { + throw new \RuntimeException('$param must be instance of Identities.'); + } foreach ($param->getIdentities() as $relationType => $identities) { + if ($identities === null) { + continue; + } foreach ($identities as $identity) { /** @var IdentityLinker $identityLinker */ $identityLinker = $this->container->get(IdentityLinker::class); @@ -879,8 +888,8 @@ protected function createModelEventClassName(string $controllerName): string * @throws ApplicationException * @throws CompressionException * @throws DefinitionException - * @throws FileNotFoundException * @throws \Exception + * @throws FileNotFoundException */ protected function handleImagePush(AbstractImage ...$images): void { @@ -1012,6 +1021,7 @@ public function handleRequest(ConnectorInterface $connector, Request $request): } $controller = $this->container->get($controllerName); + \assert(\is_object($controller)); if ($controller instanceof LoggerAwareInterface) { /** @var LoggerInterface $loggerInterface */ $loggerInterface = $this->container->get(LoggerInterface::class); @@ -1036,17 +1046,17 @@ public function handleRequest(ConnectorInterface $connector, Request $request): } try { + \assert(\method_exists($controller, $action)); + /** @var AbstractModel[] $dataModels */ $dataModels = $controller->$action(...$params); foreach ($dataModels as $dataModel) { - if ($dataModel instanceof AbstractModel) { - /** @var IdentityLinker $identityLinker */ - $identityLinker = $this->container->get(IdentityLinker::class); - $identityLinker->linkModel($dataModel, ($request->getAction() === Action::DELETE)); - /** @var ChecksumLinker $checksumLinker */ - $checksumLinker = $this->container->get(ChecksumLinker::class); - $checksumLinker->link($dataModel); - } + /** @var IdentityLinker $identityLinker */ + $identityLinker = $this->container->get(IdentityLinker::class); + $identityLinker->linkModel($dataModel, ($request->getAction() === Action::DELETE)); + /** @var ChecksumLinker $checksumLinker */ + $checksumLinker = $this->container->get(ChecksumLinker::class); + $checksumLinker->link($dataModel); $result[] = $dataModel; } @@ -1088,18 +1098,23 @@ public function handleRequest(ConnectorInterface $connector, Request $request): } break; case Action::IDENTIFY: + \assert(\method_exists($controller, $action)); + /** @var ConnectorIdentification $result */ $result = $controller->$action($connector); break; default: + \assert(\method_exists($controller, $action)); $param = \count($params) > 0 ? \reset($params) : null; $result = $controller->$action($param); break; } if ($action === Action::STATISTIC && $controller instanceof StatisticInterface) { - $result = (new Statistic()) + /** @var int $statisticCount */ + $statisticCount = $result; + $result = (new Statistic()) ->setControllerName($controllerName) - ->setAvailable((int)$result); + ->setAvailable($statisticCount); } if (!$result instanceof Response) { diff --git a/src/Config/CoreConfigInterface.php b/src/Config/CoreConfigInterface.php index 1e59c7b3..35ff6dca 100755 --- a/src/Config/CoreConfigInterface.php +++ b/src/Config/CoreConfigInterface.php @@ -14,8 +14,8 @@ interface CoreConfigInterface extends ConfigInterface * @param bool|null $default * * @return bool|null - * @throws \TypeError * @throws ConfigException + * @throws \TypeError */ public function getBool(string $valueName, ?bool $default = null): ?bool; diff --git a/src/Controller/ConnectorController.php b/src/Controller/ConnectorController.php index 4f9d15db..20788d02 100755 --- a/src/Controller/ConnectorController.php +++ b/src/Controller/ConnectorController.php @@ -89,20 +89,23 @@ public function init(): bool * @return Features * @throws CoreJsonException * @throws \InvalidArgumentException - * @throws \RuntimeException * @throws \JsonException + * @throws \RuntimeException */ public function features(): Features { + /** @var array{entities?: array, flags?: array} $features */ $features = $this->fetchFeaturesData(); + /** @var array $entities */ $entities = []; - if (isset($features['entities']) && \is_array($features['entities'])) { + if (isset($features['entities'])) { $entities = $features['entities']; } + /** @var array $flags */ $flags = []; - if (isset($features['flags']) && \is_array($features['flags'])) { + if (isset($features['flags'])) { $flags = $features['flags']; } @@ -156,7 +159,7 @@ public function ack(Ack $ack): bool // Checksum linking foreach ($ack->getChecksums() as $checksum) { - if (($checksum instanceof ChecksumInterface) && !$this->checksumLinker->save($checksum)) { + if (!$this->checksumLinker->save($checksum)) { $context = [ 'endpoint' => $checksum->getForeignKey()->getEndpoint(), 'host' => $checksum->getForeignKey()->getHost(), @@ -179,8 +182,8 @@ public function ack(Ack $ack): bool * * @return Session * @throws AuthenticationException - * @throws \RuntimeException * @throws InvalidArgumentException + * @throws \RuntimeException */ public function auth(Authentication $auth): Session { @@ -214,7 +217,7 @@ public function auth(Authentication $auth): Session */ public function identify(ConnectorInterface $endpointConnector): ConnectorIdentification { - $returnBytes = static function ($data): int { + $returnBytes = static function (string $data): int { $data = \trim($data); $len = \strlen($data); if ($data === '-1') { @@ -235,10 +238,10 @@ public function identify(ConnectorInterface $endpointConnector): ConnectorIdenti }; $serverInfo = (new ConnectorServerInfo()) - ->setMemoryLimit($returnBytes(\ini_get('memory_limit'))) + ->setMemoryLimit($returnBytes(\ini_get('memory_limit') ?: '')) ->setExecutionTime((int)\ini_get('max_execution_time')) - ->setPostMaxSize($returnBytes(\ini_get('post_max_size'))) - ->setUploadMaxFilesize($returnBytes(\ini_get('upload_max_filesize'))); + ->setPostMaxSize($returnBytes(\ini_get('post_max_size') ?: '')) + ->setUploadMaxFilesize($returnBytes(\ini_get('upload_max_filesize') ?: '')); return (new ConnectorIdentification()) ->setEndpointVersion($endpointConnector->getEndpointVersion()) @@ -275,15 +278,13 @@ public function clear(?Identities $identities = null): bool if (empty($relationIdentities)) { $this->linker->clear(RelationType::getIdentityType($relationType)); } else { - if (\is_array($relationIdentities)) { - foreach ($relationIdentities as $identity) { - $endpointId = empty($identity->getEndpoint()) ? null : $identity->getEndpoint(); - $this->linker->delete( - RelationType::getModelName($relationType), - $endpointId, - $identity->getHost() - ); - } + foreach ($relationIdentities as $identity) { + $endpointId = empty($identity->getEndpoint()) ? null : $identity->getEndpoint(); + $this->linker->delete( + RelationType::getModelName($relationType), + $endpointId, + $identity->getHost() + ); } } } diff --git a/src/Definition/Action.php b/src/Definition/Action.php index b35feb1e..bfa2e3f4 100755 --- a/src/Definition/Action.php +++ b/src/Definition/Action.php @@ -19,7 +19,7 @@ final class Action IDENTIFY = 'identify', INIT = 'init'; - /** @var string[]|null */ + /** @var array|null */ protected static ?array $actions = null; /** @var string[] */ diff --git a/src/Definition/Event.php b/src/Definition/Event.php index f12800ec..080f247f 100755 --- a/src/Definition/Event.php +++ b/src/Definition/Event.php @@ -25,8 +25,8 @@ final class Event * @param string $moment * * @return string - * @throws DefinitionException * @throws CaseConverterException + * @throws DefinitionException */ public static function createCoreEventName(string $controllerName, string $actionName, string $moment): string { @@ -39,8 +39,8 @@ public static function createCoreEventName(string $controllerName, string $actio * @param string $moment * * @return string - * @throws DefinitionException * @throws CaseConverterException + * @throws DefinitionException */ public static function createEventName(string $controllerName, string $actionName, string $moment): string { @@ -75,8 +75,8 @@ public static function isMoment(string $moment): bool * @param string $moment * * @return string - * @throws DefinitionException * @throws CaseConverterException + * @throws DefinitionException */ public static function createHandleEventName(string $controllerName, string $actionName, string $moment): string { diff --git a/src/Definition/PaymentType.php b/src/Definition/PaymentType.php index 863a7421..26647d57 100755 --- a/src/Definition/PaymentType.php +++ b/src/Definition/PaymentType.php @@ -94,7 +94,7 @@ final class PaymentType WIRECARD = 'pm_wirecard', WORLDPAY = 'pm_worldpay'; - /** @var string[]|null */ + /** @var array|null */ protected static ?array $types = null; /** diff --git a/src/Http/JsonResponse.php b/src/Http/JsonResponse.php index 9e7e157b..d8852b5c 100755 --- a/src/Http/JsonResponse.php +++ b/src/Http/JsonResponse.php @@ -4,7 +4,6 @@ namespace Jtl\Connector\Core\Http; -use Doctrine\Common\Annotations\AnnotationException; use InvalidArgumentException; use Jawira\CaseConverter\CaseConverterException; use JMS\Serializer\Exception\LogicException; @@ -66,13 +65,12 @@ public function __construct( * @throws CaseConverterException * @throws DefinitionException * @throws InvalidArgumentException - * @throws RuntimeException - * @throws AnnotationException * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LogicException * @throws NotAcceptableException - * @throws UnsupportedFormatException * @throws \Psr\Log\InvalidArgumentException + * @throws RuntimeException + * @throws UnsupportedFormatException */ public function prepareAndSend(RequestPacket $requestPacket, ResponsePacket $responsePacket): self { diff --git a/src/Linker/ChecksumLinker.php b/src/Linker/ChecksumLinker.php index 440d3d96..6de13698 100755 --- a/src/Linker/ChecksumLinker.php +++ b/src/Linker/ChecksumLinker.php @@ -37,8 +37,10 @@ public function __construct(?ChecksumLoaderInterface $loader = null) public static function find(AbstractModel $model, int $type): ?ChecksumInterface { if (\method_exists($model, 'getChecksums')) { - foreach ($model->getChecksums() as $checksum) { - if ($checksum instanceof ChecksumInterface && $checksum->getType() == $type) { + /** @var ChecksumInterface[] $checksums */ + $checksums = $model->getChecksums(); + foreach ($checksums as $checksum) { + if ($checksum->getType() == $type) { return $checksum; } } @@ -57,10 +59,11 @@ public static function find(AbstractModel $model, int $type): ?ChecksumInterface public static function findByEndpoint(AbstractModel $model, string $endpoint, int $type): ?ChecksumInterface { if (\method_exists($model, 'getChecksums')) { - foreach ($model->getChecksums() as $checksum) { + /** @var ChecksumInterface[] $checksums */ + $checksums = $model->getChecksums(); + foreach ($checksums as $checksum) { if ( - $checksum instanceof ChecksumInterface - && $checksum->getType() == $type + $checksum->getType() == $type && $checksum->getForeignKey()->getEndpoint() === $endpoint ) { return $checksum; @@ -81,10 +84,11 @@ public static function findByEndpoint(AbstractModel $model, string $endpoint, in public static function findByHost(AbstractModel $model, int $host, int $type): ?ChecksumInterface { if (\method_exists($model, 'getChecksums')) { - foreach ($model->getChecksums() as $checksum) { + /** @var ChecksumInterface[] $checksums */ + $checksums = $model->getChecksums(); + foreach ($checksums as $checksum) { if ( - $checksum instanceof ChecksumInterface - && $checksum->getType() == $type + $checksum->getType() == $type && $checksum->getForeignKey()->getHost() == $host ) { return $checksum; @@ -105,51 +109,54 @@ public static function findByHost(AbstractModel $model, int $host, int $type): ? public function link(AbstractModel $model, ?int $type = null): void { if (!\is_null($this->loader) && \method_exists($model, 'getChecksums')) { + /** @var ChecksumInterface[] $checksums */ $checksums = $model->getChecksums(); foreach ($checksums as &$checksum) { - if ($checksum instanceof ChecksumInterface && ($type === null || $checksum->getType() === $type)) { + if ($type === null || $checksum->getType() === $type) { $this->logger->debug('Checksum linking type ({type})...', ['type' => $type]); if ( \method_exists($model, 'getId') - && $model->getId()->getEndpoint() !== null - && $model->getId()->getEndpoint() !== '' ) { - $checksum->setEndpoint( - $this->loader->read($model->getId()->getEndpoint(), $checksum->getType()) - ); + /** @var \Jtl\Connector\Core\Model\Identity $modelId */ + $modelId = $model->getId(); + if ($modelId->getEndpoint() !== '') { + $checksum->setEndpoint( + $this->loader->read($modelId->getEndpoint(), $checksum->getType()) + ); - if ($checksum->getEndpoint() !== null && $checksum->getEndpoint() !== '') { - if (($checksum->getEndpoint() !== $checksum->getHost())) { + if ($checksum->getEndpoint() !== '') { + if (($checksum->getEndpoint() !== $checksum->getHost())) { + $this->logger->debug( + 'Changed checksum for endpoint ({endpoint}) type ({type})', + [ + 'endpoint' => $modelId->getEndpoint(), + 'type' => $type, + ] + ); + $checksum->setHasChanged(true); + $this->loader->delete($modelId->getEndpoint(), $checksum->getType()); + $this->loader->write( + $modelId->getEndpoint(), + $checksum->getType(), + $checksum->getHost() + ); + } + } else { $this->logger->debug( - 'Changed checksum for endpoint ({endpoint}) type ({type})', + 'Write new checksum for endpoint ({endpoint}) type ({type})', [ - 'endpoint' => $model->getId()->getEndpoint(), + 'endpoint' => $modelId->getEndpoint(), 'type' => $type, ] ); $checksum->setHasChanged(true); - $this->loader->delete($model->getId()->getEndpoint(), $checksum->getType()); $this->loader->write( - $model->getId()->getEndpoint(), + $modelId->getEndpoint(), $checksum->getType(), $checksum->getHost() ); } - } else { - $this->logger->debug( - 'Write new checksum for endpoint ({endpoint}) type ({type})', - [ - 'endpoint' => $model->getId()->getEndpoint(), - 'type' => $type, - ] - ); - $checksum->setHasChanged(true); - $this->loader->write( - $model->getId()->getEndpoint(), - $checksum->getType(), - $checksum->getHost() - ); } } else { $this->logger->debug('New checksum with empty endpoint type ({type})', ['type' => $type]); diff --git a/src/Linker/IdentityLinker.php b/src/Linker/IdentityLinker.php index dd74e739..d156f7f4 100755 --- a/src/Linker/IdentityLinker.php +++ b/src/Linker/IdentityLinker.php @@ -224,8 +224,8 @@ protected function buildKey(mixed $id, int $identityType, string $cacheType): st * * @return bool * @throws DefinitionException - * @throws LinkerException * @throws \InvalidArgumentException + * @throws LinkerException */ public function propertyHostIdExists(string $modelName, string $property, int $hostId): bool { @@ -262,8 +262,8 @@ public function isValidHostId(mixed $hostId): bool * * @return bool * @throws DefinitionException - * @throws LinkerException * @throws \InvalidArgumentException + * @throws LinkerException */ public function hostIdExists(string $modelName, int $hostId): bool { diff --git a/src/Logger/Handler/ChunkedHandler.php b/src/Logger/Handler/ChunkedHandler.php index 7f391ed0..5d9d9eeb 100644 --- a/src/Logger/Handler/ChunkedHandler.php +++ b/src/Logger/Handler/ChunkedHandler.php @@ -31,34 +31,26 @@ public function __construct(HandlerInterface $nextHandler, ?int $chunkSize = nul /** * @inheritDoc */ - public function isHandling($record): bool + public function isHandling(LogRecord $record): bool { return $this->nextHandler->isHandling($record); } /** - * @param LogRecord|array $record + * @param LogRecord $record * * @return bool */ - public function handle(LogRecord|array $record): bool + public function handle(LogRecord $record): bool { // false means continue to bubble $return = false; - $useArray = false; + $message = $record->message; + /** @var array $extra */ + $extra = $record->extra; - if (!\is_array($record) && \class_exists(LogRecord::class) && $record instanceof LogRecord) { - $message = $record->message; - /** @var array $extra */ - $extra = $record->extra; - } else { - $message = $record['message']; - /** @var array $extra */ - $extra = $record['extra']; - $useArray = true; - } - if ($this->chunkSize > 0 && \is_string($message) && \strlen($message) > $this->chunkSize) { + if ($this->chunkSize > 0 && \strlen($message) > $this->chunkSize) { $chunks = \str_split($message, $this->chunkSize); $total = \count($chunks); $recordId = \md5($message); @@ -66,34 +58,20 @@ public function handle(LogRecord|array $record): bool foreach ($chunks as $key => $chunk) { $message = \sprintf("(part %d/%d) %s", $key, $total, $chunk); - if ($useArray) { - $newRecord = [ - 'level' => $record['level'], - 'context' => $record['context'], - 'channel' => $record['channel'], - 'datetime' => $record['datetime'], - 'extra' => $extra, - 'message' => $message, - ]; - } else { - /** @var LogRecord $record */ - $newRecord = new LogRecord( - $record->datetime, - $record->channel, - $record->level, - $message, - $record->context, - $extra, - ); - } + $newRecord = new LogRecord( + $record->datetime, + $record->channel, + $record->level, + $message, + $record->context, + $extra, + ); - /** @var LogRecord $newRecord */ // to force phpstan to shut up! $return = $this->nextHandler->handle($newRecord) ?: $return; } return $return; } - /** @var LogRecord $record */ // to force phpstan to shut up! return $this->nextHandler->handle($record); } @@ -106,12 +84,14 @@ public function handle(LogRecord|array $record): bool */ public function setFormatter(FormatterInterface $formatter): HandlerInterface { - if ( - $this->nextHandler instanceof FormattableHandlerInterface - || \method_exists($this->nextHandler, 'setFormatter') - ) { + if ($this->nextHandler instanceof FormattableHandlerInterface) { return $this->nextHandler->setFormatter($formatter); } + if (\method_exists($this->nextHandler, 'setFormatter')) { + /** @var HandlerInterface $result */ + $result = $this->nextHandler->setFormatter($formatter); + return $result; + } throw new \UnexpectedValueException( 'The nested handler of type ' . \get_class($this->nextHandler) . ' does not support formatters.' ); @@ -123,12 +103,14 @@ public function setFormatter(FormatterInterface $formatter): HandlerInterface */ public function getFormatter(): FormatterInterface { - if ( - $this->nextHandler instanceof FormattableHandlerInterface - || \method_exists($this->nextHandler, 'getFormatter') - ) { + if ($this->nextHandler instanceof FormattableHandlerInterface) { return $this->nextHandler->getFormatter(); } + if (\method_exists($this->nextHandler, 'getFormatter')) { + /** @var FormatterInterface $result */ + $result = $this->nextHandler->getFormatter(); + return $result; + } throw new \UnexpectedValueException( 'The nested handler of type ' . \get_class($this->nextHandler) . ' does not support formatters.' ); diff --git a/src/Logger/LoggerService.php b/src/Logger/LoggerService.php index 5de4b97e..5e4c542f 100755 --- a/src/Logger/LoggerService.php +++ b/src/Logger/LoggerService.php @@ -44,11 +44,11 @@ class LoggerService protected FormatterInterface $formatter; protected string $logDir; - protected string|int|LogLevel $logLevel; + protected string|int $logLevel; protected int $maxFiles = 2; // Final handler that is wrapped by FilterHandler - protected HandlerInterface $handler; + protected ?HandlerInterface $handler = null; // Handler that writes to combined log file protected HandlerInterface $combinedHandler; @@ -129,10 +129,10 @@ public function setLogLevel(int|string $logLevel): void protected function createHandler(): void { // needed if we change the level - if (isset($this->handler)) { + if ($this->handler !== null) { $this->handler->close(); } - $logLevel = MonoLogger::toMonologLevel($this->logLevel); // @phpstan-ignore-line + $logLevel = $this->resolveLogLevel($this->logLevel); $handler = new FilterHandler($this->combinedHandler, $logLevel); if (isset($this->formatter)) { $handler->setFormatter($this->formatter); @@ -140,6 +140,41 @@ protected function createHandler(): void $this->handler = $handler; } + /** + * @param int|string|Level $level + * + * @return Level + * @throws \InvalidArgumentException + */ + protected function resolveLogLevel(int|string|Level $level): Level + { + if ($level instanceof Level) { + return $level; + } + if (\is_int($level)) { + return Level::from($level); + } + + /** @var array $nameMap */ + $nameMap = [ + 'debug' => Level::Debug, + 'info' => Level::Info, + 'notice' => Level::Notice, + 'warning' => Level::Warning, + 'error' => Level::Error, + 'critical' => Level::Critical, + 'alert' => Level::Alert, + 'emergency' => Level::Emergency, + ]; + + $normalized = \strtolower($level); + if (isset($nameMap[$normalized])) { + return $nameMap[$normalized]; + } + + throw new \InvalidArgumentException(\sprintf('Unknown log level: %s', $level)); + } + /** * @param ProcessorInterface $processor * @@ -168,22 +203,18 @@ public function pushProcessor(ProcessorInterface $processor): self * * @return HandlerInterface * @throws InvalidArgumentException - * @throws UnexpectedValueException * @throws \InvalidArgumentException + * @throws UnexpectedValueException */ protected function createChannelSpecificHandler(string $channel, int|string|Level $logLevel): HandlerInterface { $fileName = \sprintf('%s/%s.log', $this->logDir, $channel); - $monologLevel = MonoLogger::toMonologLevel($logLevel); // @phpstan-ignore-line + $monologLevel = $this->resolveLogLevel($logLevel); $handler = new RotatingFileHandler($fileName, $this->maxFiles, $monologLevel); if ($this->useChunkedHandler) { $handler = new ChunkedHandler($handler); } - if ( - isset($this->formatter) - && ($handler instanceof FormattableHandlerInterface // @phpstan-ignore-line - || \method_exists($handler, 'setFormatter')) - ) { + if (isset($this->formatter)) { $handler->setFormatter($this->formatter); } return $handler; @@ -193,10 +224,10 @@ protected function createChannelSpecificHandler(string $channel, int|string|Leve * @param string $channel * * @return MonoLogger + * @throws \Exception * @throws InvalidArgumentException - * @throws UnexpectedValueException * @throws \InvalidArgumentException - * @throws \Exception + * @throws UnexpectedValueException */ public function get(string $channel): MonoLogger { @@ -205,9 +236,10 @@ public function get(string $channel): MonoLogger $this->channels[$channel] = new MonoLogger($channel); } - $logLevel = MonoLogger::toMonologLevel($this->logLevel); // @phpstan-ignore-line + $logLevel = $this->resolveLogLevel($this->logLevel); if (!$this->channels[$channel]->isHandling($logLevel)) { $handler = $this->createChannelSpecificHandler($channel, $logLevel); + \assert($this->handler !== null); $this->channels[$channel]->pushHandler($this->handler); $this->channels[$channel]->pushHandler($handler); foreach ($this->processors as $processor) { @@ -263,8 +295,8 @@ public function setFormatter(FormatterInterface $formatter): self * * @return $this * @throws LoggerException - * @throws RuntimeException * @throws ReflectionException + * @throws RuntimeException */ public function setFormat(string $format, array $arguments = []): self { diff --git a/src/Logger/Processor/RequestProcessor.php b/src/Logger/Processor/RequestProcessor.php index 7b227558..801202a1 100644 --- a/src/Logger/Processor/RequestProcessor.php +++ b/src/Logger/Processor/RequestProcessor.php @@ -17,15 +17,20 @@ class RequestProcessor implements ProcessorInterface */ public function __construct() { + /** @var array $server */ + $server = $_SERVER; + /** @var array $get */ + $get = $_GET; + $this->extraFields = [ - 'http_method' => $_SERVER['REQUEST_METHOD'] ?? '', - 'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? '', - 'domain' => $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? '' + 'http_method' => $server['REQUEST_METHOD'] ?? '', + 'user_agent' => $server['HTTP_USER_AGENT'] ?? '', + 'domain' => $server['HTTP_HOST'] ?? $server['SERVER_NAME'] ?? '' ]; // strip jtlauth value from uri - $uri = $_SERVER['REQUEST_URI'] ?? ''; - $session = $_GET['jtlauth'] ?? ''; + $uri = $server['REQUEST_URI'] ?? ''; + $session = $get['jtlauth'] ?? ''; if ($session !== '') { // string replace is faster as regex $uri = \str_replace(\sprintf('jtlauth=%s', $session), 'jtlauth=***', $uri); @@ -56,20 +61,13 @@ public function __construct() } /** - * multiple param and return types are needed because some connectors use an older version of monolog - * - * @param array{extra:array}|LogRecord $record + * @param LogRecord $record * - * @phpstan-param array{extra:array} $record - * @return array{extra:array}|LogRecord + * @return LogRecord */ - public function __invoke(array|LogRecord $record): array|LogRecord + public function __invoke(LogRecord $record): LogRecord { - if (\is_array($record)) { - $record['extra'] = \array_merge($record['extra'], $this->extraFields); - } elseif ($record instanceof LogRecord) { - $record->extra = \array_merge($record->extra, $this->extraFields); - } + $record->extra = \array_merge($record->extra, $this->extraFields); return $record; } diff --git a/src/Logger/Processor/WarningProcessor.php b/src/Logger/Processor/WarningProcessor.php index 1de20d15..40becffd 100644 --- a/src/Logger/Processor/WarningProcessor.php +++ b/src/Logger/Processor/WarningProcessor.php @@ -26,21 +26,17 @@ public function __construct(Warnings $warnings) /** - * multiple param and return types are needed because some connectors use an older version of monolog + * @param LogRecord $record * - * @template T of array{message:string,context:array}|LogRecord - * @param array|LogRecord $record - * @phpstan-param T $record - * - * @return T + * @return LogRecord */ - public function __invoke(array|LogRecord $record): array|LogRecord + public function __invoke(LogRecord $record): LogRecord { if ( - isset($record['context'][self::SEND_TO_WAWI]) && - (bool)$record['context'][self::SEND_TO_WAWI] + isset($record->context[self::SEND_TO_WAWI]) && + (bool)$record->context[self::SEND_TO_WAWI] ) { - $this->warnings->addWarning($record['message']); + $this->warnings->addWarning($record->message); } return $record; diff --git a/src/Model/AbstractImage.php b/src/Model/AbstractImage.php index b96e386b..d8c2d895 100755 --- a/src/Model/AbstractImage.php +++ b/src/Model/AbstractImage.php @@ -61,10 +61,6 @@ abstract class AbstractImage extends AbstractIdentity #[Serializer\Accessor(getter: 'getSort', setter: 'setSort')] protected int $sort = 1; - /** @var \ReflectionClass */ - #[Serializer\Exclude] - protected \ReflectionClass $reflectionClass; - /** * AbstractImage constructor. * @@ -73,7 +69,6 @@ abstract class AbstractImage extends AbstractIdentity */ public function __construct(string $endpoint = '', int $host = 0) { - $this->reflectionClass = new \ReflectionClass($this); parent::__construct($endpoint, $host); $this->foreignKey = new Identity(); } @@ -267,7 +262,7 @@ public function getIdentificationStrings(): array */ public function getRelationType(): string { - $modelName = $this->reflectionClass->getShortName(); + $modelName = (new \ReflectionClass($this))->getShortName(); $imagePos = \strpos($modelName, 'Image'); if ($imagePos === false) { throw new \RuntimeException('$imagePos must not be false!'); diff --git a/src/Model/Generator/AbstractModelFactory.php b/src/Model/Generator/AbstractModelFactory.php index 792ed115..4159ed2f 100755 --- a/src/Model/Generator/AbstractModelFactory.php +++ b/src/Model/Generator/AbstractModelFactory.php @@ -4,7 +4,6 @@ namespace Jtl\Connector\Core\Model\Generator; -use Doctrine\Common\Annotations\AnnotationException; use Faker\Factory; use Faker\Generator; use JMS\Serializer\Exception\InvalidArgumentException; @@ -39,7 +38,6 @@ abstract class AbstractModelFactory * @param Generator|null $faker * @param Serializer|null $serializer * - * @throws AnnotationException * @throws InvalidArgumentException * @throws \InvalidArgumentException * @throws LogicException @@ -132,7 +130,9 @@ public function makeArray(int $quantity, array $specificOverrides = [], array $g { $models = []; for ($i = 0; $i < $quantity; $i++) { - $models[] = $this->makeOneArray(\array_merge($globalOverrides, $specificOverrides[$i] ?? [])); + /** @var array $specificOverride */ + $specificOverride = $specificOverrides[$i] ?? []; + $models[] = $this->makeOneArray(\array_merge($globalOverrides, $specificOverride)); } return $models; @@ -171,19 +171,21 @@ public function makeOne(array $override = []): AbstractModel * * @return array * @throws LogicException - * @throws RuntimeException * @throws NotAcceptableException + * @throws RuntimeException * @throws UnsupportedFormatException */ public function make(int $quantity, array $specificOverrides = [], array $globalOverrides = []): array { $models = []; for ($i = 0; $i < $quantity; $i++) { - /** @var AbstractModel $model */ - $model = $this->serializer->fromArray( - $this->makeOneArray(\array_merge($globalOverrides, $specificOverrides[$i] ?? [])), + /** @var array $specificOverride */ + $specificOverride = $specificOverrides[$i] ?? []; + $model = $this->serializer->fromArray( + $this->makeOneArray(\array_merge($globalOverrides, $specificOverride)), $this->getModelClass() ); + \assert($model instanceof AbstractModel); $models[] = $model; } @@ -210,8 +212,8 @@ public function makeIdentity(int $identityType): mixed * @param int $identityType * * @return array{0: string, 1: int} - * @throws \RuntimeException * @throws \InvalidArgumentException + * @throws \RuntimeException */ public function makeIdentityArray(int $identityType): array { diff --git a/src/Model/Generator/ProductFactory.php b/src/Model/Generator/ProductFactory.php index 36a64f6c..f0d99b70 100755 --- a/src/Model/Generator/ProductFactory.php +++ b/src/Model/Generator/ProductFactory.php @@ -27,8 +27,8 @@ public function makeOneProductVariant(?array $i18ns = null): array * @param array>|null $i18ns * * @return array - * @throws \RuntimeException * @throws \Exception + * @throws \RuntimeException */ public function makeOneProductVariantArray(?array $i18ns = null): array { @@ -109,8 +109,8 @@ public function makeOneProductVariantArray(?array $i18ns = null): array /** * @return array - * @throws \RuntimeException * @throws \Exception + * @throws \RuntimeException */ protected function makeFakeArray(): array { diff --git a/src/Model/Generator/ProductPriceFactory.php b/src/Model/Generator/ProductPriceFactory.php index 2a3f4246..44f0b9d8 100755 --- a/src/Model/Generator/ProductPriceFactory.php +++ b/src/Model/Generator/ProductPriceFactory.php @@ -56,18 +56,22 @@ public function makeItemsArray(bool $withBulkPrices = false): array if ($withBulkPrices === true) { $pricesCount = \random_int(1, \random_int(1, 30)); - $maxQuantity = \random_int($pricesCount, \random_int($pricesCount, 500)); // @phpstan-ignore-line + $maxQuantity = $pricesCount + \random_int(0, 500); $step = (int)\floor($maxQuantity / $pricesCount); - $priceStep = \floor($items[0]['netPrice'] / $pricesCount); + /** @var float $firstNetPrice */ + $firstNetPrice = $items[0]['netPrice']; + $priceStep = \floor($firstNetPrice / $pricesCount); $quantity = 0; for ($i = 0; $i < $pricesCount; $i++) { $quantity += $step; - $minPrice = $items[$i]['netPrice'] - $priceStep; - if ($minPrice > $items[$i]['netPrice'] || $minPrice < 0) { - $minPrice = (($items[$i]['netPrice'] - 0.1) / 2); + /** @var float $currentNetPrice */ + $currentNetPrice = $items[$i]['netPrice']; + $minPrice = $currentNetPrice - $priceStep; + if ($minPrice > $currentNetPrice || $minPrice < 0) { + $minPrice = (($currentNetPrice - 0.1) / 2); } - $price = $this->faker->randomFloat(4, $minPrice, $items[$i]['netPrice']); + $price = $this->faker->randomFloat(4, $minPrice, $currentNetPrice); $items[] = $this->makeItemArray(['quantity' => $quantity, 'netPrice' => $price]); } } diff --git a/src/Model/Generator/ProductVariationFactory.php b/src/Model/Generator/ProductVariationFactory.php index 43d92c60..da4e94a5 100755 --- a/src/Model/Generator/ProductVariationFactory.php +++ b/src/Model/Generator/ProductVariationFactory.php @@ -15,15 +15,15 @@ class ProductVariationFactory extends AbstractModelFactory * @return array{ * id: array, * sort: int, - * i18ns: array, + * i18ns: array>, * values: array{} * } - * @throws \RuntimeException * @throws Exception + * @throws \RuntimeException */ protected function makeFakeArray(): array { - /** @var ProductVariationI18n[] $i18ns */ + /** @var array> $i18ns */ $i18ns = $this->getFactory('ProductVariationI18n')->makeArray(\random_int(1, 5)); return [ diff --git a/src/Model/Generator/TaxRateFactory.php b/src/Model/Generator/TaxRateFactory.php index c7a8fc54..7ac0943a 100755 --- a/src/Model/Generator/TaxRateFactory.php +++ b/src/Model/Generator/TaxRateFactory.php @@ -16,9 +16,9 @@ class TaxRateFactory extends AbstractModelFactory /** * @return array - * @throws \RuntimeException * @throws ExtensionNotFound * @throws MustNotBeNullException + * @throws \RuntimeException * @throws \TypeError */ protected function makeFakeArray(): array diff --git a/src/Model/QueryFilter.php b/src/Model/QueryFilter.php index c7871ba4..02117324 100755 --- a/src/Model/QueryFilter.php +++ b/src/Model/QueryFilter.php @@ -206,16 +206,16 @@ public function overrideFilter(string $oldKey, string $newKey, mixed $value = nu */ public function set(\stdClass $obj): void { - if (!\is_object($obj)) { - return; - } - if (isset($obj->limit)) { - $this->setLimit($obj->limit); + /** @var int $limit */ + $limit = $obj->limit; + $this->setLimit($limit); } - if (isset($obj->filters) && \is_object($obj->filters)) { - $this->setFilters(\get_object_vars($obj->filters)); + if (isset($obj->filters) && $obj->filters instanceof \stdClass) { + /** @var array $filters */ + $filters = \get_object_vars($obj->filters); + $this->setFilters($filters); } } } diff --git a/src/Model/TranslatableAttribute.php b/src/Model/TranslatableAttribute.php index 6eff07a2..12cab83d 100755 --- a/src/Model/TranslatableAttribute.php +++ b/src/Model/TranslatableAttribute.php @@ -216,8 +216,8 @@ public function findTranslation(string $languageIso): ?TranslatableAttributeI18n * @param string $languageIso * * @return bool|float|int|string|array|null - * @throws TranslatableAttributeException * @throws JsonException + * @throws TranslatableAttributeException */ public function findValue(string $languageIso): array|float|bool|int|string|null { @@ -233,12 +233,12 @@ public function findValue(string $languageIso): array|float|bool|int|string|null * @param string|null $type * * @return array|null> - * @throws TranslatableAttributeException * @throws JsonException + * @throws TranslatableAttributeException */ public function getValues(?string $type = null): array { - $type = $type ?? $this->type ?? self::TYPE_STRING; + $type = $type ?? $this->type; $values = []; foreach ($this->i18ns as $i18n) { $values[$i18n->getLanguageIso()] = $i18n->getValue($type); diff --git a/src/Model/TranslatableAttributeI18n.php b/src/Model/TranslatableAttributeI18n.php index d28e6953..72d642e4 100755 --- a/src/Model/TranslatableAttributeI18n.php +++ b/src/Model/TranslatableAttributeI18n.php @@ -166,8 +166,8 @@ public function getValue(string $castToType = TranslatableAttribute::TYPE_STRING * @param mixed $value * * @return $this - * @throws TranslatableAttributeException * @throws \JsonException + * @throws TranslatableAttributeException */ public function setValue(mixed $value): self { diff --git a/src/Rpc/Packet.php b/src/Rpc/Packet.php index 7f003811..a1a781d8 100755 --- a/src/Rpc/Packet.php +++ b/src/Rpc/Packet.php @@ -4,7 +4,6 @@ namespace Jtl\Connector\Core\Rpc; -use Doctrine\Common\Annotations\AnnotationException; use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Exception\InvalidArgumentException; use JMS\Serializer\Exception\LogicException; @@ -100,11 +99,10 @@ public function setId(string $id): self * * @return mixed[] * @throws InvalidArgumentException - * @throws RuntimeException - * @throws AnnotationException * @throws \InvalidArgumentException * @throws LogicException * @throws NotAcceptableException + * @throws RuntimeException * @throws UnsupportedFormatException */ public function toArray(?JmsSerializer $serializer = null): array diff --git a/src/Rpc/RequestPacket.php b/src/Rpc/RequestPacket.php index fa9b58da..67ed63b0 100755 --- a/src/Rpc/RequestPacket.php +++ b/src/Rpc/RequestPacket.php @@ -4,7 +4,6 @@ namespace Jtl\Connector\Core\Rpc; -use Doctrine\Common\Annotations\AnnotationException; use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Exception\InvalidArgumentException; use JMS\Serializer\Exception\LogicException; @@ -47,12 +46,11 @@ class RequestPacket extends Packet * * @return RequestPacket * @throws InvalidArgumentException - * @throws RuntimeException - * @throws AnnotationException * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\RuntimeException * @throws LogicException * @throws NotAcceptableException - * @throws \JMS\Serializer\Exception\RuntimeException + * @throws RuntimeException * @throws UnsupportedFormatException */ public static function createFromJtlrpc(string $jtlrpc, ?JmsSerializer $serializer = null): RequestPacket diff --git a/src/Rpc/ResponsePacket.php b/src/Rpc/ResponsePacket.php index cd0c5ecd..3ec3bfdc 100755 --- a/src/Rpc/ResponsePacket.php +++ b/src/Rpc/ResponsePacket.php @@ -66,7 +66,7 @@ public function isValid(): bool if (!empty($this->warnings)) { foreach ($this->warnings as $warning) { - if (!\is_string($warning)) { + if ($warning === '') { $isValid = false; } } diff --git a/src/Serializer/Handler/IdentityHandler.php b/src/Serializer/Handler/IdentityHandler.php index b3eb9fe6..a980bf69 100755 --- a/src/Serializer/Handler/IdentityHandler.php +++ b/src/Serializer/Handler/IdentityHandler.php @@ -58,7 +58,8 @@ public function deserializeIdentity( $identityObject = new Identity($identity[0], $identity[1]); $currentObject = $visitor->getCurrentObject(); if ($identity[1] > 0 && !\is_null($currentObject)) { - $modelName = (new \ReflectionClass($currentObject))->getShortName(); + $modelName = (new \ReflectionClass($currentObject))->getShortName(); + /** @var array $currentPath */ $currentPath = $context->getCurrentPath(); $propertyName = \end($currentPath); if ($propertyName !== false && Model::isIdentityProperty($modelName, $propertyName)) { diff --git a/src/Serializer/SerializerBuilder.php b/src/Serializer/SerializerBuilder.php index b9f1a89d..a4f34352 100755 --- a/src/Serializer/SerializerBuilder.php +++ b/src/Serializer/SerializerBuilder.php @@ -27,8 +27,8 @@ class SerializerBuilder * * @return JmsBuilder * @throws InvalidArgumentException - * @throws RuntimeException * @throws LogicException + * @throws RuntimeException */ public static function create(?string $cacheDir = null): JmsBuilder { diff --git a/src/Serializer/Subscriber/CrossSellingSubscriber.php b/src/Serializer/Subscriber/CrossSellingSubscriber.php index 08d8120c..eb8cbd7c 100755 --- a/src/Serializer/Subscriber/CrossSellingSubscriber.php +++ b/src/Serializer/Subscriber/CrossSellingSubscriber.php @@ -33,16 +33,17 @@ public function onPreDeserialize(PreDeserializeEvent $event): void { $className = $event->getType()['name'] ?? ''; if ($className === CrossSelling::class) { + /** @var array{productId?: array{0: string, 1: int}, items?: array>} $data */ $data = $event->getData(); - $productId = $data['productId'][1] ?? 0; // @phpstan-ignore-line - if (isset($data['items']) && \is_array($data['items'])) { // @phpstan-ignore-line + $productId = $data['productId'][1] ?? 0; + if (isset($data['items'])) { foreach ($data['items'] as $i => $item) { - if (!isset($data['items'][$i]['id'])) { // @phpstan-ignore-line + if (!isset($data['items'][$i]['id'])) { + /** @var array{crossSellingGroupId?: array{0: string, 1: int}} $item */ $crossSellingGroupId = $item['crossSellingGroupId'][1] ?? 0; - - $itemId = self::cantorPairingFunction($productId, $crossSellingGroupId); // @phpstan-ignore-line + $itemId = self::cantorPairingFunction($productId, $crossSellingGroupId); if ($productId !== 0 && $crossSellingGroupId !== 0 && $itemId < \PHP_INT_MAX) { - $data['items'][$i]['id'] = [ // @phpstan-ignore-line + $data['items'][$i]['id'] = [ '', $itemId, ]; diff --git a/src/Serializer/Subscriber/ImageSubscriber.php b/src/Serializer/Subscriber/ImageSubscriber.php index 732dcd6a..2589c09a 100755 --- a/src/Serializer/Subscriber/ImageSubscriber.php +++ b/src/Serializer/Subscriber/ImageSubscriber.php @@ -56,8 +56,9 @@ public function onPostSerialize(ObjectEvent $event): void $id = clone $object->getId(); $id->setEndpoint(\sprintf('%s#=#%s', $object->getRelationType(), $id->getEndpoint())); $serializedId = $id->toArray(); - $event->getVisitor() // @phpstan-ignore-line - ->visitProperty(new StaticPropertyMetadata('', 'id', $serializedId), $serializedId); + /** @var \JMS\Serializer\JsonSerializationVisitor $visitor */ + $visitor = $event->getVisitor(); + $visitor->visitProperty(new StaticPropertyMetadata('', 'id', $serializedId), $serializedId); } } @@ -65,8 +66,8 @@ public function onPostSerialize(ObjectEvent $event): void * @param ObjectEvent $event * * @return void - * @throws SerializerException * @throws CaseConverterException + * @throws SerializerException */ public function onPostDeserialize(ObjectEvent $event): void { diff --git a/src/Serializer/Subscriber/LanguageIsoSubscriber.php b/src/Serializer/Subscriber/LanguageIsoSubscriber.php index f2ce39f0..50a0aac1 100755 --- a/src/Serializer/Subscriber/LanguageIsoSubscriber.php +++ b/src/Serializer/Subscriber/LanguageIsoSubscriber.php @@ -56,7 +56,9 @@ public function onPostSerialize(ObjectEvent $event): void $languageIso = $this->languages->fromISO_639_1($languageIso)->toISO_639_2b(); } - $event->getVisitor()->visitProperty( // @phpstan-ignore-line + /** @var \JMS\Serializer\JsonSerializationVisitor $visitor */ + $visitor = $event->getVisitor(); + $visitor->visitProperty( new StaticPropertyMetadata('', 'languageISO', $languageIso), $languageIso ); @@ -72,7 +74,9 @@ public function onPreDeserialize(PreDeserializeEvent $event): void { $data = $event->getData(); if (\is_array($data) && isset($data['languageISO']) && !isset($data['languageIso'])) { - $language = $this->languages->fromISO_639_2b($data['languageISO']); + /** @var string $languageISO */ + $languageISO = $data['languageISO']; + $language = $this->languages->fromISO_639_2b($languageISO); $data['languageIso'] = $language->toISO_639_1(); $event->setData($data); } diff --git a/src/Serializer/Subscriber/ProductStockLevelSubscriber.php b/src/Serializer/Subscriber/ProductStockLevelSubscriber.php index d88c008a..a6d129a7 100755 --- a/src/Serializer/Subscriber/ProductStockLevelSubscriber.php +++ b/src/Serializer/Subscriber/ProductStockLevelSubscriber.php @@ -35,9 +35,9 @@ public function onPostSerialize(ObjectEvent $event): void $model = $event->getObject(); if ($model instanceof Product) { $stockLevel = ['stockLevel' => $model->getStockLevel()]; - $event // @phpstan-ignore-line - ->getVisitor() - ->visitProperty( + /** @var \JMS\Serializer\JsonSerializationVisitor $visitor */ + $visitor = $event->getVisitor(); + $visitor->visitProperty( new StaticPropertyMetadata('', 'stockLevel', $stockLevel), $stockLevel ); diff --git a/src/Session/SessionHelper.php b/src/Session/SessionHelper.php index 217ef28f..1058ff37 100755 --- a/src/Session/SessionHelper.php +++ b/src/Session/SessionHelper.php @@ -45,6 +45,7 @@ public static function createByObjectClass(object $object): self */ public function get(string $name, mixed $default = null): mixed { + /** @var array> $_SESSION */ return $_SESSION[$this->namespace][$name] ?? $default; } @@ -60,6 +61,7 @@ public function & __get(string $name): mixed throw new SessionException("The '{$name}' key must be a non-empty string"); } + /** @var array> $_SESSION */ $value = &$_SESSION[$this->namespace][$name] ?? null; return $value; @@ -88,6 +90,7 @@ public function __set(string $name, mixed $value): void */ public function set(string $name, mixed $value): self { + /** @var array> $_SESSION */ $_SESSION[$this->namespace][$name] = $value; return $this; @@ -115,6 +118,7 @@ public function __isset(string $name): bool */ public function has(string $name): bool { + /** @var array> $_SESSION */ return isset($_SESSION[$this->namespace][$name]); } @@ -141,6 +145,7 @@ public function __unset(string $name): void public function unset(string $name): self { if ($this->has($name)) { + /** @var array> $_SESSION */ unset($_SESSION[$this->namespace][$name]); } diff --git a/src/Session/SqliteSessionHandler.php b/src/Session/SqliteSessionHandler.php index ab8a5979..9580f823 100755 --- a/src/Session/SqliteSessionHandler.php +++ b/src/Session/SqliteSessionHandler.php @@ -28,9 +28,9 @@ class SqliteSessionHandler implements SessionHandlerInterface, LoggerAwareInterf * * @param string $databaseDir * - * @throws SessionException * @throws DatabaseException * @throws \RuntimeException + * @throws SessionException */ public function __construct(string $databaseDir) { @@ -167,8 +167,8 @@ protected function createReadQuery(string $sessionId, int $expiresAt): string * * @return bool * @throws DatabaseException - * @throws \RuntimeException * @throws InvalidArgumentException + * @throws \RuntimeException * @noinspection PhpParameterNameChangedDuringInheritanceInspection */ #[ReturnTypeWillChange] diff --git a/src/Subscriber/RequestParamsTransformSubscriber.php b/src/Subscriber/RequestParamsTransformSubscriber.php index 5ca452c9..c46fcd71 100755 --- a/src/Subscriber/RequestParamsTransformSubscriber.php +++ b/src/Subscriber/RequestParamsTransformSubscriber.php @@ -85,10 +85,12 @@ public function transformProductData(array $products): array if (!isset($products[$i]['prices'])) { throw new \RuntimeException('unexpected array structure.'); } - foreach ($products[$i]['prices'] as $j => $productPrice) { - /** @var array $productPrice */ - $products[$i]['prices'][$j] = self::sortProductPriceItems($productPrice); + /** @var array> $prices */ + $prices = $products[$i]['prices']; + foreach ($prices as $j => $productPrice) { + $prices[$j] = self::sortProductPriceItems($productPrice); } + $products[$i]['prices'] = $prices; } } @@ -103,10 +105,10 @@ public function transformProductData(array $products): array protected static function sortProductPriceItems(array $productPrice): array { if (isset($productPrice['items'])) { - /** @var array $items */ + /** @var array $items */ $items = $productPrice['items']; - \usort($items, static function ($a, $b) { - return ($a['quantity'] ?? 0) - ($b['quantity'] ?? 0); + \usort($items, static function (array $a, array $b): int { + return (int)(($a['quantity'] ?? 0) - ($b['quantity'] ?? 0)); }); $productPrice['items'] = $items; } diff --git a/src/SyncError/SqliteSyncErrorCollector.php b/src/SyncError/SqliteSyncErrorCollector.php index 7d117725..13b13ffa 100644 --- a/src/SyncError/SqliteSyncErrorCollector.php +++ b/src/SyncError/SqliteSyncErrorCollector.php @@ -177,6 +177,7 @@ public function hasErrors(): bool $row = $result->fetchArray(\SQLITE3_NUM); + /** @var array{0: int}|false $row */ return \is_array($row) && (int)$row[0] > 0; } diff --git a/src/System/Check.php b/src/System/Check.php index b89baef7..d2a0ac9b 100755 --- a/src/System/Check.php +++ b/src/System/Check.php @@ -16,7 +16,8 @@ class Check public static function run(): void { // PHP - if (!\version_compare(\PHP_VERSION, Application::MIN_PHP_VERSION, '>=')) { + $phpVersion = \PHP_VERSION; + if (\version_compare($phpVersion, Application::MIN_PHP_VERSION, '<')) { throw new MissingRequirementException( \sprintf( 'The connector needs at least PHP version %s, %s given', diff --git a/src/Utilities/Money.php b/src/Utilities/Money.php index 6b1c3035..98524b4f 100755 --- a/src/Utilities/Money.php +++ b/src/Utilities/Money.php @@ -7,14 +7,14 @@ class Money { /** - * @param $net - * @param $vat + * @param numeric|numeric-string $net + * @param numeric|numeric-string $vat * * @return float * @deprecated since 5.2 use Money::gross() instead. */ //phpcs:ignore - public static function AsGross($net, $vat): float // @phpstan-ignore-line + public static function AsGross(float|int|string $net, float|int|string $vat): float { return self::gross($net, $vat); } @@ -37,14 +37,14 @@ public static function gross(float|int|string $net, float|int|string $vat): floa } /** - * @param $gross - * @param $vat + * @param numeric|numeric-string $gross + * @param numeric|numeric-string $vat * * @return float * @deprecated since 5.2 use Money::net() instead. */ //phpcs:ignore - public static function AsNet($gross, $vat): float // @phpstan-ignore-line + public static function AsNet(float|int|string $gross, float|int|string $vat): float { return self::net($gross, $vat); } diff --git a/src/Utilities/Validator/Validate.php b/src/Utilities/Validator/Validate.php index ea0f3494..32fc9295 100755 --- a/src/Utilities/Validator/Validate.php +++ b/src/Utilities/Validator/Validate.php @@ -68,9 +68,9 @@ public static function requestPacket(mixed $value): RequestPacket * @param mixed $value * * @return object - * @throws TypeError - * @throws \RuntimeException * @throws InvalidArgumentException + * @throws \RuntimeException + * @throws TypeError */ public static function productObj(mixed $value): object { diff --git a/src/Utilities/Validator/Validator.php b/src/Utilities/Validator/Validator.php index 5226b0d8..ff420b8e 100755 --- a/src/Utilities/Validator/Validator.php +++ b/src/Utilities/Validator/Validator.php @@ -44,7 +44,13 @@ public function string(): string */ public function throwException(): void { - $value = \is_object($this->value) ? \get_class($this->value) : $this->value; + if (\is_object($this->value)) { + $value = \get_class($this->value); + } elseif (\is_scalar($this->value)) { + $value = (string)$this->value; + } else { + $value = \get_debug_type($this->value); + } $message = $this->hasValue() ? $value . ' must be type ' . $this->assertedType : 'Type Error: Value is null'; @@ -158,9 +164,9 @@ public function isObject(): bool * @param int|string $keyName * * @return bool + * @throws ArrayKeyDoesNotExistException * @throws \InvalidArgumentException * @throws \TypeError - * @throws ArrayKeyDoesNotExistException */ public function hasKey(int|string $keyName): bool { diff --git a/src/Utilities/Validator/ValidatorInterface.php b/src/Utilities/Validator/ValidatorInterface.php index a83ed386..b426da47 100755 --- a/src/Utilities/Validator/ValidatorInterface.php +++ b/src/Utilities/Validator/ValidatorInterface.php @@ -84,8 +84,8 @@ public function hasProperty(string $propertyName): bool; * * @return bool * @throws ArrayKeyDoesNotExistException - * @throws \TypeError * @throws \InvalidArgumentException + * @throws \TypeError */ public function hasKey(int|string $keyName): bool; diff --git a/src/dbc/AbstractTable.php b/src/dbc/AbstractTable.php index a8040cee..13e732d9 100755 --- a/src/dbc/AbstractTable.php +++ b/src/dbc/AbstractTable.php @@ -5,7 +5,6 @@ namespace Jtl\Connector\Dbc; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Table; @@ -34,15 +33,15 @@ public function __construct(DbManager $dbManager) } /** - * @param mixed[] $data - * @param string[]|null $types + * @param array $data + * @param array|string, \Doctrine\DBAL\ParameterType|\Doctrine\DBAL\Types\Type|string>|null $types * - * @return int - * @throws DBALException + * @return int|string * @throws DbcRuntimeException + * @throws Exception * @throws \RuntimeException */ - public function insert(array $data, ?array $types = null): int + public function insert(array $data, ?array $types = null): int|string { if (\is_null($types)) { $types = $this->getColumnTypesFor(...\array_keys($data)); @@ -54,9 +53,9 @@ public function insert(array $data, ?array $types = null): int /** * @param string ...$columnNames * - * @return string[] - * @throws DBALException + * @return array * @throws DbcRuntimeException + * @throws Exception */ protected function getColumnTypesFor(string ...$columnNames): array { @@ -67,15 +66,15 @@ protected function getColumnTypesFor(string ...$columnNames): array /** * @return array - * @throws DBALException * @throws DbcRuntimeException + * @throws Exception * @throws SchemaException */ public function getColumnTypes(): array { $columnTypes = []; foreach ($this->getTableSchema()->getColumns() as $column) { - $columnTypes[$column->getName()] = $column->getType()->getName(); + $columnTypes[$column->getName()] = Type::getTypeRegistry()->lookupName($column->getType()); } return $columnTypes; } @@ -83,7 +82,7 @@ public function getColumnTypes(): array /** * @return Table * @throws DbcRuntimeException - * @throws DBALException + * @throws Exception */ public function getTableSchema(): Table { @@ -92,7 +91,9 @@ public function getTableSchema(): Table $this->preCreateTableSchema($this->tableSchema); $this->createTableSchema($this->tableSchema); $this->postCreateTableSchema($this->tableSchema); - if (\count($this->tableSchema->getColumns()) === 0) { + /** @var array $columns */ + $columns = $this->tableSchema->getColumns(); + if (\count($columns) === 0) { throw DbcRuntimeException::tableEmpty($this->tableSchema->getName()); } } @@ -102,8 +103,8 @@ public function getTableSchema(): Table /** * @return Table - * @throws Exception * @throws DbcRuntimeException + * @throws Exception */ protected function createSchemaTable(): Table { @@ -166,16 +167,16 @@ public function getDbManager(): DbManager } /** - * @param mixed[] $data - * @param mixed[] $identifiers - * @param string[]|null $types + * @param array $data + * @param array $identifiers + * @param array|string, \Doctrine\DBAL\ParameterType|\Doctrine\DBAL\Types\Type|string>|null $types * - * @return int - * @throws DBALException + * @return int|string * @throws DbcRuntimeException + * @throws Exception * @throws \RuntimeException */ - public function update(array $data, array $identifiers, ?array $types = null): int + public function update(array $data, array $identifiers, ?array $types = null): int|string { if (\is_null($types)) { $types = @@ -186,15 +187,15 @@ public function update(array $data, array $identifiers, ?array $types = null): i } /** - * @param mixed[] $identifiers - * @param string[]|null $types + * @param array $identifiers + * @param array|string, \Doctrine\DBAL\ParameterType|\Doctrine\DBAL\Types\Type|string>|null $types * - * @return int - * @throws DBALException + * @return int|string * @throws DbcRuntimeException + * @throws Exception * @throws \RuntimeException */ - public function delete(array $identifiers, ?array $types = null): int + public function delete(array $identifiers, ?array $types = null): int|string { if (\is_null($types)) { $types = $this->getColumnTypesFor(...\array_keys($identifiers)); @@ -206,7 +207,7 @@ public function delete(array $identifiers, ?array $types = null): int /** * @return string[] * @throws DbcRuntimeException - * @throws DBALException + * @throws Exception */ public function getColumnNames(): array { @@ -229,11 +230,11 @@ protected function convertToDatabaseValue(string $doctrineType, mixed $phpValue) } /** - * @param array> $rows + * @param array> $rows * - * @return array> - * @throws DBALException + * @return array> * @throws DbcRuntimeException + * @throws Exception */ protected function convertAllToPhpValues(array $rows): array { @@ -246,11 +247,11 @@ protected function convertAllToPhpValues(array $rows): array } /** - * @param array $row + * @param array $row * - * @return array + * @return array * @throws DbcRuntimeException - * @throws DBALException + * @throws Exception */ protected function convertToPhpValues(array $row): array { @@ -276,7 +277,9 @@ protected function convertToPhpValues(array $row): array //Dirty BIGINT to int cast if ($result[$index] !== null && $types[$index] === Types::BIGINT) { - $result[$index] = (int)$result[$index]; + /** @var int|float|string|bool $bigintValue */ + $bigintValue = $result[$index]; + $result[$index] = (int)$bigintValue; } } } @@ -306,7 +309,7 @@ protected function createQueryBuilder(?string $tableAlias = null): QueryBuilder * * @return $this * @throws DbcRuntimeException - * @throws DBALException + * @throws Exception * @throws SchemaException */ protected function restrict(string $column, mixed $value): self diff --git a/src/dbc/Connection.php b/src/dbc/Connection.php index 94b56ada..8f267c9a 100755 --- a/src/dbc/Connection.php +++ b/src/dbc/Connection.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\Exception; use Jtl\Connector\Dbc\Query\QueryBuilder; use Jtl\Connector\Dbc\Schema\TableRestriction; -use RuntimeException; class Connection extends \Doctrine\DBAL\Connection { @@ -57,17 +56,13 @@ public function getTableRestrictions(?string $tableExpression = null): array return $this->tableRestrictions; } - if (!isset($this->tableRestrictions[$tableExpression])) { - $this->tableRestrictions[$tableExpression] = []; - } - - return $this->tableRestrictions[$tableExpression]; + return $this->tableRestrictions[$tableExpression] ?? []; } /** - * @param string $tableExpression - * @param array> $data - * @param string[] $types + * @param string $tableExpression + * @param array> $data + * @param array|string, \Doctrine\DBAL\ParameterType|\Doctrine\DBAL\Types\Type|string> $types * * @return int * @throws \Exception @@ -78,11 +73,11 @@ public function multiInsert(string $tableExpression, array $data, array $types = $this->beginTransaction(); try { foreach ($data as $row) { - $affectedRows += $this->insert($tableExpression, $row, $types); + $affectedRows += (int)$this->insert($tableExpression, $row, $types); } $this->commit(); } catch (\Exception $e) { - $this->rollback(); + $this->rollBack(); throw $e; } @@ -90,83 +85,53 @@ public function multiInsert(string $tableExpression, array $data, array $types = } /** - * @phpstan-param string $tableExpression - * - * @param mixed $tableExpression - * @param mixed[] $data - * @param string[] $types + * @param string $table + * @param array $data + * @param array|string, \Doctrine\DBAL\ParameterType|\Doctrine\DBAL\Types\Type|string> $types * - * @return int + * @return int|string * @throws Exception - * @throws DbcRuntimeException|\RuntimeException - * @noinspection PhpParameterNameChangedDuringInheritanceInspection */ - public function insert(mixed $tableExpression, array $data, array $types = []): int + public function insert(string $table, array $data, array $types = []): int|string { - $return = parent::insert( - $tableExpression, - \array_merge($data, $this->getTableRestrictions($tableExpression)), + return parent::insert( + $table, + \array_merge($data, $this->getTableRestrictions($table)), $types ); - - if (!\is_numeric($return)) { - throw new RuntimeException('insert must return a numeric value.'); - } - - return (int)$return; } /** - * @phpstan-param string $tableExpression + * @param string $table + * @param array $data + * @param array $criteria + * @param array|string, \Doctrine\DBAL\ParameterType|\Doctrine\DBAL\Types\Type|string> $types * - * @param mixed $tableExpression - * @param mixed[] $data - * @param mixed[] $identifiers - * @param string[] $types - * - * @return int + * @return int|string * @throws Exception - * @throws DbcRuntimeException|\RuntimeException - * @noinspection PhpParameterNameChangedDuringInheritanceInspection */ - public function update(mixed $tableExpression, array $data, array $identifiers, array $types = []): int + public function update(string $table, array $data, array $criteria = [], array $types = []): int|string { - $restrictions = $this->getTableRestrictions($tableExpression); + $restrictions = $this->getTableRestrictions($table); $data = \array_merge($data, $restrictions); - $identifiers = \array_merge($identifiers, $restrictions); + $criteria = \array_merge($criteria, $restrictions); - $return = parent::update($tableExpression, $data, $identifiers, $types); - - if (!\is_numeric($return)) { - throw new RuntimeException('update must return a numeric value.'); - } - - return (int)$return; + return parent::update($table, $data, $criteria, $types); } /** - * @phpstan-param string $tableExpression - * - * @param mixed $tableExpression - * @param mixed[] $identifiers - * @param string[] $types + * @param string $table + * @param array $criteria + * @param array|string, \Doctrine\DBAL\ParameterType|\Doctrine\DBAL\Types\Type|string> $types * - * @return int + * @return int|string * @throws Exception - * @throws DbcRuntimeException|\RuntimeException - * @noinspection PhpParameterNameChangedDuringInheritanceInspection */ - public function delete(mixed $tableExpression, array $identifiers, array $types = []): int + public function delete(string $table, array $criteria = [], array $types = []): int|string { - $restrictions = $this->getTableRestrictions($tableExpression); - $identifiers = \array_merge($identifiers, $restrictions); - - $return = parent::delete($tableExpression, $identifiers, $types); - - if (!\is_numeric($return)) { - throw new RuntimeException('delete must return a numeric value.'); - } + $restrictions = $this->getTableRestrictions($table); + $criteria = \array_merge($criteria, $restrictions); - return (int)$return; + return parent::delete($table, $criteria, $types); } } diff --git a/src/dbc/Console/Command/UpdateDatabaseSchemaCommand.php b/src/dbc/Console/Command/UpdateDatabaseSchemaCommand.php index 526ba6fa..6464369e 100644 --- a/src/dbc/Console/Command/UpdateDatabaseSchemaCommand.php +++ b/src/dbc/Console/Command/UpdateDatabaseSchemaCommand.php @@ -4,19 +4,18 @@ namespace Jtl\Connector\Dbc\Console\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Exception\InvalidArgumentException; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +#[AsCommand(name: 'database:update-schema')] class UpdateDatabaseSchemaCommand extends AbstractDbManagerCommand { public const string OPTION_FORCE = 'force'; - /** @var string */ - protected static $defaultName = 'database:update-schema'; // phpcs:ignore - /** * @return void * @throws InvalidArgumentException diff --git a/src/dbc/DbManager.php b/src/dbc/DbManager.php index d7915086..21e30268 100755 --- a/src/dbc/DbManager.php +++ b/src/dbc/DbManager.php @@ -5,12 +5,12 @@ namespace Jtl\Connector\Dbc; use Doctrine\DBAL\Configuration; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaException; +use Doctrine\DBAL\Schema\SchemaManagerFactory; use Doctrine\DBAL\Schema\Table; use RuntimeException; @@ -48,7 +48,7 @@ public function getConnection(): Connection * @param string|null $tablesPrefix * * @return self - * @throws DBALException + * @throws Exception */ public static function createFromParams( array $params, @@ -56,7 +56,7 @@ public static function createFromParams( ?string $tablesPrefix = null ): self { $params['wrapperClass'] = Connection::class; - /** @var Connection $connection */ + /** @var array{wrapperClass: class-string, driver?: 'ibm_db2'|'mysqli'|'oci8'|'pdo_mysql'|'pdo_oci'|'pdo_pgsql'|'pdo_sqlite'|'pdo_sqlsrv'|'pgsql'|'sqlite3'|'sqlsrv', path?: string, url?: string} $params */ $connection = DriverManager::getConnection($params, $config); return new self($connection, $tablesPrefix); @@ -77,18 +77,23 @@ public function registerTable(AbstractTable $table): self /** * @return string[] - * @throws DBALException * @throws DbcRuntimeException + * @throws Exception */ public function getSchema(): array { - return (new Schema($this->getSchemaTables()))->toSql($this->connection->getDatabasePlatform()); + $schema = new Schema($this->getSchemaTables()); + $platform = $this->connection->getDatabasePlatform(); + + return $platform->getAlterSchemaSQL( + (new Comparator($platform))->compareSchemas(new Schema(), $schema) + ); } /** * @return Table[] - * @throws DBALException * @throws DbcRuntimeException + * @throws Exception */ public function getSchemaTables(): array { @@ -107,9 +112,9 @@ public function getTables(): array /** * @return bool - * @throws DBALException * @throws DbcRuntimeException * @throws DbcRuntimeException|\RuntimeException + * @throws Exception */ public function hasSchemaUpdates(): bool { @@ -118,29 +123,75 @@ public function hasSchemaUpdates(): bool /** * @return string[] - * @throws DBALException * @throws DbcRuntimeException + * @throws DbcRuntimeException|RuntimeException * @throws Exception * @throws SchemaException - * @throws DbcRuntimeException|RuntimeException */ public function getSchemaUpdates(): array { - /** @var Configuration $configuration */ - $configuration = $this->connection->getConfiguration(); - /** @var AbstractSchemaManager $schemaManager */ - $schemaManager = $this->connection->getSchemaManager(); + $configuration = $this->connection->getConfiguration(); + $schemaManager = $this->connection->createSchemaManager(); $originalSchemaAssetsFilter = $configuration->getSchemaAssetsFilter(); $configuration->setSchemaAssetsFilter($this->createSchemaAssetsFilterCallback()); - $fromSchema = $schemaManager->createSchema(); - $updateStatements = $fromSchema->getMigrateToSql( - new Schema($this->getSchemaTables()), - $this->connection->getDatabasePlatform() - ); + $fromSchema = $schemaManager->introspectSchema(); + $toSchema = new Schema($this->getSchemaTables()); + $this->normalizeIntrospectedSchema($fromSchema, $toSchema); + $comparator = $schemaManager->createComparator(); + $schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema); + $platform = $this->connection->getDatabasePlatform(); + $updateStatements = $platform->getAlterSchemaSQL($schemaDiff); $configuration->setSchemaAssetsFilter($originalSchemaAssetsFilter); return $updateStatements; } + /** + * Normalizes the introspected schema to account for platform-specific round-trip + * inconsistencies (e.g. SQLite not distinguishing DateTime from DateTimeImmutable, + * or returning float defaults as strings). + * + * @param Schema $introspectedSchema + * @param Schema $targetSchema + * + * @return void + */ + protected function normalizeIntrospectedSchema(Schema $introspectedSchema, Schema $targetSchema): void + { + foreach ($targetSchema->getTables() as $targetTable) { + $tableName = $targetTable->getName(); + if (!$introspectedSchema->hasTable($tableName)) { + continue; + } + + $introspectedTable = $introspectedSchema->getTable($tableName); + + foreach ($targetTable->getColumns() as $targetColumn) { + $columnName = $targetColumn->getName(); + if (!$introspectedTable->hasColumn($columnName)) { + continue; + } + + $introspectedColumn = $introspectedTable->getColumn($columnName); + $targetType = $targetColumn->getType(); + $introspectedType = $introspectedColumn->getType(); + + if ($targetType::class !== $introspectedType::class) { + $introspectedColumn->setType($targetType); + } + + $targetDefault = $targetColumn->getDefault(); + $introspectedDefault = $introspectedColumn->getDefault(); + if ($targetDefault !== $introspectedDefault) { + if (\is_numeric($targetDefault) && \is_numeric($introspectedDefault)) { + if ((float)$targetDefault === (float)$introspectedDefault) { + $introspectedColumn->setDefault($targetDefault); + } + } + } + } + } + } + /** * @return callable */ @@ -163,7 +214,7 @@ public function updateDatabaseSchema(): void { $this->connection->transactional(function ($connection): void { foreach ($this->getSchemaUpdates() as $ddl) { - $connection->executeQuery($ddl); + $connection->executeStatement($ddl); } }); } diff --git a/src/dbc/Query/QueryBuilder.php b/src/dbc/Query/QueryBuilder.php index 9bd4e678..3e41e957 100755 --- a/src/dbc/Query/QueryBuilder.php +++ b/src/dbc/Query/QueryBuilder.php @@ -4,20 +4,25 @@ namespace Jtl\Connector\Dbc\Query; -use Doctrine\DBAL\Query\Expression\CompositeExpression; -use Doctrine\DBAL\Query\QueryException; use Jtl\Connector\Dbc\Connection; class QueryBuilder extends \Doctrine\DBAL\Query\QueryBuilder { + private const string + TYPE_SELECT = 'select', + TYPE_INSERT = 'insert', + TYPE_UPDATE = 'update', + TYPE_DELETE = 'delete'; + /** @var array{empty}|array>|array */ protected array $tableRestrictions = []; - protected ?string $fromTable; - protected ?string $fromAlias; + protected ?string $lockedFromTable; + protected ?string $lockedFromAlias; + protected ?string $currentTable = null; + protected string $queryType = self::TYPE_SELECT; + protected bool $restrictionsApplied = false; /** - * QueryBuilder constructor. - * * @param Connection $connection * @param array{empty}|array|array> $tableRestrictions * @param string|null $fromTable @@ -31,45 +36,86 @@ public function __construct( ) { parent::__construct($connection); $this->tableRestrictions = $tableRestrictions; - $this->fromTable = $fromTable; - $this->fromAlias = $fromAlias; + $this->lockedFromTable = $fromTable; + $this->lockedFromAlias = $fromAlias; + + if ($fromTable !== null) { + parent::from($fromTable, $fromAlias); + } } /** - * @return string - * @throws QueryException + * @param string $table + * @param string|null $alias + * + * @return $this */ - public function getSQL(): string + public function from(string $table, ?string $alias = null): static { - $fromTable = $this->fromTable; - if (!\is_null($fromTable)) { - $this->resetQueryPart('from'); - switch ($this->getType()) { - case self::SELECT: - $this->from($fromTable, $this->fromAlias); - break; - case self::INSERT: - $this->insert($fromTable); - break; - case self::UPDATE: - $this->update($fromTable, $this->fromAlias); - break; - case self::DELETE: - $this->delete($fromTable, $this->fromAlias); - break; - } + if ($this->lockedFromTable !== null) { + return $this; } + $this->currentTable = $table; + + return parent::from($table, $alias); + } + + /** + * @param string $table + * + * @return $this + */ + public function insert(string $table): static + { + $actualTable = $this->lockedFromTable ?? $table; + $this->currentTable = $actualTable; + $this->queryType = self::TYPE_INSERT; + + return parent::insert($actualTable); + } - /** @var array|string> $queryPart */ - $queryPart = $this->getQueryPart('from'); - foreach ($queryPart as $table) { - if (!$table) { - continue; + /** + * @param string $table + * + * @return $this + */ + public function update(string $table): static + { + $actualTable = $this->lockedFromTable ?? $table; + $this->currentTable = $actualTable; + $this->queryType = self::TYPE_UPDATE; + + return parent::update($actualTable); + } + + /** + * @param string $table + * + * @return $this + */ + public function delete(string $table): static + { + $actualTable = $this->lockedFromTable ?? $table; + $this->currentTable = $actualTable; + $this->queryType = self::TYPE_DELETE; + + return parent::delete($actualTable); + } + + /** + * @param string $table + * + * @return void + */ + protected function assignWhereRestrictions(string $table): void + { + if (isset($this->tableRestrictions[$table]) && \is_array($this->tableRestrictions[$table])) { + foreach ($this->tableRestrictions[$table] as $column => $value) { + $id = 'glob_id_' . $column; + $this->setParameter($id, $value); + $this->andWhere($column . ' = :' . $id); } - $this->assignTableRestrictions(\is_array($table) ? $table['table'] : $table); } - - return parent::getSQL(); } /** @@ -77,25 +123,57 @@ public function getSQL(): string * * @return void */ - protected function assignTableRestrictions(string $table): void + protected function assignInsertRestrictions(string $table): void { if (isset($this->tableRestrictions[$table]) && \is_array($this->tableRestrictions[$table])) { foreach ($this->tableRestrictions[$table] as $column => $value) { - $id = 'glob_id_' . $column; - $where = $this->getQueryPart('where'); + $id = 'glob_id_' . $column; $this->setParameter($id, $value); $this->setValue($column, ':' . $id); + } + } + } + + /** + * @param string $table + * + * @return void + */ + protected function assignUpdateRestrictions(string $table): void + { + if (isset($this->tableRestrictions[$table]) && \is_array($this->tableRestrictions[$table])) { + foreach ($this->tableRestrictions[$table] as $column => $value) { + $id = 'glob_id_' . $column; + $this->setParameter($id, $value); $this->set($column, ':' . $id); - $whereCondition = $column . ' = :' . $id; - - if ( - !$where instanceof CompositeExpression - || $where->getType() !== CompositeExpression::TYPE_AND - || !\str_contains((string)$where, $whereCondition) - ) { - $this->andWhere($whereCondition); + $this->andWhere($column . ' = :' . $id); + } + } + } + + /** + * @return string + */ + public function getSQL(): string + { + if (!$this->restrictionsApplied) { + $table = $this->currentTable ?? $this->lockedFromTable; + if ($table !== null) { + switch ($this->queryType) { + case self::TYPE_INSERT: + $this->assignInsertRestrictions($table); + break; + case self::TYPE_UPDATE: + $this->assignUpdateRestrictions($table); + break; + default: + $this->assignWhereRestrictions($table); + break; } } + $this->restrictionsApplied = true; } + + return parent::getSQL(); } } diff --git a/src/dbc/Schema/TableRestriction.php b/src/dbc/Schema/TableRestriction.php index dd12d856..fb27483d 100755 --- a/src/dbc/Schema/TableRestriction.php +++ b/src/dbc/Schema/TableRestriction.php @@ -4,7 +4,7 @@ namespace Jtl\Connector\Dbc\Schema; -use Doctrine\DBAL\Schema\SchemaException; +use Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist; use Doctrine\DBAL\Schema\Table; class TableRestriction @@ -20,12 +20,12 @@ class TableRestriction * @param string $columnName * @param mixed $columnValue * - * @throws SchemaException + * @throws ColumnDoesNotExist */ public function __construct(Table $table, string $columnName, mixed $columnValue) { if (!$table->hasColumn($columnName)) { - throw SchemaException::columnDoesNotExist($columnName, $table->getName()); + throw ColumnDoesNotExist::new($columnName, $table->getName()); } $this->table = $table; @@ -39,7 +39,7 @@ public function __construct(Table $table, string $columnName, mixed $columnValue * @param mixed $columnValue * * @return self - * @throws SchemaException + * @throws ColumnDoesNotExist */ public static function create(Table $table, string $columnName, mixed $columnValue): self { diff --git a/src/dbc/Session/SessionHandler.php b/src/dbc/Session/SessionHandler.php index fc8c7635..1f5c065b 100644 --- a/src/dbc/Session/SessionHandler.php +++ b/src/dbc/Session/SessionHandler.php @@ -5,8 +5,6 @@ namespace Jtl\Connector\Dbc\Session; use DateTimeImmutable; -use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Driver\Exception; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\DBAL\Schema\SchemaException; @@ -59,9 +57,9 @@ public function close(): bool * @param string $sessionId * * @return bool - * @throws DBALException - * @throws InvalidArgumentException * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Exception + * @throws InvalidArgumentException * @throws \RuntimeException * @noinspection PhpParameterNameChangedDuringInheritanceInspection */ @@ -84,10 +82,10 @@ public function destroy(string $sessionId): bool public function gc(int $maxLifetime): bool { $this->createQueryBuilder() - ->delete() - ->andWhere($this->getConnection()->getExpressionBuilder()->lte(self::EXPIRES_AT, ':now')) + ->delete($this->getTableName()) + ->andWhere($this->getConnection()->createExpressionBuilder()->lte(self::EXPIRES_AT, ':now')) ->setParameter('now', new DateTimeImmutable(), Types::DATETIME_IMMUTABLE) - ->execute(); + ->executeStatement(); return true; } @@ -108,16 +106,16 @@ public function open(string $savePath, string $name): bool * @param string $sessionId * * @return string - * @throws Exception|\Doctrine\DBAL\Exception * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Exception * @throws \RuntimeException * @noinspection PhpParameterNameChangedDuringInheritanceInspection */ #[ReturnTypeWillChange] public function read(string $sessionId): string { - $stmt = $this->createReadQuery($sessionId, [self::SESSION_DATA])->execute(); - if (\is_object($stmt) && \is_scalar(($fetchOne = $stmt->fetchOne()))) { + $stmt = $this->createReadQuery($sessionId, [self::SESSION_DATA])->executeQuery(); + if (\is_scalar(($fetchOne = $stmt->fetchOne()))) { return (string)$fetchOne; } return ''; @@ -134,10 +132,10 @@ public function read(string $sessionId): string protected function createReadQuery(string $sessionId, array $columns = [self::SESSION_DATA]): QueryBuilder { return $this->createQueryBuilder() - ->select($columns) - ->where($this->getConnection()->getExpressionBuilder()->eq(self::SESSION_ID, ':sessionId')) + ->select(...$columns) + ->where($this->getConnection()->createExpressionBuilder()->eq(self::SESSION_ID, ':sessionId')) ->setParameter('sessionId', $sessionId) - ->andWhere($this->getConnection()->getExpressionBuilder()->gt(self::EXPIRES_AT, ':now')) + ->andWhere($this->getConnection()->createExpressionBuilder()->gt(self::EXPIRES_AT, ':now')) ->setParameter('now', new DateTimeImmutable(), Types::DATETIME_IMMUTABLE); } @@ -146,8 +144,8 @@ protected function createReadQuery(string $sessionId, array $columns = [self::SE * @param string $sessionData * * @return bool - * @throws DBALException * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Exception * @throws \RuntimeException * @noinspection PhpParameterNameChangedDuringInheritanceInspection */ @@ -182,19 +180,15 @@ protected function calculateExpiryTime(): int * @param string $sessionId * * @return bool - * @throws \Doctrine\DBAL\Exception|Exception * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Exception * @throws \RuntimeException * @noinspection PhpParameterNameChangedDuringInheritanceInspection */ public function validateId(string $sessionId): bool { - $stmt = $this->createReadQuery($sessionId, [self::SESSION_ID])->execute(); - if (\is_object($stmt)) { - return $stmt->fetchOne() === $sessionId; - } - - return false; + $stmt = $this->createReadQuery($sessionId, [self::SESSION_ID])->executeQuery(); + return $stmt->fetchOne() === $sessionId; } /** @@ -202,8 +196,8 @@ public function validateId(string $sessionId): bool * @param string $sessionData * * @return bool - * @throws DBALException * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Exception * @throws \RuntimeException * @noinspection PhpParameterNameChangedDuringInheritanceInspection */ @@ -229,8 +223,8 @@ protected function getName(): string * @param Table $tableSchema * * @return void - * @throws SchemaException * @throws \Doctrine\DBAL\Exception + * @throws SchemaException */ protected function createTableSchema(Table $tableSchema): void { diff --git a/src/dbc/TableCollection.php b/src/dbc/TableCollection.php index 508c2aca..ebeb18c7 100755 --- a/src/dbc/TableCollection.php +++ b/src/dbc/TableCollection.php @@ -59,7 +59,7 @@ public function removeByInstance(AbstractTable $table): bool */ public function has(string $name): bool { - return isset($this->tables[$name]) && $this->tables[$name] instanceof AbstractTable; + return isset($this->tables[$name]); } /** diff --git a/src/dbc/Types/Uuid4Type.php b/src/dbc/Types/Uuid4Type.php index ddff532a..674103a5 100644 --- a/src/dbc/Types/Uuid4Type.php +++ b/src/dbc/Types/Uuid4Type.php @@ -6,9 +6,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Platforms\MySqlPlatform; -use Doctrine\DBAL\Platforms\SqlitePlatform; -use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Types\Exception\InvalidType; use Doctrine\DBAL\Types\Type; class Uuid4Type extends Type @@ -28,6 +26,7 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st $column['length'] = 16; $column['fixed'] = true; + /** @var array{length: int, fixed: bool} $column */ return $platform->getBinaryTypeDeclarationSQL($column); } @@ -51,61 +50,28 @@ public function convertToPHPValue(mixed $value, AbstractPlatform $platform): str * @param AbstractPlatform $platform * * @return string - * @throws ConversionException + * @throws InvalidType */ public function convertToDatabaseValue(mixed $value, AbstractPlatform $platform): string { $converted = \hex2bin(\str_replace('-', '', $value)); if ($converted === false) { - throw ConversionException::conversionFailedInvalidType((string)$value, $this->getName(), ['UUIDv4 string']); + throw InvalidType::new((string)$value, self::NAME, ['UUIDv4 string']); } return $converted; } - /** - * @return string - */ - public function getName(): string - { - return self::NAME; - } - /** * Modifies the SQL expression (identifier, parameter) to convert to a PHP value. * - * @phpstan-param string $sqlExpr - * @phpstan-param AbstractPlatform $platform - * - * @param mixed $sqlExpr - * @param mixed $platform - * - * @return string - */ - public function convertToPHPValueSQL(mixed $sqlExpr, mixed $platform): string - { - if ($platform instanceof MySqlPlatform || $platform instanceof SqlitePlatform) { - return $platform->getLowerExpression(\sprintf('HEX(%s)', $sqlExpr)); - } - - return $sqlExpr; - } - - /** + * @param string $sqlExpr * @param AbstractPlatform $platform * - * @return bool - */ - public function requiresSQLCommentHint(AbstractPlatform $platform): bool - { - return true; - } - - /** - * @return bool + * @return string */ - public function canRequireSQLConversion(): bool + public function convertToPHPValueSQL(string $sqlExpr, AbstractPlatform $platform): string { - return true; + return \sprintf('LOWER(HEX(%s))', $sqlExpr); } } diff --git a/src/mapping-tables/AbstractTable.php b/src/mapping-tables/AbstractTable.php index 2d48f1b1..9e52a959 100755 --- a/src/mapping-tables/AbstractTable.php +++ b/src/mapping-tables/AbstractTable.php @@ -4,12 +4,9 @@ namespace Jtl\Connector\MappingTables; -use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; -use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Table; @@ -38,8 +35,8 @@ abstract class AbstractTable extends AbstractDbcTable implements TableInterface * @param DbManager $dbManager * @param bool $isSingleIdentity * - * @throws MappingTablesException * @throws \Exception + * @throws MappingTablesException */ public function __construct(DbManager $dbManager, bool $isSingleIdentity = true) { @@ -48,6 +45,7 @@ public function __construct(DbManager $dbManager, bool $isSingleIdentity = true) } foreach ($this->getTypes() as $type) { + /** @var mixed $type */ if (!\is_int($type)) { throw MappingTablesException::typeNotInteger(); } @@ -102,10 +100,9 @@ protected function setEndpointColumn(string $columnName, string $columnType, boo * @param string $endpoint * * @return int|null - * @throws DBALException + * @throws Exception * @throws MappingTablesException * @throws \RuntimeException - * @throws \Doctrine\DBAL\Driver\Exception */ public function getHostId(string $endpoint): ?int { @@ -118,12 +115,17 @@ public function getHostId(string $endpoint): ?int foreach ($this->extractEndpoint($endpoint) as $column => $value) { if (\in_array($column, $primaryColumnNames, true)) { $qb->andWhere($column . ' = :' . $column) - ->setParameter($column, $value, $this->endpointColumns[$column]->getColumn()->getType()->getName()); + ->setParameter( + $column, + $value, + Type::getTypeRegistry()->lookupName($this->endpointColumns[$column]->getColumn()->getType()) + ); } } - $hostId = $qb->execute(); - if (($hostId instanceof Result) && \is_numeric(($id = $hostId->fetchOne()))) { + $result = $qb->executeQuery(); + $id = $result->fetchOne(); + if (\is_numeric($id)) { return (int)$id; } @@ -166,8 +168,8 @@ static function (EndpointColumn $endpointColumn) use ($onlyPrimaryColumns) { * @param string $endpointId * * @return mixed[] - * @throws DBALException|MappingTablesException * @throws DbcRuntimeException + * @throws Exception|MappingTablesException * @throws \RuntimeException */ public function extractEndpoint(string $endpointId): array @@ -190,9 +192,9 @@ public function extractEndpoint(string $endpointId): array * @param mixed[] $data * * @return mixed[] - * @throws DBALException - * @throws MappingTablesException * @throws DbcRuntimeException + * @throws Exception + * @throws MappingTablesException * @throws \RuntimeException */ protected function createEndpointData(array $data): array @@ -205,7 +207,6 @@ protected function createEndpointData(array $data): array throw MappingTablesException::wrongEndpointPartsAmount($dataCount, $columnsCount); } - //@phpstan-ignore-next-line return $this->convertToPhpValues(\array_combine($columnNames, $data)); } @@ -243,18 +244,15 @@ public function isResponsible(?int $type): bool * @param int|null $type * * @return string|null + * @throws DbcRuntimeException * @throws Exception * @throws MappingTablesException - * @throws DbcRuntimeException * @throws \RuntimeException */ public function getEndpoint(int $hostId, ?int $type = null): ?string { - $endpointData = $this->createEndpointIdQuery($hostId, $type)->execute(); - if (!($endpointData instanceof Result)) { - throw new \RuntimeException('$endpoint data must be an Result - object.'); - } - $endpointData = $endpointData->fetch(); + $endpointData = $this->createEndpointIdQuery($hostId, $type)->executeQuery() + ->fetchAssociative(); if (\is_array($endpointData)) { return $this->buildEndpoint($endpointData); @@ -268,9 +266,9 @@ public function getEndpoint(int $hostId, ?int $type = null): ?string * @param int|null $type * * @return QueryBuilder + * @throws DbcRuntimeException * @throws Exception * @throws MappingTablesException - * @throws DbcRuntimeException * @throws \RuntimeException * @throws \RuntimeException */ @@ -283,7 +281,7 @@ protected function createEndpointIdQuery(int $hostId, ?int $type = null): QueryB $columnExpressions = $this->getEndpointColumnExpressions(); $qb = $this->createQueryBuilder() - ->select($columnExpressions) + ->select(...$columnExpressions) ->from($this->getTableName()) ->andWhere(\sprintf('%s = :hostId', self::HOST_ID)) ->setParameter('hostId', $hostId); @@ -343,12 +341,13 @@ public function buildEndpoint(array $data): string } /** - * @param mixed[] $data + * @param array $data * * @return string */ protected function implodeEndpoint(array $data): string { + /** @var array $data */ return \implode($this->endpointDelimiter, $data); } @@ -357,19 +356,20 @@ protected function implodeEndpoint(array $data): string * @param int $hostId * * @return int - * @throws DBALException - * @throws MappingTablesException * @throws DbcRuntimeException + * @throws Exception + * @throws MappingTablesException * @throws \RuntimeException * @throws \RuntimeException */ public function save(string $endpoint, int $hostId): int { + /** @var array $data */ $data = $this->extractEndpoint($endpoint); $data[self::HOST_ID] = $hostId; try { - return $this->insert($data); + return (int)$this->insert($data); } catch (UniqueConstraintViolationException $ex) { $primaryColumnNames = $this->getEndpointColumnNames(true); @@ -380,7 +380,7 @@ public function save(string $endpoint, int $hostId): int } } - return $this->update($data, $identifier); + return (int)$this->update($data, $identifier); } } @@ -390,10 +390,10 @@ public function save(string $endpoint, int $hostId): int * @param int|null $type * * @return int - * @throws DBALException + * @throws DbcRuntimeException + * @throws Exception * @throws Exception * @throws MappingTablesException - * @throws DbcRuntimeException * @throws \RuntimeException */ public function remove(?string $endpoint = null, ?int $hostId = null, ?int $type = null): int @@ -417,7 +417,9 @@ public function remove(?string $endpoint = null, ?int $hostId = null, ?int $type ->setParameter( $column, $value, - $primaryColumns[\array_search($column, $primaryColumnNames)]->getType()->getName() + Type::getTypeRegistry()->lookupName( + $primaryColumns[\array_search($column, $primaryColumnNames)]->getType() + ) ); } } @@ -433,34 +435,16 @@ public function remove(?string $endpoint = null, ?int $hostId = null, ?int $type ->setParameter(self::IDENTITY_TYPE, $type, Types::INTEGER); } - return $this->returnInt($qb->execute(), __FUNCTION__); - } - - /** - * @param mixed $value - * @param string $methodName - * - * @return int - * @throws \RuntimeException - */ - private function returnInt(mixed $value, string $methodName): int - { - if (!\is_int($value)) { - throw new \RuntimeException( - \sprintf('%s must return an integer.', $methodName) - ); - } - - return $value; + return (int)$qb->executeStatement(); } /** * @param int|null $type * * @return int + * @throws DbcRuntimeException * @throws Exception * @throws MappingTablesException - * @throws DbcRuntimeException * @throws \RuntimeException */ public function clear(?int $type = null): int @@ -479,20 +463,19 @@ public function clear(?int $type = null): int } } - return $this->returnInt($qb->execute(), __FUNCTION__); + return (int)$qb->executeStatement(); } /** - * @param string[] $where - * @param mixed[] $parameters - * @param string[] $orderBy - * @param int|null $limit - * @param int|null $offset - * @param int|null $type + * @param string[] $where + * @param mixed[] $parameters + * @param array $orderBy + * @param int|null $limit + * @param int|null $offset + * @param int|null $type * * @return int - * @throws DBALException|MappingTablesException|\RuntimeException - * @throws \Doctrine\DBAL\Driver\Exception + * @throws Exception|MappingTablesException|\RuntimeException */ public function count( array $where = [], @@ -502,18 +485,9 @@ public function count( ?int $offset = null, ?int $type = null ): int { - if ( - !($dbPlatform = $this->getDbManager()->getConnection()->getDatabasePlatform()) instanceof AbstractPlatform - ) { - throw new \RuntimeException('$dbPlatform must instance of AbstractPlatform.'); - } - $result = $this->createFindQuery($where, $parameters, $orderBy, $limit, $offset, $type) - ->select($dbPlatform->getCountExpression('*')) - ->execute(); - if ($result instanceof Result === false) { - throw new \RuntimeException('$result must be instance of Result.'); - } + ->select('COUNT(*)') + ->executeQuery(); $result = $result->fetchOne(); return \is_numeric($result) ? (int)$result : 0; @@ -528,9 +502,9 @@ public function count( * @param int|null $type * * @return QueryBuilder - * @throws DBALException - * @throws MappingTablesException * @throws DbcRuntimeException + * @throws Exception + * @throws MappingTablesException * @throws \RuntimeException * @throws \RuntimeException */ @@ -560,19 +534,20 @@ public function createFindQuery( } foreach ($parameters as $param => $value) { - $qb->setParameter($param, $value); + $qb->setParameter((string)$param, $value); } - if (\is_int($limit)) { + if ($limit !== null) { $qb->setMaxResults($limit); } - if (\is_int($offset)) { + if ($offset !== null) { $qb->setFirstResult($offset); } $allColumns = $this->getColumnNames(); foreach ($orderBy as $column => $direction) { + $column = (string)$column; if (!\in_array($column, $allColumns)) { throw MappingTablesException::endpointColumnNotFound($column); } @@ -584,15 +559,15 @@ public function createFindQuery( } /** - * @param string[] $where - * @param mixed[] $parameters - * @param string[] $orderBy - * @param int|null $limit - * @param int|null $offset - * @param int|null $type + * @param string[] $where + * @param mixed[] $parameters + * @param array $orderBy + * @param int|null $limit + * @param int|null $offset + * @param int|null $type * * @return string[] - * @throws DBALException + * @throws Exception * @throws Exception * @throws MappingTablesException * @throws \RuntimeException @@ -606,43 +581,39 @@ public function findEndpoints( ?int $type = null ): array { $stmt = $this->createFindQuery($where, $parameters, $orderBy, $limit, $offset, $type) - ->select($this->getEndpointColumnExpressions()) - ->execute(); - - if ($stmt instanceof Result === false) { - throw new \RuntimeException('$stmt must be instance of Result.'); - } + ->select(...$this->getEndpointColumnExpressions()) + ->executeQuery(); - //@phpstan-ignore-next-line return \array_map(function (array $data): string { return $this->buildEndpoint($data); - }, $stmt->fetchAll()); + }, $stmt->fetchAllAssociative()); } /** * @param string[] $endpoints * * @return array|string[] - * @throws DBALException + * @throws DbcRuntimeException + * @throws Exception * @throws Exception * @throws MappingTablesException - * @throws DbcRuntimeException * @throws \RuntimeException */ public function filterMappedEndpoints(array $endpoints): array { - $platform = $this->getConnection()->getDatabasePlatform(); $primaryColumnExpressions = $this->getEndpointColumnExpressions(true); $primaryColumnNames = $this->getEndpointColumnNames(true); - $concatArray = []; + $concatParts = []; foreach ($primaryColumnExpressions as $i => $columnExpression) { - $concatArray[] = $columnExpression; + $concatParts[] = $columnExpression; if (isset($primaryColumnExpressions[$i + 1])) { - $concatArray[] = $this->getConnection()->quote($this->endpointDelimiter); + $concatParts[] = $this->getConnection()->quote($this->endpointDelimiter); } } + $concatExpression = \implode(' || ', $concatParts); + $preparedEndpoints = []; foreach ($endpoints as $endpoint) { $extracted = \array_filter( @@ -653,31 +624,27 @@ static function ($key) use ($primaryColumnNames) { \ARRAY_FILTER_USE_KEY ); + /** @var array $extracted */ $preparedEndpoints[\implode($this->endpointDelimiter, $extracted)] = $endpoint; } - $concatExpression = $platform->getConcatExpression(...$concatArray); - $qb = $this->createQueryBuilder() - ->select($concatExpression) - ->from($this->getTableName()) - ->where( - $this->getConnection()->getExpressionBuilder()->in( - $concatExpression, - ':preparedEndpoints' - ) - ) - ->setParameter( - 'preparedEndpoints', - \array_keys($preparedEndpoints), - Connection::PARAM_STR_ARRAY - ); - - $fetchedEndpoints = $qb->execute(); - if ($fetchedEndpoints instanceof Result === false) { - throw new \RuntimeException('$fetchedEndpoints must be instance of Result.'); - } - $fetchedEndpoints = $fetchedEndpoints->fetchAll(\PDO::FETCH_COLUMN); - if (\is_array($fetchedEndpoints) && !empty($fetchedEndpoints)) { + $qb = $this->createQueryBuilder() + ->select($concatExpression) + ->from($this->getTableName()) + ->where( + $this->getConnection()->createExpressionBuilder()->in( + $concatExpression, + ':preparedEndpoints' + ) + ) + ->setParameter( + 'preparedEndpoints', + \array_keys($preparedEndpoints), + ArrayParameterType::STRING + ); + + $fetchedEndpoints = $qb->executeQuery()->fetchFirstColumn(); + if (!empty($fetchedEndpoints)) { foreach ($preparedEndpoints as $prepared => $endpoint) { if (\in_array($prepared, $fetchedEndpoints)) { unset($preparedEndpoints[$prepared]); @@ -715,9 +682,9 @@ public function setEndpointDelimiter(string $endpointDelimiter): self * @param string $endpoint * * @return mixed|null - * @throws DBALException - * @throws MappingTablesException * @throws DbcRuntimeException + * @throws Exception + * @throws MappingTablesException * @throws \RuntimeException */ public function extractValueFromEndpoint(string $field, string $endpoint): mixed @@ -760,8 +727,8 @@ public function isSingleIdentity(): bool /** * @return Table - * @throws Exception * @throws DbcRuntimeException + * @throws Exception * @throws \RuntimeException */ protected function createSchemaTable(): Table @@ -773,12 +740,12 @@ protected function createSchemaTable(): Table * @param Table $tableSchema * * @return void + * @throws DbcRuntimeException * @throws Exception * @throws MappingTablesException - * @throws DbcRuntimeException - * @throws SchemaException * @throws \RuntimeException * @throws \RuntimeException + * @throws SchemaException */ protected function createTableSchema(Table $tableSchema): void { @@ -793,9 +760,14 @@ protected function createTableSchema(Table $tableSchema): void $tableSchema->addIndex([self::HOST_ID], $this->createIndexName(self::HOST_INDEX_NAME)); - $tableSchema->setPrimaryKey($primaryColumnNames); + if (\count($primaryColumnNames) === 0) { + throw MappingTablesException::endpointColumnsNotDefined(); + } + + $tableSchema->setPrimaryKey(\array_values($primaryColumnNames)); if (\count($primaryColumnNames) < \count($endpointColumnNames)) { - $tableSchema->addIndex($endpointColumnNames, $this->createIndexName(self::ENDPOINT_INDEX_NAME)); + $indexName = $this->createIndexName(self::ENDPOINT_INDEX_NAME); + $tableSchema->addIndex(\array_values($endpointColumnNames), $indexName); } } diff --git a/src/mapping-tables/TableManager.php b/src/mapping-tables/TableManager.php index 7d589568..5f4b4713 100755 --- a/src/mapping-tables/TableManager.php +++ b/src/mapping-tables/TableManager.php @@ -63,7 +63,7 @@ public function getEndpointId(int $type, int $hostId): ?string */ public function save(int $type, string $endpointId, int $hostId): bool { - return \is_int($this->collection->get($type)->save($endpointId, $hostId)); + return $this->collection->get($type)->save($endpointId, $hostId) > 0; } /** @@ -76,7 +76,7 @@ public function save(int $type, string $endpointId, int $hostId): bool */ public function delete(int $type, ?string $endpointId = null, ?int $hostId = null): bool { - return \is_int($this->collection->get($type)->remove($endpointId, $hostId, $type)); + return $this->collection->get($type)->remove($endpointId, $hostId, $type) >= 0; } /** @@ -131,7 +131,7 @@ public function count(?int $type = null): int public function clear(?int $type = null): bool { if (!\is_null($type)) { - return \is_int($this->collection->get($type)->clear($type)); + return $this->collection->get($type)->clear($type) >= 0; } foreach ($this->collection->toArray() as $table) { diff --git a/src/mapping-tables/TableProxy.php b/src/mapping-tables/TableProxy.php index 17a5a9d5..9c0e7516 100755 --- a/src/mapping-tables/TableProxy.php +++ b/src/mapping-tables/TableProxy.php @@ -4,7 +4,6 @@ namespace Jtl\Connector\MappingTables; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Exception; use Jtl\Connector\Dbc\DbcRuntimeException; use RuntimeException; @@ -30,10 +29,10 @@ public function __construct(int $type, AbstractTable $table) /** * @return int + * @throws DbcRuntimeException * @throws Exception * @throws MappingTablesException * @throws RuntimeException - * @throws DbcRuntimeException */ public function clear(): int { @@ -41,17 +40,16 @@ public function clear(): int } /** - * @param string[] $where - * @param string[] $parameters - * @param string[] $orderBy - * @param int|null $limit - * @param int|null $offset + * @param string[] $where + * @param string[] $parameters + * @param array $orderBy + * @param int|null $limit + * @param int|null $offset * * @return int - * @throws DBALException + * @throws Exception * @throws MappingTablesException * @throws RuntimeException - * @throws \Doctrine\DBAL\Driver\Exception */ public function count( array $where = [], @@ -82,11 +80,11 @@ public function createEndpoint(mixed ...$parts): string * @param int|null $hostId * * @return int - * @throws DBALException + * @throws DbcRuntimeException + * @throws Exception * @throws Exception * @throws MappingTablesException * @throws RuntimeException - * @throws DbcRuntimeException */ public function delete(?string $endpoint = null, ?int $hostId = null): int { @@ -94,14 +92,14 @@ public function delete(?string $endpoint = null, ?int $hostId = null): int } /** - * @param string[] $where - * @param string[] $parameters - * @param string[] $orderBy - * @param int|null $limit - * @param int|null $offset + * @param string[] $where + * @param string[] $parameters + * @param array $orderBy + * @param int|null $limit + * @param int|null $offset * * @return string[] - * @throws DBALException + * @throws Exception * @throws Exception * @throws MappingTablesException * @throws RuntimeException @@ -120,11 +118,11 @@ public function findEndpoints( * @param string[] $endpoints * * @return string[] - * @throws DBALException + * @throws DbcRuntimeException + * @throws Exception * @throws Exception * @throws MappingTablesException * @throws RuntimeException - * @throws DbcRuntimeException */ public function filterMappedEndpoints(array $endpoints): array { @@ -135,10 +133,10 @@ public function filterMappedEndpoints(array $endpoints): array * @param int $hostId * * @return string|null + * @throws DbcRuntimeException * @throws Exception * @throws MappingTablesException * @throws RuntimeException - * @throws DbcRuntimeException */ public function getEndpoint(int $hostId): ?string { @@ -149,9 +147,8 @@ public function getEndpoint(int $hostId): ?string * @param string $endpoint * * @return int|null - * @throws DBALException + * @throws Exception * @throws MappingTablesException - * @throws \Doctrine\DBAL\Driver\Exception * @throws RuntimeException */ public function getHostId(string $endpoint): ?int @@ -197,8 +194,8 @@ public function setType(int $type): self * @param int $hostId * * @return int - * @throws DBALException|MappingTablesException * @throws DbcRuntimeException + * @throws Exception|MappingTablesException * @throws RuntimeException */ public function save(string $endpoint, int $hostId): int diff --git a/src/mapping-tables/Validator.php b/src/mapping-tables/Validator.php index bea8246e..846b9e62 100644 --- a/src/mapping-tables/Validator.php +++ b/src/mapping-tables/Validator.php @@ -4,7 +4,7 @@ namespace Jtl\Connector\MappingTables; -use Doctrine\DBAL\ForwardCompatibility\Result; +use Doctrine\DBAL\Result; use Jtl\Connector\Dbc\DbcRuntimeException; class Validator @@ -13,7 +13,7 @@ class Validator * @param mixed $value * @param string|null $name * - * @return Result + * @return Result * @throws DbcRuntimeException */ public static function returnResult(mixed $value, ?string $name = null): Result diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9d028c54..6d123094 100755 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,11 +2,7 @@ declare(strict_types=1); -use Doctrine\Common\Annotations\AnnotationRegistry; - require_once __DIR__ . DIRECTORY_SEPARATOR . '../vendor/autoload.php'; -AnnotationRegistry::registerLoader('class_exists'); - const TEST_DIR = __DIR__; const TESTROOT = __DIR__; diff --git a/tests/src/Application/ApplicationTest.php b/tests/src/Application/ApplicationTest.php index 4cb9ce90..51870ddb 100755 --- a/tests/src/Application/ApplicationTest.php +++ b/tests/src/Application/ApplicationTest.php @@ -8,7 +8,6 @@ use DI\Definition\Exception\InvalidDefinition; use DI\DependencyException; use DI\NotFoundException; -use Doctrine\Common\Annotations\AnnotationException; use Jawira\CaseConverter\CaseConverterException; use JMS\Serializer\Exception\LogicException; use JMS\Serializer\Exception\NotAcceptableException; @@ -62,27 +61,15 @@ use Noodlehaus\Exception\EmptyDirectoryException; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; -use PHPUnit\Framework\InvalidArgumentException; use PHPUnit\Framework\MockObject\CannotUseOnlyMethodsException; -use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; -use PHPUnit\Framework\MockObject\ClassIsFinalException; -use PHPUnit\Framework\MockObject\ClassIsReadonlyException; -use PHPUnit\Framework\MockObject\DuplicateMethodException; -use PHPUnit\Framework\MockObject\IncompatibleReturnValueException; -use PHPUnit\Framework\MockObject\InvalidMethodNameException; -use PHPUnit\Framework\MockObject\MethodCannotBeConfiguredException; -use PHPUnit\Framework\MockObject\MethodNameAlreadyConfiguredException; -use PHPUnit\Framework\MockObject\MethodNameNotConfiguredException; -use PHPUnit\Framework\MockObject\MethodParametersAlreadyConfiguredException; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; -use PHPUnit\Framework\MockObject\UnknownTypeException; use ReflectionException; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\File\Exception\FileException; use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\HttpFoundation\FileBag; use Symfony\Component\HttpFoundation\Request as HttpRequest; +use PHPUnit\Framework\Attributes\DataProvider; use Throwable; use TypeError; @@ -95,35 +82,19 @@ class ApplicationTest extends TestCase { /** * @return void - * @throws AnnotationException * @throws ApplicationException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ConfigException * @throws DependencyException - * @throws DuplicateMethodException * @throws EmptyDirectoryException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidDefinition - * @throws InvalidMethodNameException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LoggerException * @throws LogicException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws TypeError - * @throws UnknownTypeException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws \LogicException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException + * @throws TypeError * @throws \UnexpectedValueException */ public function testHandleRequestControllerClassNotFoundException(): void @@ -141,32 +112,19 @@ public function testHandleRequestControllerClassNotFoundException(): void * @param CoreConfigInterface|null $config * * @return Application - * @throws AnnotationException * @throws ApplicationException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ConfigException * @throws DependencyException - * @throws DuplicateMethodException * @throws EmptyDirectoryException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidDefinition - * @throws InvalidMethodNameException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LoggerException * @throws LogicException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws TypeError - * @throws UnknownTypeException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws \LogicException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException + * @throws TypeError * @throws \UnexpectedValueException */ protected function createInitializedApplication( @@ -207,19 +165,15 @@ protected function createInitializedApplication( * @throws ApplicationException * @throws ConfigException * @throws DependencyException - * @throws LoggerException - * @throws ReflectionException - * @throws RuntimeException - * @throws TypeError - * @throws InvalidDefinition - * @throws AnnotationException + * @throws EmptyDirectoryException * @throws \InvalidArgumentException + * @throws InvalidDefinition * @throws \JMS\Serializer\Exception\InvalidArgumentException + * @throws LoggerException * @throws LogicException * @throws \LogicException - * @throws EmptyDirectoryException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException + * @throws TypeError * @throws \UnexpectedValueException */ protected function createApplication( @@ -247,19 +201,7 @@ protected function createApplication( * @param bool $tokenValidatorValidateValue * * @return ConnectorInterface&MockObject - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException - * @throws InvalidMethodNameException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException + * @throws \InvalidArgumentException */ public function createConnector( string $controllerNamespace = '', @@ -278,46 +220,28 @@ public function createConnector( } /** - * @dataProvider controllerActionsDataProvider - * * @param string $action * @param mixed $parameter * * @return void - * @throws AnnotationException * @throws ApplicationException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ConfigException * @throws DependencyException - * @throws DuplicateMethodException * @throws EmptyDirectoryException * @throws Exception - * @throws ExpectationFailedException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidDefinition - * @throws InvalidMethodNameException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LoggerException * @throws LogicException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws TypeError - * @throws UnknownTypeException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws \LogicException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws TypeError * @throws \UnexpectedValueException */ + #[DataProvider('controllerActionsDataProvider')] public function testHandleRequestControllerAction(string $action, mixed $parameter): void { $mock = $this->createMock(Product::class); @@ -364,7 +288,7 @@ public function createTransactionalController(bool $commitThrowsException = fals /** * @return array */ - public function controllerActionsDataProvider(): array + public static function controllerActionsDataProvider(): array { $product = new Product(); $product->setCreationDate(new \DateTimeImmutable()); @@ -391,40 +315,21 @@ public function controllerActionsDataProvider(): array /** * @return void - * @throws AnnotationException * @throws ApplicationException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ConfigException * @throws DependencyException - * @throws DuplicateMethodException * @throws EmptyDirectoryException * @throws Exception - * @throws ExpectationFailedException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidDefinition - * @throws InvalidMethodNameException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LoggerException * @throws LogicException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws MethodNameNotConfiguredException - * @throws MethodParametersAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws TypeError - * @throws UnknownTypeException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws \LogicException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws TypeError * @throws \UnexpectedValueException */ public function testHandleRequestTransactionalMethodsCalls(): void @@ -450,38 +355,20 @@ public function testHandleRequestTransactionalMethodsCalls(): void /** * @return void - * @throws AnnotationException * @throws ApplicationException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ConfigException * @throws DependencyException - * @throws DuplicateMethodException * @throws EmptyDirectoryException * @throws Exception - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidDefinition - * @throws InvalidMethodNameException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LoggerException * @throws LogicException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws MethodNameNotConfiguredException - * @throws MethodParametersAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws TypeError - * @throws UnknownTypeException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws \LogicException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException + * @throws TypeError * @throws \UnexpectedValueException */ public function testHandleRequestTransactionalControllerFail(): void @@ -505,37 +392,20 @@ public function testHandleRequestTransactionalControllerFail(): void /** * @return void - * @throws AnnotationException * @throws ApplicationException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ConfigException * @throws DependencyException - * @throws DuplicateMethodException * @throws EmptyDirectoryException - * @throws ExpectationFailedException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidDefinition - * @throws InvalidMethodNameException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LoggerException * @throws LogicException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws TypeError - * @throws UnknownTypeException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws \LogicException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws TypeError * @throws \UnexpectedValueException */ public function testHandleRequestControllerClassNeedToBeInitialized(): void @@ -552,40 +422,23 @@ public function testHandleRequestControllerClassNeedToBeInitialized(): void /** * @return void - * @throws AnnotationException * @throws ApplicationException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ConfigException * @throws DatabaseException * @throws DependencyException - * @throws DuplicateMethodException * @throws EmptyDirectoryException - * @throws ExpectationFailedException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidDefinition - * @throws InvalidMethodNameException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LoggerException * @throws LogicException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException + * @throws \LogicException * @throws NotFoundException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws \Psr\Log\InvalidArgumentException * @throws SessionException * @throws TypeError - * @throws UnknownTypeException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException - * @throws \LogicException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException - * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException * @throws \UnexpectedValueException */ public function testPrepareContainer(): void @@ -609,19 +462,8 @@ public function testPrepareContainer(): void /** * @return void * @throws ConfigException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException - * @throws UnknownTypeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testPrepareConfigSetDefaultParameters(): void { @@ -645,20 +487,9 @@ public function testPrepareConfigSetDefaultParameters(): void /** * @return void - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ConfigException - * @throws DuplicateMethodException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testPrepareConfigurationSetDefaultValuesInConfig(): void { @@ -683,19 +514,8 @@ public function testPrepareConfigurationSetDefaultValuesInConfig(): void /** * @return void - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testLoadPlugins(): void { @@ -716,40 +536,22 @@ public function testLoadPlugins(): void /** * @return void * @throws ApplicationException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException + * @throws CannotUseOnlyMethodsException + * @throws CaseConverterException * @throws CompressionException * @throws ConfigException * @throws DefinitionException * @throws DependencyException - * @throws DuplicateMethodException * @throws Exception - * @throws ExpectationFailedException * @throws FileNotFoundException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException - * @throws InvalidMethodNameException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws JsonException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException * @throws NotFoundException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws RpcException - * @throws RuntimeException * @throws SessionException * @throws Throwable - * @throws UnknownTypeException - * @throws \JMS\Serializer\Exception\InvalidArgumentException - * @throws CaseConverterException - * @throws CannotUseOnlyMethodsException - * @throws MethodNameNotConfiguredException - * @throws MethodParametersAlreadyConfiguredException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException */ public function testRun(): void { @@ -842,22 +644,16 @@ public function testRun(): void * @throws DefinitionException * @throws DependencyException * @throws FileNotFoundException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws JsonException * @throws LoggerException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException * @throws NotFoundException - * @throws ReflectionException + * @throws \Psr\Log\InvalidArgumentException * @throws RpcException - * @throws RuntimeException * @throws SessionException * @throws Throwable * @throws TypeError - * @throws \JMS\Serializer\Exception\InvalidArgumentException - * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException */ public function testRunInvalidRpcMethod(): void { @@ -889,22 +685,16 @@ public function testRunInvalidRpcMethod(): void * @throws DefinitionException * @throws DependencyException * @throws FileNotFoundException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws JsonException * @throws LoggerException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException * @throws NotFoundException - * @throws ReflectionException + * @throws \Psr\Log\InvalidArgumentException * @throws RpcException - * @throws RuntimeException * @throws SessionException * @throws Throwable * @throws TypeError - * @throws \JMS\Serializer\Exception\InvalidArgumentException - * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException */ public function testRunUnknownController(): void { @@ -939,27 +729,21 @@ public function testRunUnknownController(): void /** * @return void * @throws ApplicationException + * @throws CompressionException * @throws ConfigException * @throws DefinitionException * @throws DependencyException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException + * @throws FileNotFoundException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException + * @throws JsonException * @throws LoggerException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException * @throws NotFoundException - * @throws ReflectionException + * @throws \Psr\Log\InvalidArgumentException * @throws RpcException - * @throws RuntimeException * @throws SessionException - * @throws TypeError - * @throws \JMS\Serializer\Exception\InvalidArgumentException - * @throws JsonException - * @throws CompressionException - * @throws FileNotFoundException - * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException * @throws Throwable + * @throws TypeError */ public function testRunUnknownAction(): void { @@ -987,41 +771,27 @@ public function testRunUnknownAction(): void /** * @return void - * @throws AnnotationException * @throws ApplicationException * @throws CaseConverterException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ConfigException * @throws DefinitionException * @throws DependencyException - * @throws DuplicateMethodException * @throws EmptyDirectoryException - * @throws ExpectationFailedException * @throws FileException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidDefinition - * @throws InvalidMethodNameException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LoggerException * @throws LogicException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws TypeError - * @throws UnknownTypeException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException - * @throws NotAcceptableException - * @throws UnsupportedFormatException * @throws \LogicException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException + * @throws NotAcceptableException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException * @throws \Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException + * @throws TypeError * @throws \UnexpectedValueException + * @throws UnsupportedFormatException */ public function testHandleImagePushWithFilesSentByWawi(): void { @@ -1041,10 +811,7 @@ public function testHandleImagePushWithFilesSentByWawi(): void ); $filebag = new FileBag(['file' => $file]); - $request = $this->getMockBuilder(HttpRequest::class) - ->disableOriginalConstructor() - ->getMock(); - + $request = new HttpRequest(); $request->files = $filebag; $app = $this->createApplication() @@ -1065,27 +832,22 @@ public function testHandleImagePushWithFilesSentByWawi(): void /** * @return void - * @throws AnnotationException * @throws ApplicationException * @throws ConfigException * @throws DependencyException * @throws EmptyDirectoryException - * @throws ExpectationFailedException + * @throws \InvalidArgumentException * @throws InvalidDefinition + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LoggerException * @throws LogicException - * @throws NotAcceptableException - * @throws ReflectionException - * @throws RuntimeException - * @throws TypeError - * @throws UnsupportedFormatException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws \LogicException + * @throws NotAcceptableException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws TypeError * @throws \UnexpectedValueException + * @throws UnsupportedFormatException */ public function testHandleImagePushUploadedFileNotFound(): void { @@ -1103,39 +865,25 @@ public function testHandleImagePushUploadedFileNotFound(): void /** * @return void - * @throws AnnotationException * @throws ApplicationException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws ConfigException * @throws DependencyException - * @throws DuplicateMethodException * @throws EmptyDirectoryException - * @throws ExpectationFailedException * @throws FileException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException * @throws InvalidDefinition - * @throws InvalidMethodNameException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LoggerException * @throws LogicException - * @throws NotAcceptableException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws TypeError - * @throws UnknownTypeException - * @throws UnsupportedFormatException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws \LogicException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException + * @throws NotAcceptableException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException * @throws \Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException + * @throws TypeError * @throws \UnexpectedValueException + * @throws UnsupportedFormatException */ public function testHandleImagePushFileExtractionFailed(): void { @@ -1156,12 +904,9 @@ public function testHandleImagePushFileExtractionFailed(): void true ); $filebag = new FileBag(['file' => $file]); - $request = $this->getMockBuilder(HttpRequest::class) - ->disableOriginalConstructor() - ->getMock(); - - $request->files = $filebag; - $app = $this->createApplication()->setHttpRequest($request); + $request = new HttpRequest(); + $request->files = $filebag; + $app = $this->createApplication()->setHttpRequest($request); $this->invokeMethodFromObject($app, 'handleImagePush', ...$images); } } diff --git a/tests/src/Application/RequestTest.php b/tests/src/Application/RequestTest.php index 0b4049ae..5b14e772 100755 --- a/tests/src/Application/RequestTest.php +++ b/tests/src/Application/RequestTest.php @@ -8,7 +8,6 @@ use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class RequestTest @@ -20,8 +19,8 @@ class RequestTest extends TestCase /** * @return void * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCreateFromStatic(): void { diff --git a/tests/src/Application/ResponseTest.php b/tests/src/Application/ResponseTest.php index 81bc324b..592a84e7 100755 --- a/tests/src/Application/ResponseTest.php +++ b/tests/src/Application/ResponseTest.php @@ -8,8 +8,8 @@ use Jtl\Connector\Core\Model\AbstractModel; use Jtl\Connector\Core\Model\Identity; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class ResponseTest @@ -21,7 +21,7 @@ class ResponseTest extends TestCase /** * @return array */ - public function responseDataProvider(): array + public static function responseDataProvider(): array { return [ [new Identity('1')], @@ -33,14 +33,13 @@ public function responseDataProvider(): array } /** - * @dataProvider responseDataProvider - * * @param AbstractModel|int|string|float|int[] $result * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('responseDataProvider')] public function testCreateFromStatic(AbstractModel|int|string|float|array $result): void { $response = Response::create($result); @@ -50,9 +49,9 @@ public function testCreateFromStatic(AbstractModel|int|string|float|array $resul /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSetResult(): void { diff --git a/tests/src/Authentication/TokenValidationTest.php b/tests/src/Authentication/TokenValidationTest.php index c8559e73..9a4dd190 100755 --- a/tests/src/Authentication/TokenValidationTest.php +++ b/tests/src/Authentication/TokenValidationTest.php @@ -6,9 +6,9 @@ use Jtl\Connector\Core\Authentication\TokenValidator; use Jtl\Connector\Core\Exception\TokenValidatorException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class TokenValidationTest @@ -18,17 +18,16 @@ class TokenValidationTest extends TestCase { /** - * @dataProvider tokenDataProvider - * * @param string $connectorToken * @param string $token * @param bool $result * * @return void + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws TokenValidatorException - * @throws ExpectationFailedException - * @throws InvalidArgumentException */ + #[DataProvider('tokenDataProvider')] public function testValidateToken(string $connectorToken, string $token, bool $result): void { $validator = new TokenValidator($connectorToken); @@ -48,7 +47,7 @@ public function testInstantiateWithEmptyToken(): void /** * @return array */ - public function tokenDataProvider(): array + public static function tokenDataProvider(): array { return [ ['foo', 'foo', true], diff --git a/tests/src/Config/ConfigParameterTest.php b/tests/src/Config/ConfigParameterTest.php index e3dd809a..85ed5856 100755 --- a/tests/src/Config/ConfigParameterTest.php +++ b/tests/src/Config/ConfigParameterTest.php @@ -7,25 +7,24 @@ use Exception; use Jtl\Connector\Core\Config\ConfigParameter; use Jtl\Connector\Core\Exception\ConfigException; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use RuntimeException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class ConfigParameterTest extends TestCase { /** - * @dataProvider dataProvider - * * @param string $type * @param mixed $validValue * @param array $invalidValues * * @return void * @throws ConfigException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('dataProvider')] public function testIsValidValueString(string $type, mixed $validValue, array $invalidValues): void { $option = new ConfigParameter('foo', $type); @@ -36,16 +35,15 @@ public function testIsValidValueString(string $type, mixed $validValue, array $i } /** - * @dataProvider dataProvider - * * @param string $type * @param mixed $validValue * * @return void * @throws ConfigException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('dataProvider')] public function testSetDefaultValue(string $type, mixed $validValue): void { $option = new ConfigParameter('foo', $type); @@ -54,17 +52,15 @@ public function testSetDefaultValue(string $type, mixed $validValue): void } /** - * @dataProvider dataProvider - * * @param string $type * @param mixed $validValue * @param array $invalidValues * * @return void * @throws ConfigException - * @throws RuntimeException * @throws Exception */ + #[DataProvider('dataProvider')] public function testSetWrongDefaultValue(string $type, mixed $validValue, array $invalidValues): void { $this->expectException(ConfigException::class); @@ -81,7 +77,6 @@ public function testSetWrongDefaultValue(string $type, mixed $validValue, array /** * @return void - * @throws \ReflectionException */ public function testSetUnknownType(): void { @@ -96,7 +91,6 @@ public function testSetUnknownType(): void /** * @return void - * @throws \ReflectionException */ public function testSetEmptyKey(): void { @@ -110,16 +104,15 @@ public function testSetEmptyKey(): void } /** - * @dataProvider dataProvider - * * @param string $type * @param mixed $validValue * * @return void * @throws ConfigException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('dataProvider')] public function testHasDefaultValue(string $type, mixed $validValue): void { $option = new ConfigParameter('foo', $type); @@ -131,7 +124,7 @@ public function testHasDefaultValue(string $type, mixed $validValue): void /** * @return array}> */ - public function dataProvider(): array + public static function dataProvider(): array { return [ [ConfigParameter::TYPE_STRING, 'foo', [null, 5, false, true, 0.1]], diff --git a/tests/src/Config/ConfigSchemaTest.php b/tests/src/Config/ConfigSchemaTest.php index 0729303f..8bdbe38d 100755 --- a/tests/src/Config/ConfigSchemaTest.php +++ b/tests/src/Config/ConfigSchemaTest.php @@ -12,7 +12,6 @@ use Noodlehaus\Exception\EmptyDirectoryException; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class ConfigSchemaTest extends TestCase { @@ -20,8 +19,8 @@ class ConfigSchemaTest extends TestCase * @return void * @throws ConfigException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetOption(): void { @@ -43,8 +42,8 @@ public function testGetNotExistingParameter(): void /** * @return void * @throws ConfigException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testIsParameter(): void { @@ -55,8 +54,8 @@ public function testIsParameter(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetParameters(): void { @@ -74,8 +73,8 @@ public function testGetParameters(): void * @return void * @throws ConfigException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSetparameter(): void { @@ -99,8 +98,8 @@ public function testSetparameter(): void * @return void * @throws ConfigException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSetParameters(): void { @@ -121,8 +120,8 @@ public function testSetParameters(): void /** * @return void * @throws ConfigException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetDefaultValues(): void { @@ -147,9 +146,9 @@ public function testGetDefaultValues(): void * @return void * @throws ConfigException * @throws EmptyDirectoryException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws JsonException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testValidate(): void { @@ -169,10 +168,10 @@ public function testValidate(): void /** * @return void * @throws ConfigException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws JsonException * @throws EmptyDirectoryException + * @throws \InvalidArgumentException + * @throws JsonException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testValidateHasInvalidValueAndMissingRequiredProperty(): void { diff --git a/tests/src/Config/FileConfigTest.php b/tests/src/Config/FileConfigTest.php index 7f66aaf6..193e54e7 100755 --- a/tests/src/Config/FileConfigTest.php +++ b/tests/src/Config/FileConfigTest.php @@ -11,7 +11,6 @@ use Noodlehaus\Exception\EmptyDirectoryException; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class FileConfig @@ -24,8 +23,8 @@ class FileConfigTest extends TestCase * @return void * @throws ConfigException * @throws EmptyDirectoryException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testConfigSetParameter(): void { @@ -57,11 +56,11 @@ public function testConfigSetParameterCannotBeEmpty(): void /** * @return void * @throws ConfigException + * @throws EmptyDirectoryException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws JsonException - * @throws EmptyDirectoryException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSave(): void { diff --git a/tests/src/Controller/ConnectorTest.php b/tests/src/Controller/ConnectorTest.php index 4bba0fb0..93547700 100755 --- a/tests/src/Controller/ConnectorTest.php +++ b/tests/src/Controller/ConnectorTest.php @@ -23,45 +23,18 @@ use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\CannotUseOnlyMethodsException; -use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; -use PHPUnit\Framework\MockObject\ClassIsFinalException; -use PHPUnit\Framework\MockObject\ClassIsReadonlyException; -use PHPUnit\Framework\MockObject\DuplicateMethodException; -use PHPUnit\Framework\MockObject\IncompatibleReturnValueException; -use PHPUnit\Framework\MockObject\InvalidMethodNameException; -use PHPUnit\Framework\MockObject\MethodCannotBeConfiguredException; -use PHPUnit\Framework\MockObject\MethodNameAlreadyConfiguredException; -use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; -use PHPUnit\Framework\MockObject\ReflectionException; -use PHPUnit\Framework\MockObject\RuntimeException; -use PHPUnit\Framework\MockObject\UnknownTypeException; use SessionHandlerInterface; class ConnectorTest extends TestCase { /** * @return void + * @throws CannotUseOnlyMethodsException + * @throws Exception * @throws \InvalidArgumentException * @throws \JsonException * @throws JsonException - * @throws Exception - * @throws ExpectationFailedException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws CannotUseOnlyMethodsException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws IncompatibleReturnValueException - * @throws InvalidMethodNameException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testFeatures(): void { @@ -83,20 +56,9 @@ public function testFeatures(): void /** * @return void * @throws CaseConverterException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws DefinitionException - * @throws DuplicateMethodException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testAckEmpty(): void { @@ -112,16 +74,6 @@ public function testAckEmpty(): void * @param string $featuresPath * * @return ConnectorController - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\InvalidArgumentException */ protected function createConnectorController( ?IdentityLinker $linker = null, @@ -158,23 +110,9 @@ protected function createConnectorController( /** * @return void * @throws CaseConverterException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws DefinitionException - * @throws DuplicateMethodException - * @throws ExpectationFailedException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException - * @throws InvalidMethodNameException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testAckInvalidModelName(): void { @@ -196,7 +134,6 @@ public function testAckInvalidModelName(): void * @return void * @throws AuthenticationException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException */ public function testAuthMissingToken(): void { @@ -212,20 +149,7 @@ public function testAuthMissingToken(): void /** * @return void * @throws AuthenticationException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws InvalidMethodNameException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\InvalidArgumentException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException */ public function testAuthTokenIsInvalid(): void { @@ -248,24 +172,9 @@ public function testAuthTokenIsInvalid(): void /** * @return void * @throws AuthenticationException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException * @throws Exception - * @throws ExpectationFailedException - * @throws IncompatibleReturnValueException - * @throws InvalidMethodNameException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException */ public function testAuthCorrect(): void { @@ -289,21 +198,7 @@ public function testAuthCorrect(): void /** * @return void - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws ExpectationFailedException - * @throws IncompatibleReturnValueException - * @throws InvalidMethodNameException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testIdentify(): void { @@ -327,23 +222,9 @@ public function testIdentify(): void /** * @return void - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws DefinitionException - * @throws DuplicateMethodException - * @throws ExpectationFailedException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException - * @throws InvalidMethodNameException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testClearSuccess(): void { diff --git a/tests/src/Definition/ActionTest.php b/tests/src/Definition/ActionTest.php index 2eef5a1a..4734afa2 100755 --- a/tests/src/Definition/ActionTest.php +++ b/tests/src/Definition/ActionTest.php @@ -5,9 +5,9 @@ namespace Jtl\Connector\Core\Test\Definition; use Jtl\Connector\Core\Definition\Action; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class ActionTest @@ -18,8 +18,8 @@ class ActionTest extends TestCase { /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetActions(): void { @@ -44,15 +44,14 @@ public function testGetActions(): void } /** - * @dataProvider actionDataProvider - * * @param string $actionName * @param bool $expectedResult * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('actionDataProvider')] public function testIsAction(string $actionName, bool $expectedResult): void { $this->assertSame($expectedResult, Action::isAction($actionName)); @@ -61,7 +60,7 @@ public function testIsAction(string $actionName, bool $expectedResult): void /** * @return array */ - public function actionDataProvider(): array + public static function actionDataProvider(): array { return [ [Action::PULL, true], @@ -76,15 +75,14 @@ public function actionDataProvider(): array } /** - * @dataProvider coreActionDataProvider - * * @param string $actionName * @param bool $expectedResult * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('coreActionDataProvider')] public function testIsCoreAction(string $actionName, bool $expectedResult): void { $this->assertSame($expectedResult, Action::isCoreAction($actionName)); @@ -94,7 +92,7 @@ public function testIsCoreAction(string $actionName, bool $expectedResult): void * @return array * @throws \Exception */ - public function coreActionDataProvider(): array + public static function coreActionDataProvider(): array { return [ [Action::AUTH, true], diff --git a/tests/src/Definition/ControllerTest.php b/tests/src/Definition/ControllerTest.php index 36b43ca5..6ee1a967 100755 --- a/tests/src/Definition/ControllerTest.php +++ b/tests/src/Definition/ControllerTest.php @@ -6,21 +6,20 @@ use Jtl\Connector\Core\Definition\Controller; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class ControllerTest extends TestCase { /** - * @dataProvider isTypeDataProvider - * * @param string $controllerName * @param bool $shouldBeController * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('isTypeDataProvider')] public function testIsType(string $controllerName, bool $shouldBeController): void { $isType = Controller::isController($controllerName); @@ -29,12 +28,11 @@ public function testIsType(string $controllerName, bool $shouldBeController): vo /** * @return array - * @throws \ReflectionException */ - public function isTypeDataProvider(): array + public static function isTypeDataProvider(): array { /** @var array $testCases */ - $testCases = $this->getCorrectConstantsTestCases(Controller::class); + $testCases = self::getCorrectConstantsTestCases(Controller::class); $testCases[] = [ 'false', false, diff --git a/tests/src/Definition/EventTest.php b/tests/src/Definition/EventTest.php index 1e5adf5f..02d0dd47 100755 --- a/tests/src/Definition/EventTest.php +++ b/tests/src/Definition/EventTest.php @@ -10,8 +10,8 @@ use Jtl\Connector\Core\Definition\Event; use Jtl\Connector\Core\Exception\DefinitionException; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class EventTest @@ -22,8 +22,8 @@ class EventTest extends TestCase { /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testIsMoment(): void { @@ -50,8 +50,8 @@ public function testCreateRpcEventNameInvalidMoment(): void /** * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCreateRpcEventNameWithCorrectMoment(): void { @@ -61,10 +61,10 @@ public function testCreateRpcEventNameWithCorrectMoment(): void /** * @return void - * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws CaseConverterException + * @throws DefinitionException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCreateHandleEventName(): void { @@ -77,8 +77,8 @@ public function testCreateHandleEventName(): void * @return void * @throws CaseConverterException * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCreateCoreEventName(): void { @@ -88,8 +88,6 @@ public function testCreateCoreEventName(): void } /** - * @dataProvider createEventNameInvalidParamsDataProvider - * * @param string $controller * @param string $action * @param string $moment @@ -99,6 +97,7 @@ public function testCreateCoreEventName(): void * @throws CaseConverterException * @throws DefinitionException */ + #[DataProvider('createEventNameInvalidParamsDataProvider')] public function testCreateEventNameInvalidParams( string $controller, string $action, @@ -113,7 +112,7 @@ public function testCreateEventNameInvalidParams( /** * @return array */ - public function createEventNameInvalidParamsDataProvider(): array + public static function createEventNameInvalidParamsDataProvider(): array { return [ ['foo', '', '', DefinitionException::unknownController('foo')], @@ -126,8 +125,8 @@ public function createEventNameInvalidParamsDataProvider(): array * @return void * @throws CaseConverterException * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function createEventNameCorrectParams(): void { diff --git a/tests/src/Definition/IdentityTypeTest.php b/tests/src/Definition/IdentityTypeTest.php index 8972e15c..b65bf0f1 100755 --- a/tests/src/Definition/IdentityTypeTest.php +++ b/tests/src/Definition/IdentityTypeTest.php @@ -6,8 +6,8 @@ use Jtl\Connector\Core\Definition\IdentityType; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class IdentityTypeTest @@ -17,15 +17,14 @@ class IdentityTypeTest extends TestCase { /** - * @dataProvider isTypeDataProvider - * * @param int $type * @param bool $shouldBeIdentityType * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('isTypeDataProvider')] public function testIsType(int $type, bool $shouldBeIdentityType): void { $isType = IdentityType::isType($type); @@ -34,12 +33,11 @@ public function testIsType(int $type, bool $shouldBeIdentityType): void /** * @return array - * @throws \ReflectionException */ - public function isTypeDataProvider(): array + public static function isTypeDataProvider(): array { /** @var array $testCases */ - $testCases = $this->getCorrectConstantsTestCases(IdentityType::class); + $testCases = self::getCorrectConstantsTestCases(IdentityType::class); $testCases[] = [0, false]; $testCases[] = [-100, false]; $testCases[] = [68, true]; diff --git a/tests/src/Definition/ModelTest.php b/tests/src/Definition/ModelTest.php index c027e3cd..d715cd59 100755 --- a/tests/src/Definition/ModelTest.php +++ b/tests/src/Definition/ModelTest.php @@ -8,9 +8,9 @@ use Jtl\Connector\Core\Definition\Model; use Jtl\Connector\Core\Exception\DefinitionException; use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class ModelTest @@ -22,8 +22,8 @@ class ModelTest extends TestCase /** * @return void * @throws AssertionFailedError - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testPropertyMappingsMatchModelIdentities(): void { @@ -38,6 +38,7 @@ public function testPropertyMappingsMatchModelIdentities(): void $mappings = $propertyMappings->getValue($definition); $this->assertIsArray($mappings); + /** @var array> $mappings */ foreach ($mappings as $modelName => $identityMappings) { if (\in_array($modelName, $exceptions, true)) { continue; @@ -56,8 +57,8 @@ public function testPropertyMappingsMatchModelIdentities(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testMappingsMatchIdentityType(): void { @@ -68,24 +69,24 @@ public function testMappingsMatchIdentityType(): void $mappings = $propertyMappings->getValue($definition); $this->assertIsArray($mappings); + /** @var array $mappings */ foreach ($mappings as $mapping) { $this->assertTrue(IdentityType::isType($mapping)); } } /** - * @dataProvider getModelByTypeProvider - * * @param int $identityType * @param \Exception|string $expectedResult * @param bool $shouldThrowException * * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('getModelByTypeProvider')] public function testGetModelByType( int $identityType, \Exception|string $expectedResult, @@ -110,7 +111,7 @@ public function testGetModelByType( /** * @return array */ - public function getModelByTypeProvider(): array + public static function getModelByTypeProvider(): array { return [ [IdentityType::CATEGORY, Model::CATEGORY], @@ -134,16 +135,15 @@ public function testGetIdentityTypeModelIsInvalid(): void } /** - * @dataProvider isIdentityPropertyProvider - * * @param string $modelName * @param string $propertyName * @param bool $expectedResult * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('isIdentityPropertyProvider')] public function testIsIdentityPropertyInvalidPropertyName( string $modelName, string $propertyName, @@ -156,7 +156,7 @@ public function testIsIdentityPropertyInvalidPropertyName( /** * @return array */ - public function isIdentityPropertyProvider(): array + public static function isIdentityPropertyProvider(): array { return [ [Model::SHIPMENT, 'id', false], @@ -170,31 +170,29 @@ public function isIdentityPropertyProvider(): array } /** - * @dataProvider modelNameProvider - * * @param string $modelName * @param bool $expectedResult * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('modelNameProvider')] public function testIsModel(string $modelName, bool $expectedResult): void { $this->assertEquals($expectedResult, Model::isModel($modelName)); } /** - * @dataProvider modelNameProvider - * * @param string $modelName * @param bool $isModelName * * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('modelNameProvider')] public function testGetRelationType(string $modelName, bool $isModelName): void { if (!$isModelName) { @@ -207,7 +205,7 @@ public function testGetRelationType(string $modelName, bool $isModelName): void /** * @return array */ - public function modelNameProvider(): array + public static function modelNameProvider(): array { return [ [Model::PRODUCT, true], diff --git a/tests/src/Definition/PaymentTypeTest.php b/tests/src/Definition/PaymentTypeTest.php index 1eb6a7b7..052b5f74 100755 --- a/tests/src/Definition/PaymentTypeTest.php +++ b/tests/src/Definition/PaymentTypeTest.php @@ -6,8 +6,8 @@ use Jtl\Connector\Core\Definition\PaymentType; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class PaymentTypeTest @@ -17,15 +17,14 @@ class PaymentTypeTest extends TestCase { /** - * @dataProvider isTypeDataProvider - * * @param string $type * @param bool $shouldBePaymentType * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('isTypeDataProvider')] public function testIsType(string $type, bool $shouldBePaymentType): void { $isType = PaymentType::isType($type); @@ -34,12 +33,11 @@ public function testIsType(string $type, bool $shouldBePaymentType): void /** * @return array - * @throws \ReflectionException */ - public function isTypeDataProvider(): array + public static function isTypeDataProvider(): array { /** @var array $testCases */ - $testCases = $this->getCorrectConstantsTestCases(PaymentType::class); + $testCases = self::getCorrectConstantsTestCases(PaymentType::class); $testCases[] = ['false', false]; $testCases[] = ['', false]; $testCases[] = ['pm worldpay', false]; diff --git a/tests/src/Definition/RelationTypeTest.php b/tests/src/Definition/RelationTypeTest.php index 748c4787..e68056ec 100755 --- a/tests/src/Definition/RelationTypeTest.php +++ b/tests/src/Definition/RelationTypeTest.php @@ -8,8 +8,8 @@ use Jtl\Connector\Core\Definition\RelationType; use Jtl\Connector\Core\Exception\DefinitionException; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class RelationTypeTest @@ -19,16 +19,15 @@ class RelationTypeTest extends TestCase { /** - * @dataProvider relatedImageIdentityTypeProvider - * * @param string $relationType * @param int|null $relatedImageIdentityType * * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('relatedImageIdentityTypeProvider')] public function testGetRelatedImageIdentityType(string $relationType, ?int $relatedImageIdentityType): void { if (\is_null($relatedImageIdentityType)) { @@ -41,32 +40,30 @@ public function testGetRelatedImageIdentityType(string $relationType, ?int $rela /** - * @dataProvider relatedImageIdentityProvider - * * @param string $relationType * @param bool $hasRelatedImageIdentityType * * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('relatedImageIdentityProvider')] public function testHasRelatedImageIdentityType(string $relationType, bool $hasRelatedImageIdentityType): void { $this->assertEquals(RelationType::hasRelatedImageIdentityType($relationType), $hasRelatedImageIdentityType); } /** - * @dataProvider relationTypeProvider - * * @param string $relationType * @param bool $isRelationType * * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('relationTypeProvider')] public function testGetRelatedImageModelName(string $relationType, bool $isRelationType): void { if (!$isRelationType) { @@ -80,16 +77,15 @@ public function testGetRelatedImageModelName(string $relationType, bool $isRelat } /** - * @dataProvider relationTypeProvider - * * @param string $relationType * @param bool $isRelationType * * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('relationTypeProvider')] public function testGetModelName(string $relationType, bool $isRelationType): void { if (!$isRelationType) { @@ -100,15 +96,14 @@ public function testGetModelName(string $relationType, bool $isRelationType): vo } /** - * @dataProvider relationTypeProvider - * * @param string $relationType * @param bool $isRelationType * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('relationTypeProvider')] public function testHasIdentityType(string $relationType, bool $isRelationType): void { $hasIdentityType = RelationType::hasIdentityType($relationType); @@ -116,15 +111,14 @@ public function testHasIdentityType(string $relationType, bool $isRelationType): } /** - * @dataProvider relationTypeProvider - * * @param string $relationType * @param bool $isRelationType * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('relationTypeProvider')] public function testIsRelationType(string $relationType, bool $isRelationType): void { $hasIdentityType = RelationType::isRelationType($relationType); @@ -134,7 +128,7 @@ public function testIsRelationType(string $relationType, bool $isRelationType): /** * @return array */ - public function relationTypeProvider(): array + public static function relationTypeProvider(): array { $testCases[] = [' ', false]; $testCases[] = ['Category', true]; @@ -149,7 +143,7 @@ public function relationTypeProvider(): array /** * @return array */ - public function relatedImageIdentityProvider(): array + public static function relatedImageIdentityProvider(): array { return [ ['productStockLevel', false], @@ -163,7 +157,7 @@ public function relatedImageIdentityProvider(): array /** * @return array */ - public function relatedImageIdentityTypeProvider(): array + public static function relatedImageIdentityTypeProvider(): array { return [ ['product', IdentityType::PRODUCT_IMAGE], @@ -175,16 +169,15 @@ public function relatedImageIdentityTypeProvider(): array } /** - * @dataProvider getIdentityTypeDataProvider - * * @param string $relationType * @param DefinitionException|int $expectedValue * * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('getIdentityTypeDataProvider')] public function testGetIdentityType(string $relationType, DefinitionException|int $expectedValue): void { if ($expectedValue instanceof DefinitionException) { @@ -201,7 +194,7 @@ public function testGetIdentityType(string $relationType, DefinitionException|in /** * @return array */ - public function getIdentityTypeDataProvider(): array + public static function getIdentityTypeDataProvider(): array { return [ ['category', IdentityType::CATEGORY], diff --git a/tests/src/Definition/RpcMethodTest.php b/tests/src/Definition/RpcMethodTest.php index 23dc55dc..6ecc87d2 100755 --- a/tests/src/Definition/RpcMethodTest.php +++ b/tests/src/Definition/RpcMethodTest.php @@ -6,8 +6,8 @@ use Jtl\Connector\Core\Definition\RpcMethod; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class RpcMethodTest @@ -17,15 +17,14 @@ class RpcMethodTest extends TestCase { /** - * @dataProvider isMethodDataProvider - * * @param string $methodName * @param bool $shouldBeMethod * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('isMethodDataProvider')] public function testIsMethod(string $methodName, bool $shouldBeMethod): void { $isMethodResult = RpcMethod::isMethod($methodName); @@ -33,12 +32,11 @@ public function testIsMethod(string $methodName, bool $shouldBeMethod): void } /** - * @return array - * @throws \ReflectionException + * @return array> */ - public function isMethodDataProvider(): array + public static function isMethodDataProvider(): array { - $definedMethods = $this->getCorrectConstantsTestCases(RpcMethod::class); + $definedMethods = self::getCorrectConstantsTestCases(RpcMethod::class); $customTests = []; $customTests[] = ['""', false]; @@ -52,19 +50,18 @@ public function isMethodDataProvider(): array $customTests[] = ['method\.name', false]; $customTests[] = ['very.long.method.name', true]; - return \array_merge_recursive($definedMethods, $customTests); + return \array_merge($definedMethods, $customTests); } /** - * @dataProvider mapMethodDataProvider - * * @param string $methodName * @param string $expectedMapping * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('mapMethodDataProvider')] public function testMapMethod(string $methodName, string $expectedMapping): void { $mappedName = RpcMethod::mapMethod($methodName); @@ -74,7 +71,7 @@ public function testMapMethod(string $methodName, string $expectedMapping): void /** * @return array> */ - public function mapMethodDataProvider(): array + public static function mapMethodDataProvider(): array { return [ [RpcMethod::CLEAR, 'core.connector.clear'], diff --git a/tests/src/Linker/IdentityLinkerTest.php b/tests/src/Linker/IdentityLinkerTest.php index 91480247..e4bd8912 100755 --- a/tests/src/Linker/IdentityLinkerTest.php +++ b/tests/src/Linker/IdentityLinkerTest.php @@ -19,10 +19,10 @@ use Jtl\Connector\Core\Test\TestCase; use Mockery\Exception\RuntimeException; use Mockery\LegacyMockInterface; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; use ReflectionException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class IdentityLinkerTest @@ -32,17 +32,14 @@ class IdentityLinkerTest extends TestCase { /** - * @dataProvider hostIdDataProvider - * * @param mixed $hostId * @param bool $shouldBeValid * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('hostIdDataProvider')] public function testHostIdValidator(mixed $hostId, bool $shouldBeValid): void { $isValid = $this->createLinker()->isValidHostId($hostId); @@ -54,8 +51,6 @@ public function testHostIdValidator(mixed $hostId, bool $shouldBeValid): void * @param PrimaryKeyMapperInterface|null $mockedPrimaryKeyMapper * * @return IdentityLinker - * @throws ReflectionException - * @throws RuntimeException */ protected function createLinker(?PrimaryKeyMapperInterface $mockedPrimaryKeyMapper = null): IdentityLinker { @@ -71,8 +66,6 @@ protected function createLinker(?PrimaryKeyMapperInterface $mockedPrimaryKeyMapp * @param array $endpointId * * @return PrimaryKeyMapperInterface&LegacyMockInterface - * @throws ReflectionException - * @throws RuntimeException */ public function createPrimaryKeyMapperMock( array $hostId = [1], @@ -93,27 +86,26 @@ public function createPrimaryKeyMapperMock( * @return array> * @throws \Exception */ - public function hostIdDataProvider(): array + public static function hostIdDataProvider(): array { + $hostId = \random_int(1, 9999); + return [ [0, false], [null, false], - [$this->createHostId(), true] + [$hostId, true] ]; } /** - * @dataProvider endpointIdDataProvider - * * @param mixed $endpointId * @param bool $shouldBeValid * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('endpointIdDataProvider')] public function testEndpointIdValidator(mixed $endpointId, bool $shouldBeValid): void { $isValid = $this->createLinker()->isValidEndpointId($endpointId); @@ -124,22 +116,24 @@ public function testEndpointIdValidator(mixed $endpointId, bool $shouldBeValid): * @return array> * @throws \Exception */ - public function endpointIdDataProvider(): array + public static function endpointIdDataProvider(): array { + $hostId = \random_int(1, 9999); + $endpointId = \sprintf('%s_%s', 't', $hostId); + return [ [0, false], [null, false], - [$this->createEndpointId(), true] + [$endpointId, true] ]; } /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws Exception - * @throws ReflectionException * @throws \Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCache(): void { @@ -185,11 +179,9 @@ public function testCache(): void /** * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException - * @throws RuntimeException * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testHostIdResolver(): void { @@ -209,11 +201,9 @@ public function testHostIdResolver(): void /** * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException - * @throws RuntimeException * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testEndpointIdResolver(): void { @@ -232,10 +222,8 @@ public function testEndpointIdResolver(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testIdentityClear(): void { @@ -248,11 +236,10 @@ public function testIdentityClear(): void /** * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException - * @throws \InvalidArgumentException * @throws \Exception + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testIdentitySave(): void { @@ -278,12 +265,11 @@ public function testIdentitySave(): void /** * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException + * @throws \Exception + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws LinkerException - * @throws \Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testIdentityDelete(): void { @@ -315,12 +301,11 @@ public function testIdentityDelete(): void /** * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException + * @throws \Exception + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws LinkerException - * @throws \Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testLinkModel(): void { @@ -361,12 +346,11 @@ public function testLinkModel(): void /** * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException + * @throws \Exception + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws LinkerException - * @throws \Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testUnlinkModel(): void { @@ -387,12 +371,11 @@ public function testUnlinkModel(): void /** * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException + * @throws \Exception + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws LinkerException - * @throws \Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testLinkCollection(): void { @@ -418,12 +401,11 @@ public function testLinkCollection(): void /** * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException + * @throws \Exception + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws LinkerException - * @throws \Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testUnlinkCollection(): void { @@ -453,11 +435,11 @@ public function testUnlinkCollection(): void /** * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \Exception + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws LinkerException - * @throws \Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testLinkIdentityList(): void { @@ -486,8 +468,8 @@ public function testLinkIdentityList(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ protected function tearDown(): void { diff --git a/tests/src/Logger/LoggerServiceTest.php b/tests/src/Logger/LoggerServiceTest.php index e2ec2e22..a17c01ea 100755 --- a/tests/src/Logger/LoggerServiceTest.php +++ b/tests/src/Logger/LoggerServiceTest.php @@ -18,17 +18,7 @@ use Monolog\Handler\RotatingFileHandler; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; -use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; -use PHPUnit\Framework\MockObject\ClassIsFinalException; -use PHPUnit\Framework\MockObject\ClassIsReadonlyException; -use PHPUnit\Framework\MockObject\DuplicateMethodException; -use PHPUnit\Framework\MockObject\InvalidMethodNameException; -use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; -use PHPUnit\Framework\MockObject\ReflectionException; -use PHPUnit\Framework\MockObject\RuntimeException; -use PHPUnit\Framework\MockObject\UnknownTypeException; use Psr\Log\LogLevel; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class LoggerServiceTest extends TestCase { @@ -38,12 +28,10 @@ class LoggerServiceTest extends TestCase /** * @return void - * @throws LoggerException * @throws Exception - * @throws ExpectationFailedException - * @throws \ReflectionException - * @throws \RuntimeException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws LoggerException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSetFormat(): void { @@ -59,8 +47,6 @@ public function testSetFormat(): void /** * @return void * @throws LoggerException - * @throws \ReflectionException - * @throws \RuntimeException */ public function testSetFormatFormatterNotFound(): void { @@ -71,18 +57,8 @@ public function testSetFormatFormatterNotFound(): void /** * @return void - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSetFormatter(): void { @@ -98,20 +74,10 @@ public function testSetFormatter(): void /** * @return void * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws \OutOfBoundsException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException * @throws \UnexpectedValueException */ @@ -159,11 +125,10 @@ public function testSetFormatterToExistingLoggers(): void /** * @return void * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException - * @throws \ReflectionException * @throws \UnexpectedValueException */ public function testGet(): void @@ -194,9 +159,9 @@ public function testGet(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException * @throws \UnexpectedValueException */ @@ -208,8 +173,8 @@ public function testHas(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testHasNot(): void { @@ -220,7 +185,6 @@ public function testHasNot(): void * @return void * @throws \InvalidArgumentException * @throws \Psr\Log\InvalidArgumentException - * @throws \RuntimeException * @throws \UnexpectedValueException */ protected function setUp(): void diff --git a/tests/src/Model/AbstractImageTest.php b/tests/src/Model/AbstractImageTest.php index 2ec91090..7a8d9124 100755 --- a/tests/src/Model/AbstractImageTest.php +++ b/tests/src/Model/AbstractImageTest.php @@ -11,33 +11,22 @@ use Jtl\Connector\Core\Model\ProductImage; use Jtl\Connector\Core\Model\ProductVariationValueImage; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; -use PHPUnit\Framework\MockObject\ClassIsFinalException; -use PHPUnit\Framework\MockObject\ClassIsReadonlyException; -use PHPUnit\Framework\MockObject\DuplicateMethodException; -use PHPUnit\Framework\MockObject\InvalidMethodNameException; -use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; -use PHPUnit\Framework\MockObject\ReflectionException; -use PHPUnit\Framework\MockObject\UnknownClassException; -use PHPUnit\Framework\MockObject\UnknownTypeException; use RuntimeException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class AbstractImageTest extends TestCase { /** - * @dataProvider relationTypeProvider - * * @param AbstractImage $image * @param string $relationType * * @return void * @throws DefinitionException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws RuntimeException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('relationTypeProvider')] public function testGetRelationType(AbstractImage $image, string $relationType): void { $this->assertEquals($relationType, $image->getRelationType()); @@ -51,7 +40,7 @@ public function testGetRelationType(AbstractImage $image, string $relationType): * 3: array{0: ManufacturerImage} * } */ - public function relationTypeProvider(): array + public static function relationTypeProvider(): array { return [ [new CategoryImage(), 'category'], @@ -62,26 +51,14 @@ public function relationTypeProvider(): array } /** - * @dataProvider extensionProvider - * * @param string $fileName * @param string $expectedExtension * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws \PHPUnit\Framework\MockObject\RuntimeException - * @throws UnknownClassException - * @throws UnknownTypeException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('extensionProvider')] public function testGetExtension(string $fileName, string $expectedExtension): void { $image = $this->getMockForAbstractClass(AbstractImage::class); @@ -92,7 +69,7 @@ public function testGetExtension(string $fileName, string $expectedExtension): v /** * @return array */ - public function extensionProvider(): array + public static function extensionProvider(): array { return [ ['file.name', 'name'], diff --git a/tests/src/Model/ModelTest.php b/tests/src/Model/ModelTest.php index 74ada130..a9cc797d 100755 --- a/tests/src/Model/ModelTest.php +++ b/tests/src/Model/ModelTest.php @@ -4,7 +4,6 @@ namespace Jtl\Connector\Core\Tests\Model; -use Doctrine\Common\Annotations\AnnotationException; use Exception; use JMS\Serializer\Exception\InvalidArgumentException; use JMS\Serializer\Exception\LogicException; @@ -17,25 +16,25 @@ use Jtl\Connector\Core\Model\Product; use Jtl\Connector\Core\Serializer\SerializerBuilder; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; class ModelTest extends TestCase { /** - * @dataProvider modelsDataProvider * @doesNotPerformAssertions * * @param string $modelName * * @return void - * @throws InvalidArgumentException - * @throws RuntimeException - * @throws AnnotationException + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws LogicException * @throws NotAcceptableException + * @throws RuntimeException * @throws UnsupportedFormatException */ + #[DataProvider('modelsDataProvider')] public function testModelsInitialization(string $modelName): void { $serializer = SerializerBuilder::create()->build(); @@ -50,16 +49,18 @@ public function testModelsInitialization(string $modelName): void /** * @return array> - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws \RuntimeException */ - public function modelsDataProvider(): array + public static function modelsDataProvider(): array { $ignoredModels = self::getIgnoredModels(); $modelsPattern = \dirname(\TEST_DIR) . '/src/Model/*.php'; $array_map = []; $models = \glob($modelsPattern); - $this->assertNotFalse($models); + if ($models === false) { + throw new \RuntimeException('glob() returned false'); + } foreach ($models as $key => $modelPath) { $fileInfo = new \SplFileInfo($modelPath); $modelName = $fileInfo->getBasename('.php'); @@ -99,8 +100,6 @@ public static function getIgnoredModels(): array } /** - * @dataProvider unsetIdentificationStringProvider - * * @param string $identificationString * @param string $subject * @param bool $setString @@ -108,6 +107,7 @@ public static function getIgnoredModels(): array * @return void * @throws Exception */ + #[DataProvider('unsetIdentificationStringProvider')] public function testUnsetIdentificationString(string $identificationString, string $subject, bool $setString): void { $model = $this->getMockForAbstractClass(AbstractModel::class); @@ -134,18 +134,16 @@ public function testUnsetIdentificationString(string $identificationString, stri } /** - * @dataProvider unsetIdentificationStringProvider - * * @param string $identificationString * @param string $subject * @param bool $setString * * @return void - * @throws \PHPUnit\Framework\Exception - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException * @throws Exception + * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('unsetIdentificationStringProvider')] public function testUnsetIdentificationStringBySubject( string $identificationString, string $subject, @@ -192,7 +190,7 @@ public function testUnsetIdentificationStringBySubject( * 1: array{0: string, 1: 'hallo', 2: false} * } */ - public function unsetIdentificationStringProvider(): array + public static function unsetIdentificationStringProvider(): array { return [ [\uniqid('foo-', false), 'hola', true], diff --git a/tests/src/Model/TranslatableAttributeI18nTest.php b/tests/src/Model/TranslatableAttributeI18nTest.php index db58fbb0..6b5b4e34 100755 --- a/tests/src/Model/TranslatableAttributeI18nTest.php +++ b/tests/src/Model/TranslatableAttributeI18nTest.php @@ -10,25 +10,24 @@ use Jtl\Connector\Core\Model\TranslatableAttributeI18n; use Jtl\Connector\Core\Test\TestCase; use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class TranslatableAttributeI18nTest extends TestCase { /** - * @dataProvider getValueProvider - * * @param string $type * @param mixed $originalValue * @param mixed $expectedValue * @param bool $strictMode * * @return void - * @throws TranslatableAttributeException + * @throws \InvalidArgumentException * @throws JsonException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws TranslatableAttributeException */ + #[DataProvider('getValueProvider')] public function testGetValue( string $type, mixed $originalValue, @@ -61,7 +60,7 @@ public function testGetValue( /** * @return array|null>> */ - public function getValueProvider(): array + public static function getValueProvider(): array { return [ ['int', '2', 2], @@ -110,18 +109,17 @@ public function testGetValueAndJsonDecodingFailedInStrictMode(): void } /** - * @dataProvider setValueProvider - * * @param mixed $value * @param float|int|string|bool $expectedValue * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws AssertionFailedError + * @throws \InvalidArgumentException * @throws JsonException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws TranslatableAttributeException - * @throws AssertionFailedError */ + #[DataProvider('setValueProvider')] public function testSetValue(mixed $value, float|int|string|bool $expectedValue): void { $translation = (new TranslatableAttributeI18n())->setValue($value); @@ -152,7 +150,7 @@ public function testSetValue(mixed $value, float|int|string|bool $expectedValue) /** * @return array>> */ - public function setValueProvider(): array + public static function setValueProvider(): array { return [ [true, '1'], @@ -169,14 +167,13 @@ public function setValueProvider(): array } /** - * @dataProvider setValueInvalidTypeProvider - * * @param mixed $value * * @return void * @throws JsonException * @throws TranslatableAttributeException */ + #[DataProvider('setValueInvalidTypeProvider')] public function testSetValueWrongType(mixed $value): void { $this->expectException(TranslatableAttributeException::class); @@ -187,7 +184,7 @@ public function testSetValueWrongType(mixed $value): void /** * @return array{0: array{null}, 1: array{0: false|resource}} */ - public function setValueInvalidTypeProvider(): array + public static function setValueInvalidTypeProvider(): array { /** @noinspection FopenBinaryUnsafeUsageInspection */ return [ diff --git a/tests/src/Model/TranslatableAttributeTest.php b/tests/src/Model/TranslatableAttributeTest.php index e4005b96..402c114e 100755 --- a/tests/src/Model/TranslatableAttributeTest.php +++ b/tests/src/Model/TranslatableAttributeTest.php @@ -12,37 +12,23 @@ use Jtl\Connector\Core\Model\TranslatableAttribute; use Jtl\Connector\Core\Model\TranslatableAttributeI18n; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; -use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; -use PHPUnit\Framework\MockObject\ClassIsFinalException; -use PHPUnit\Framework\MockObject\ClassIsReadonlyException; -use PHPUnit\Framework\MockObject\DuplicateMethodException; -use PHPUnit\Framework\MockObject\IncompatibleReturnValueException; -use PHPUnit\Framework\MockObject\InvalidMethodNameException; -use PHPUnit\Framework\MockObject\MethodCannotBeConfiguredException; -use PHPUnit\Framework\MockObject\MethodNameAlreadyConfiguredException; -use PHPUnit\Framework\MockObject\MethodNameNotConfiguredException; -use PHPUnit\Framework\MockObject\MethodParametersAlreadyConfiguredException; -use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; -use PHPUnit\Framework\MockObject\ReflectionException; -use PHPUnit\Framework\MockObject\RuntimeException; -use PHPUnit\Framework\MockObject\UnknownTypeException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class TranslatableAttributeTest extends TestCase { /** - * @dataProvider findTranslationProvider - * * @param string $languageIso * @param TranslatableAttributeI18n|null $expectedTranslation * @param array $translations * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('findTranslationProvider')] public function testFindTranslation( string $languageIso, ?TranslatableAttributeI18n $expectedTranslation, @@ -57,10 +43,11 @@ public function testFindTranslation( } /** - * @return array|null>> + * @return array> * @throws \Exception + * @throws \RuntimeException */ - public function findTranslationProvider(): array + public static function findTranslationProvider(): array { /** @var TranslatableAttributeI18nFactory $translationsFactory */ $translationsFactory = AbstractModelFactory::createFactory('TranslatableAttributeI18n'); @@ -68,11 +55,10 @@ public function findTranslationProvider(): array /** @var TranslatableAttributeI18n[] $translations */ $translations = $translationsFactory->make(\random_int(2, 10)); $translationsCount = \count($translations); - $this->assertGreaterThan(1, $translationsCount); - $randomIntMax = $translationsCount - 1; - if ($randomIntMax < 1) { - $this->fail('$randomIntMax must be greater than 0.'); + if ($translationsCount < 2) { + throw new \RuntimeException('$translationsCount must be greater than 1.'); } + $randomIntMax = $translationsCount - 1; return [ [ @@ -93,35 +79,19 @@ public function findTranslationProvider(): array } /** - * @dataProvider findValueProvider - * * @param string $type * @param TranslatableAttributeI18n|null $translation * @param mixed $expectedValue * * @return void * @throws Exception - * @throws ExpectationFailedException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws JsonException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws MethodNameNotConfiguredException - * @throws MethodParametersAlreadyConfiguredException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws TranslatableAttributeException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @depends testSetType */ + #[DataProvider('findValueProvider')] + #[Depends('testSetType')] public function testFindValue(string $type, ?TranslatableAttributeI18n $translation, mixed $expectedValue): void { $attribute = $this->createPartialMock(TranslatableAttribute::class, ['findTranslation']); @@ -145,7 +115,7 @@ public function testFindValue(string $type, ?TranslatableAttributeI18n $translat * @return array> * @throws \Exception */ - public function findValueProvider(): array + public static function findValueProvider(): array { /** @var TranslatableAttributeI18nFactory $translationsFactory */ $translationsFactory = AbstractModelFactory::createFactory('TranslatableAttributeI18n'); @@ -165,16 +135,15 @@ public function findValueProvider(): array } /** - * @dataProvider getNameProvider - * * @param array $translations * @param string $expectedName * @param string $languageIso * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('getNameProvider')] public function testGetName(array $translations, string $expectedName, string $languageIso): void { $attribute = (new TranslatableAttribute()) @@ -189,7 +158,7 @@ public function testGetName(array $translations, string $expectedName, string $l * @return array * @throws \Exception */ - public function getNameProvider(): array + public static function getNameProvider(): array { /** @var TranslatableAttributeI18nFactory $translationsFactory */ $translationsFactory = AbstractModelFactory::createFactory('TranslatableAttributeI18n'); @@ -225,18 +194,17 @@ public function getNameProvider(): array } /** - * @dataProvider getValuesProvider - * * @param TranslatableAttributeI18n[] $translations * @param array $expectedValues * @param string|null $castToType * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws JsonException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws TranslatableAttributeException */ + #[DataProvider('getValuesProvider')] public function testGetValues(array $translations, array $expectedValues, ?string $castToType = null): void { $attribute = (new TranslatableAttribute()) @@ -251,7 +219,7 @@ public function testGetValues(array $translations, array $expectedValues, ?strin * @return array}> * @throws \Exception */ - public function getValuesProvider(): array + public static function getValuesProvider(): array { /** @var TranslatableAttributeI18nFactory $translationsFactory */ $translationsFactory = AbstractModelFactory::createFactory('TranslatableAttributeI18n'); @@ -280,10 +248,10 @@ public function getValuesProvider(): array * @param string $expectedType * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @dataProvider setTypeProvider + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('setTypeProvider')] public function testSetType(string $actualType, string $expectedType): void { $attribute = new TranslatableAttribute(); @@ -295,7 +263,7 @@ public function testSetType(string $actualType, string $expectedType): void /** * @return array> */ - public function setTypeProvider(): array + public static function setTypeProvider(): array { $data = []; foreach (TranslatableAttribute::getTypes() as $type) { diff --git a/tests/src/Rpc/ErrorTest.php b/tests/src/Rpc/ErrorTest.php index f2910072..0a4fc52a 100755 --- a/tests/src/Rpc/ErrorTest.php +++ b/tests/src/Rpc/ErrorTest.php @@ -8,7 +8,6 @@ use Jtl\Connector\Core\Rpc\Error; use Jtl\Connector\Core\Test\TestCase; use PHPUnit\Framework\AssertionFailedError; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class ErrorTest @@ -47,7 +46,7 @@ public function testValidateThrowExceptionWhenMessageIsNotSet(): void /** * @return void * @throws AssertionFailedError - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ public function testValidateCorrect(): void { @@ -60,6 +59,6 @@ public function testValidateCorrect(): void } catch (RpcException $rpcException) { $this->fail($rpcException->getMessage()); } - $this->assertIsObject($error); + $this->addToAssertionCount(1); } } diff --git a/tests/src/Rpc/MethodTest.php b/tests/src/Rpc/MethodTest.php index 1f6eaf94..8ee2622a 100755 --- a/tests/src/Rpc/MethodTest.php +++ b/tests/src/Rpc/MethodTest.php @@ -9,8 +9,8 @@ use Jtl\Connector\Core\Definition\Controller; use Jtl\Connector\Core\Rpc\Method; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class MethodTest @@ -21,8 +21,8 @@ class MethodTest extends TestCase { /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testConstructorParameters(): void { @@ -35,18 +35,17 @@ public function testConstructorParameters(): void } /** - * @dataProvider createFromRpcMethodDataProvider - * * @param string $rpcMethod * @param string $expectedController * @param string $expectedAction * @param bool $isCore * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws CaseConverterException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('createFromRpcMethodDataProvider')] public function testCreateFromRpcMethod( string $rpcMethod, string $expectedController, @@ -63,7 +62,7 @@ public function testCreateFromRpcMethod( /** * @return array> */ - public function createFromRpcMethodDataProvider(): array + public static function createFromRpcMethodDataProvider(): array { return [ [ diff --git a/tests/src/Rpc/PacketTest.php b/tests/src/Rpc/PacketTest.php index e45fab1a..f5774434 100755 --- a/tests/src/Rpc/PacketTest.php +++ b/tests/src/Rpc/PacketTest.php @@ -17,8 +17,8 @@ class PacketTest extends TestCase { /** * @return void - * @throws \ReflectionException * @throws \Exception + * @throws \ReflectionException */ public function testToArray(): void { diff --git a/tests/src/Rpc/RequestPacketTest.php b/tests/src/Rpc/RequestPacketTest.php index da11220e..85d3afcb 100755 --- a/tests/src/Rpc/RequestPacketTest.php +++ b/tests/src/Rpc/RequestPacketTest.php @@ -4,16 +4,15 @@ namespace Jtl\Connector\Core\Test\Rpc; -use Doctrine\Common\Annotations\AnnotationException; use JMS\Serializer\Exception\LogicException; use JMS\Serializer\Exception\NotAcceptableException; use JMS\Serializer\Exception\UnsupportedFormatException; use JMS\Serializer\SerializerBuilder; use Jtl\Connector\Core\Rpc\RequestPacket; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use RuntimeException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class RequestPacketTest @@ -23,16 +22,15 @@ class RequestPacketTest extends TestCase { /** - * @dataProvider validPacketDataProvider - * * @param array{0: string, 1: string, 2: string, 3: array} $inputParams * @param array{0: string, 1: string, 2: string, 3: array} $expectedParams * @param bool $isValid * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('validPacketDataProvider')] public function testValidPacket(array $inputParams, array $expectedParams, bool $isValid): void { $requestPacket = new RequestPacket(); @@ -48,9 +46,9 @@ public function testValidPacket(array $inputParams, array $expectedParams, bool } /** - * @return array|array{}|array{array{}}>|bool>> + * @return list, list, bool}> */ - public function validPacketDataProvider(): array + public static function validPacketDataProvider(): array { return [ [ @@ -112,24 +110,21 @@ public function validPacketDataProvider(): array } /** - * @dataProvider createFromJtlRpcDataProvider - * * @param string $jtlRpcInput * @param array{0: string, 1: string, 2: array} $expectedParams * @param bool $isValid * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws RuntimeException - * @throws AnnotationException + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws \JMS\Serializer\Exception\InvalidArgumentException + * @throws \JMS\Serializer\Exception\RuntimeException * @throws LogicException * @throws NotAcceptableException - * @throws \JMS\Serializer\Exception\RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws UnsupportedFormatException */ + #[DataProvider('createFromJtlRpcDataProvider')] public function testCreateFromJtlrpc(string $jtlRpcInput, array $expectedParams, bool $isValid): void { $requestPacket = RequestPacket::createFromJtlrpc($jtlRpcInput); @@ -144,7 +139,7 @@ public function testCreateFromJtlrpc(string $jtlRpcInput, array $expectedParams, /** * @return array>|bool>> */ - public function createFromJtlRpcDataProvider(): array + public static function createFromJtlRpcDataProvider(): array { return [ ['', ['', 'undefined.undefined', [],], false,], @@ -158,24 +153,21 @@ public function createFromJtlRpcDataProvider(): array } /** - * @dataProvider createFromJtlRpcDataProvider - * * @param string $jtlRpcInput * @param array{0: string, 1: string, 2: array} $expectedParams * @param bool $isValid * * @return void - * @throws AnnotationException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws LogicException - * @throws NotAcceptableException - * @throws RuntimeException - * @throws UnsupportedFormatException + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws \JMS\Serializer\Exception\RuntimeException + * @throws LogicException + * @throws NotAcceptableException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws UnsupportedFormatException */ + #[DataProvider('createFromJtlRpcDataProvider')] public function testCreateFromJtlRpcUseAnotherSerializer( string $jtlRpcInput, array $expectedParams, diff --git a/tests/src/Rpc/ResponsePacketTest.php b/tests/src/Rpc/ResponsePacketTest.php index 74e27ded..9215495f 100755 --- a/tests/src/Rpc/ResponsePacketTest.php +++ b/tests/src/Rpc/ResponsePacketTest.php @@ -9,8 +9,8 @@ use Jtl\Connector\Core\Rpc\Error; use Jtl\Connector\Core\Rpc\ResponsePacket; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class ResponsePacketTest @@ -20,8 +20,6 @@ class ResponsePacketTest extends TestCase { /** - * @dataProvider isValidDataProvider - * * @param string $id * @param Error|null $error * @param mixed $result @@ -29,10 +27,11 @@ class ResponsePacketTest extends TestCase * @param bool $isValid * * @return void + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws RpcException - * @throws ExpectationFailedException - * @throws InvalidArgumentException */ + #[DataProvider('isValidDataProvider')] public function testIsValid(string $id, ?Error $error, mixed $result, string $jtlRpc, bool $isValid): void { $responsePacket = new ResponsePacket(); @@ -50,7 +49,7 @@ public function testIsValid(string $id, ?Error $error, mixed $result, string $jt /** * @return array> */ - public function isValidDataProvider(): array + public static function isValidDataProvider(): array { return [ [ diff --git a/tests/src/Serializer/Handler/IdentityHandlerTest.php b/tests/src/Serializer/Handler/IdentityHandlerTest.php index 11151c8f..172e2c76 100755 --- a/tests/src/Serializer/Handler/IdentityHandlerTest.php +++ b/tests/src/Serializer/Handler/IdentityHandlerTest.php @@ -11,6 +11,7 @@ use Jtl\Connector\Core\Model\Identity; use Jtl\Connector\Core\Serializer\Handler\IdentityHandler; use Jtl\Connector\Core\Test\TestCase; +use PHPUnit\Framework\Attributes\DataProvider; /** * Class IdentityHandlerTest @@ -71,14 +72,13 @@ public function testDeserializeEntityMethod(): void } /** - * @dataProvider identityDataProvider - * * @param IdentityHandler $identityHandler * @param array{0: string, 1: int} $identityArray * * @return void * @throws \Exception */ + #[DataProvider('identityDataProvider')] public function testDeserializeEntityMultipleMethod(IdentityHandler $identityHandler, array $identityArray): void { $identity = new Identity($identityArray[0], $identityArray[1]); @@ -99,7 +99,7 @@ public function testDeserializeEntityMultipleMethod(IdentityHandler $identityHan /** * @return array|IdentityHandler>> */ - public function identityDataProvider(): array + public static function identityDataProvider(): array { $identityHandler = new IdentityHandler(); diff --git a/tests/src/Serializer/Subscriber/CrossSellingSubscriberTest.php b/tests/src/Serializer/Subscriber/CrossSellingSubscriberTest.php index a09a74f9..21d2435c 100755 --- a/tests/src/Serializer/Subscriber/CrossSellingSubscriberTest.php +++ b/tests/src/Serializer/Subscriber/CrossSellingSubscriberTest.php @@ -8,43 +8,23 @@ use JMS\Serializer\EventDispatcher\PreDeserializeEvent; use Jtl\Connector\Core\Model\CrossSelling; use Jtl\Connector\Core\Serializer\Subscriber\CrossSellingSubscriber; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; -use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; -use PHPUnit\Framework\MockObject\ClassIsFinalException; -use PHPUnit\Framework\MockObject\ClassIsReadonlyException; -use PHPUnit\Framework\MockObject\DuplicateMethodException; -use PHPUnit\Framework\MockObject\InvalidMethodNameException; -use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; -use PHPUnit\Framework\MockObject\ReflectionException; -use PHPUnit\Framework\MockObject\RuntimeException; -use PHPUnit\Framework\MockObject\UnknownTypeException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class CrossSellingSubscriberTest extends TestCase { /** - * @dataProvider crossSellingDataProvider - * * @param array $data * @param int ...$expectedItemIds * * @return void * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('crossSellingDataProvider')] public function testOnPreDeserialize(array $data, int ...$expectedItemIds): void { $context = $this->createMock(DeserializationContext::class); @@ -60,6 +40,7 @@ public function testOnPreDeserialize(array $data, int ...$expectedItemIds): void $this->assertArrayHasKey('items', $eventData); $items = $eventData['items']; $this->assertIsArray($items); + /** @var array> $items */ foreach ($items as $i => $item) { $this->assertArrayHasKey('id', $item); $this->assertIsArray($item['id']); @@ -73,7 +54,7 @@ public function testOnPreDeserialize(array $data, int ...$expectedItemIds): void * //phpcs:ignore Generic.Files.LineLength.TooLong, SlevomatCodingStandard.Commenting.DocCommentSpacing.IncorrectLinesCountBetweenDescriptionAndAnnotations * @return array|int|string>>|int|string>>|int>> */ - public function crossSellingDataProvider(): array + public static function crossSellingDataProvider(): array { $items = [ [ diff --git a/tests/src/Serializer/Subscriber/ImageSubscriberTest.php b/tests/src/Serializer/Subscriber/ImageSubscriberTest.php index 28e76817..a1efafbd 100755 --- a/tests/src/Serializer/Subscriber/ImageSubscriberTest.php +++ b/tests/src/Serializer/Subscriber/ImageSubscriberTest.php @@ -4,7 +4,6 @@ namespace Jtl\Connector\Core\Test\Serializer\Subscriber; -use Doctrine\Common\Annotations\AnnotationException; use JMS\Serializer\Exception\LogicException; use JMS\Serializer\Exception\NotAcceptableException; use JMS\Serializer\Exception\RuntimeException; @@ -16,21 +15,18 @@ use Jtl\Connector\Core\Test\TestCase; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class ImageSubscriberTest extends TestCase { /** * @return void - * @throws AnnotationException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LogicException * @throws NotAcceptableException - * @throws RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws UnsupportedFormatException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException */ public function testOnPostSerialize(): void { @@ -40,6 +36,7 @@ public function testOnPostSerialize(): void $image = (new ManufacturerImage())->setId(new Identity($endpoint, $expectedHost)); $serializer = SerializerBuilder::create()->build(); $data = $serializer->toArray($image); + $this->assertIsArray($data['id']); $this->assertEquals($expectedEndpoint, $data['id'][0]); $this->assertEquals($expectedHost, $data['id'][1]); } @@ -47,14 +44,12 @@ public function testOnPostSerialize(): void /** * @return void * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws RuntimeException - * @throws AnnotationException + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LogicException * @throws NotAcceptableException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws UnsupportedFormatException */ public function testOnPostDeserialize(): void diff --git a/tests/src/Serializer/Subscriber/LanguageIsoSubscriberTest.php b/tests/src/Serializer/Subscriber/LanguageIsoSubscriberTest.php index 22041e44..c0b9345e 100755 --- a/tests/src/Serializer/Subscriber/LanguageIsoSubscriberTest.php +++ b/tests/src/Serializer/Subscriber/LanguageIsoSubscriberTest.php @@ -4,7 +4,6 @@ namespace Jtl\Connector\Core\Test\Serializer\Subscriber; -use Doctrine\Common\Annotations\AnnotationException; use JMS\Serializer\Exception\LogicException; use JMS\Serializer\Exception\NotAcceptableException; use JMS\Serializer\Exception\RuntimeException; @@ -19,9 +18,9 @@ use Jtl\Connector\Core\Serializer\SerializerBuilder; use Jtl\Connector\Core\Test\TestCase; use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class LanguageIsoSubscriberTest @@ -33,7 +32,7 @@ class LanguageIsoSubscriberTest extends TestCase /** * @return array */ - public function i18NDataProvider(): array + public static function i18NDataProvider(): array { return [ [ProductI18n::class], @@ -45,24 +44,21 @@ public function i18NDataProvider(): array } /** - * @dataProvider i18NDataProvider - * * @param class-string $model * * @return void - * @throws AnnotationException * @throws AssertionFailedError * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws JsonException * @throws LogicException * @throws NotAcceptableException - * @throws RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws UnsupportedFormatException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException */ + #[DataProvider('i18NDataProvider')] public function testOnPostSerializeWithInvalidValue(string $model): void { $i18nModel = new $model(); @@ -86,13 +82,11 @@ public function testOnPostSerializeWithInvalidValue(string $model): void * @param AbstractI18n $i18nModel * * @return string - * @throws AnnotationException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LogicException * @throws NotAcceptableException - * @throws RuntimeException * @throws UnsupportedFormatException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException */ protected function serializeModel(AbstractI18n $i18nModel): string { @@ -100,24 +94,21 @@ protected function serializeModel(AbstractI18n $i18nModel): string } /** - * @dataProvider i18NDataProvider - * * @param class-string $model * * @return void - * @throws AnnotationException * @throws AssertionFailedError * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws JsonException * @throws LogicException * @throws NotAcceptableException - * @throws RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws UnsupportedFormatException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException */ + #[DataProvider('i18NDataProvider')] public function testOnPostSerializeWithEmptyValue(string $model): void { $i18nModel = new $model(); @@ -135,24 +126,21 @@ public function testOnPostSerializeWithEmptyValue(string $model): void } /** - * @dataProvider i18NDataProvider - * * @param string $model * * @return void - * @throws AnnotationException * @throws AssertionFailedError * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws JsonException * @throws LogicException * @throws NotAcceptableException - * @throws RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws UnsupportedFormatException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException */ + #[DataProvider('i18NDataProvider')] public function testOnPostSerializeWithValidValue(string $model): void { $i18nModel = new $model(); @@ -171,24 +159,21 @@ public function testOnPostSerializeWithValidValue(string $model): void } /** - * @dataProvider i18NDataProvider - * * @param class-string $model * * @return void - * @throws AnnotationException * @throws AssertionFailedError * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws JsonException * @throws LogicException * @throws NotAcceptableException - * @throws RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws UnsupportedFormatException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException */ + #[DataProvider('i18NDataProvider')] public function testOnPostSerializeWithNoValue(string $model): void { $i18nModel = new $model(); @@ -205,23 +190,20 @@ public function testOnPostSerializeWithNoValue(string $model): void } /** - * @dataProvider i18NDataProvider - * * @param class-string $model * * @return void - * @throws AnnotationException * @throws AssertionFailedError * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LogicException * @throws NotAcceptableException - * @throws RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws UnsupportedFormatException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException */ + #[DataProvider('i18NDataProvider')] public function testOnPreDeserializeWithValidValue(string $model): void { $i18nModel = new $model(); @@ -230,9 +212,6 @@ public function testOnPreDeserializeWithValidValue(string $model): void $deserializeData = $this->serializeAndDeserializeModel($i18nModel); - if (!\property_exists($deserializeData, 'languageIso')) { - $this->fail('property "languageISO" does not exist.'); - } $this->assertSame($deserializeData->getLanguageIso(), 'de'); } @@ -241,14 +220,12 @@ public function testOnPreDeserializeWithValidValue(string $model): void * * @return ProductI18n * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws RuntimeException - * @throws AnnotationException + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LogicException * @throws NotAcceptableException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws UnsupportedFormatException */ protected function serializeAndDeserializeModel(AbstractI18n $i18nModel): ProductI18n @@ -261,23 +238,20 @@ protected function serializeAndDeserializeModel(AbstractI18n $i18nModel): Produc } /** - * @dataProvider i18NDataProvider - * * @param class-string $model * * @return void - * @throws AnnotationException * @throws AssertionFailedError * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \JMS\Serializer\Exception\InvalidArgumentException * @throws LogicException * @throws NotAcceptableException - * @throws RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws UnsupportedFormatException - * @throws \InvalidArgumentException - * @throws \JMS\Serializer\Exception\InvalidArgumentException */ + #[DataProvider('i18NDataProvider')] public function testOnPreDeserializeWithInValidValue(string $model): void { $value = '_____'; @@ -288,9 +262,6 @@ public function testOnPreDeserializeWithInValidValue(string $model): void $deserializeData = $this->serializeAndDeserializeModel($i18nModel); - if (!\property_exists($deserializeData, 'languageIso')) { - $this->fail('property "languageISO" does not exist.'); - } $this->assertSame($deserializeData->getLanguageIso(), $value); } } diff --git a/tests/src/Serializer/Subscriber/ProductAttributeSubscriberTest.php b/tests/src/Serializer/Subscriber/ProductAttributeSubscriberTest.php index 52bf0c1c..8e6633a4 100755 --- a/tests/src/Serializer/Subscriber/ProductAttributeSubscriberTest.php +++ b/tests/src/Serializer/Subscriber/ProductAttributeSubscriberTest.php @@ -47,7 +47,9 @@ public function testOnPostSerializeAppendProductAttrIdToAttributes(): void $productObj = \json_decode($serializedProduct, false, 512, \JSON_THROW_ON_ERROR); foreach ($productObj->attributes[0]->i18ns as $index => $i18n) { //@phpstan-ignore-line + /** @var int $index */ $attributeId = $attributes[$index]->getId(); + /** @var stdClass $i18n */ if (!\property_exists($i18n, 'productAttrId')) { $this->fail('property \'productAttrId\' does not exist.'); } @@ -141,9 +143,16 @@ public function testOnPostSerializeAppendProductAttrIdToAttributesNestedObjects( $resultArr = $responseObj->result; $this->assertIsArray($resultArr); $this->assertArrayHasKey(0, $resultArr); + /** @var stdClass $responseProduct */ $responseProduct = $resultArr[0]; + /** @var list $attributes */ + $attributes = $responseProduct->attributes; + /** @var stdClass $firstAttr */ + $firstAttr = $attributes[0]; + /** @var list $i18ns */ + $i18ns = $firstAttr->i18ns; /** @var stdClass $i18n */ - $i18n = $responseProduct->attributes[0]->i18ns[0]; + $i18n = $i18ns[0]; if (!\property_exists($i18n, 'productAttrId')) { $this->fail('property \'productAttrId\' does not exist.'); diff --git a/tests/src/Session/SessionHelperTest.php b/tests/src/Session/SessionHelperTest.php index 7ace7faa..f4461843 100755 --- a/tests/src/Session/SessionHelperTest.php +++ b/tests/src/Session/SessionHelperTest.php @@ -9,18 +9,18 @@ use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class SessionHelperTest extends TestCase { /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testHas(): void { - $helper = new SessionHelper('foo'); + $helper = new SessionHelper('foo'); + /** @var array> $_SESSION */ $_SESSION['foo']['bar'] = 'boofar'; $_SESSION['foo']['you'] = 'yalla'; $this->assertTrue($helper->has('bar')); @@ -29,8 +29,8 @@ public function testHas(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testHasNot(): void { @@ -41,12 +41,13 @@ public function testHasNot(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGet(): void { - $helper = new SessionHelper('foo'); + $helper = new SessionHelper('foo'); + /** @var array> $_SESSION */ $_SESSION['foo']['bar'] = 'vaaaaalue'; $_SESSION['foo']['och'] = 'taataa'; $this->assertEquals('vaaaaalue', $helper->get('bar')); @@ -55,8 +56,8 @@ public function testGet(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetDefault(): void { @@ -67,14 +68,15 @@ public function testGetDefault(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSet(): void { $helper = new SessionHelper('yo'); $helper->set('lo', 'miau'); + /** @var array> $_SESSION */ $this->assertArrayHasKey('lo', $_SESSION['yo']); $this->assertEquals('miau', $_SESSION['yo']['lo']); } @@ -82,12 +84,13 @@ public function testSet(): void /** * @return void * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testUnset(): void { - $helper = new SessionHelper('tests'); + $helper = new SessionHelper('tests'); + /** @var array> $_SESSION */ $_SESSION['tests']['foo'] = 'bar'; $this->assertArrayHasKey('foo', $_SESSION['tests']); $helper->unset('foo'); @@ -96,10 +99,9 @@ public function testUnset(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws SessionException - * @throws \ReflectionException */ public function testCreateByObjectClass(): void { diff --git a/tests/src/Session/SqliteSessionHandlerTest.php b/tests/src/Session/SqliteSessionHandlerTest.php index bfcf5616..0fa4ca5b 100755 --- a/tests/src/Session/SqliteSessionHandlerTest.php +++ b/tests/src/Session/SqliteSessionHandlerTest.php @@ -13,7 +13,6 @@ use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\ExpectationFailedException; use RuntimeException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class SqliteSessionHandlerTest extends TestCase { @@ -23,8 +22,8 @@ class SqliteSessionHandlerTest extends TestCase /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testConstruct(): void { @@ -33,8 +32,8 @@ public function testConstruct(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException */ public function testClose(): void @@ -44,8 +43,8 @@ public function testClose(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Throwable */ public function testDestroy(): void @@ -91,7 +90,10 @@ protected function findSessionData(string $sessionId): ?array $stmt->execute(); $data = $stmt->fetch(\PDO::FETCH_ASSOC); if (\is_array($data)) { - $data['sessionData'] = \base64_decode($data['sessionData'], true); + /** @var string $sessionData */ + $sessionData = $data['sessionData']; + $data['sessionData'] = \base64_decode($sessionData, true); + /** @var array $data */ return $data; } return null; @@ -100,11 +102,10 @@ protected function findSessionData(string $sessionId): ?array /** * @return void * @throws DatabaseException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws RuntimeException + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws \PDOException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException */ public function testWriteInsert(): void @@ -114,8 +115,9 @@ public function testWriteInsert(): void $now = \time(); $this->assertNull($this->findSessionData($sessionId)); $this->handler->write($sessionId, $sessionData); + /** @var array|null $data */ $data = $this->findSessionData($sessionId); - $this->assertIsArray($data); + $this->assertNotNull($data); $this->assertEquals($sessionId, $data['sessionId']); $this->assertEquals($sessionData, $data['sessionData']); $this->assertGreaterThan($now, $data['sessionExpires']); @@ -124,11 +126,10 @@ public function testWriteInsert(): void /** * @return void * @throws DatabaseException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws RuntimeException + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws \PDOException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException */ public function testWriteUpdate(): void @@ -140,16 +141,16 @@ public function testWriteUpdate(): void $newData = $this->getFaker()->text . '213'; $this->handler->write($sessionId, $newData); $data = $this->findSessionData($sessionId); - $this->assertIsArray($data); + $this->assertNotNull($data); $this->assertEquals($sessionId, $data['sessionId']); $this->assertEquals($newData, $data['sessionData']); } /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws \PDOException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Throwable */ public function testGc(): void @@ -168,7 +169,7 @@ public function testGc(): void /** * @return int * @throws AssertionFailedError - * @throws RuntimeException + * @throws \RuntimeException */ protected function countSessionData(): int { @@ -189,9 +190,9 @@ protected function countSessionData(): int /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws \PDOException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Throwable */ public function testValidateIdSuccess(): void @@ -205,9 +206,9 @@ public function testValidateIdSuccess(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws \PDOException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Throwable */ public function testValidateIdFailsSessionExpired(): void @@ -221,8 +222,8 @@ public function testValidateIdFailsSessionExpired(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Throwable */ public function testValidateIdFailsSessionDoesNotExist(): void @@ -233,8 +234,8 @@ public function testValidateIdFailsSessionDoesNotExist(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Psr\Log\InvalidArgumentException */ public function testOpen(): void @@ -244,9 +245,9 @@ public function testOpen(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws \PDOException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Throwable */ public function testReadSuccess(): void @@ -260,9 +261,9 @@ public function testReadSuccess(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws \PDOException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Throwable */ public function testReadFailedSessionExpired(): void @@ -276,8 +277,8 @@ public function testReadFailedSessionExpired(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws \Throwable */ public function testReadFailedSessionNotExists(): void @@ -288,11 +289,10 @@ public function testReadFailedSessionNotExists(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws RuntimeException + * @throws \InvalidArgumentException * @throws \InvalidArgumentException * @throws \PDOException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testUpdateTimestamp(): void { @@ -309,9 +309,8 @@ public function testUpdateTimestamp(): void /** * @return void * @throws DatabaseException - * @throws SessionException * @throws \PDOException - * @throws \RuntimeException + * @throws SessionException */ protected function setUp(): void { @@ -328,8 +327,8 @@ protected function setUp(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ protected function tearDown(): void { diff --git a/tests/src/Subscriber/FeaturesSubscriberTest.php b/tests/src/Subscriber/FeaturesSubscriberTest.php index 7f40dcbf..90ff8ed8 100755 --- a/tests/src/Subscriber/FeaturesSubscriberTest.php +++ b/tests/src/Subscriber/FeaturesSubscriberTest.php @@ -15,15 +15,14 @@ use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class FeaturesSubscriberTest extends TestCase { /** * @return void * @throws FeaturesException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSetNeedsFinishCallActive(): void { @@ -38,8 +37,8 @@ public function testSetNeedsFinishCallActive(): void /** * @return void * @throws FeaturesException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSetNeedsFinishCallActiveOverrideInactive(): void { @@ -56,8 +55,8 @@ public function testSetNeedsFinishCallActiveOverrideInactive(): void * @throws CaseConverterException * @throws DefinitionException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetSubscribedEvents(): void { diff --git a/tests/src/Subscriber/RequestParamsTransformSubscriberTest.php b/tests/src/Subscriber/RequestParamsTransformSubscriberTest.php index 3a2a1158..554055a6 100755 --- a/tests/src/Subscriber/RequestParamsTransformSubscriberTest.php +++ b/tests/src/Subscriber/RequestParamsTransformSubscriberTest.php @@ -7,6 +7,7 @@ use InvalidArgumentException; use Jtl\Connector\Core\Event\RpcEvent; use Jtl\Connector\Core\Subscriber\RequestParamsTransformSubscriber; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\MethodCannotBeConfiguredException; @@ -18,20 +19,19 @@ class RequestParamsTransformSubscriberTest extends TestCase { /** - * @dataProvider transformRequestParamsProvider - * * @param RpcEvent $event * * @return void - * @throws InvalidArgumentException * @throws Exception - * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws \InvalidArgumentException * @throws MethodCannotBeConfiguredException * @throws MethodNameAlreadyConfiguredException * @throws MethodNameNotConfiguredException * @throws MethodParametersAlreadyConfiguredException + * @throws \PHPUnit\Framework\InvalidArgumentException * @throws \RuntimeException */ + #[DataProvider('transformRequestParamsProvider')] public function testTransformRequestParams(RpcEvent $event): void { $subscriber = $this->createPartialMock( @@ -66,16 +66,15 @@ public function testTransformRequestParams(RpcEvent $event): void } /** - * @dataProvider transformProductProvider - * * @param array> $products * @param array> $expectedResult * * @return void + * @throws \PHPUnit\Framework\ExpectationFailedException + * \Exception * @throws \RuntimeException - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException */ + #[DataProvider('transformProductProvider')] public function testTransformProductData(array $products, array $expectedResult): void { $subscriber = new RequestParamsTransformSubscriber(); @@ -84,16 +83,15 @@ public function testTransformProductData(array $products, array $expectedResult) } /** - * @dataProvider transformProductPriceProvider - * * @param array> $productPrices * @param array $expectedResult * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \InvalidArgumentException + * \Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('transformProductPriceProvider')] public function testTransformProductPriceData(array $productPrices, array $expectedResult): void { $subscriber = new RequestParamsTransformSubscriber(); @@ -102,15 +100,14 @@ public function testTransformProductPriceData(array $productPrices, array $expec } /** - * @dataProvider transformProductStockLevelProvider - * * @param array $productStock * @param array $expectedResult * * @return void - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException + * \Exception */ + #[DataProvider('transformProductStockLevelProvider')] public function testTransformStockLevelData(array $productStock, array $expectedResult): void { $subscriber = new RequestParamsTransformSubscriber(); @@ -120,8 +117,8 @@ public function testTransformStockLevelData(array $productStock, array $expected /** * @return void - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException|\Exception + * @throws \Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetSubscribedEvents(): void { @@ -135,7 +132,7 @@ public function testGetSubscribedEvents(): void /** * @return array */ - public function transformRequestParamsProvider(): array + public static function transformRequestParamsProvider(): array { return [ [new RpcEvent(['foo', 'bar'], 'Product', 'push')], @@ -152,7 +149,7 @@ public function transformRequestParamsProvider(): array /** * @return array|float|int>>>|float>|float|string>>>> */ - public function transformProductProvider(): array + public static function transformProductProvider(): array { //phpcs:enable return [ @@ -243,7 +240,7 @@ public function transformProductProvider(): array /** * @return array|float|int>|int|string>|float|int|string>|int|string>|float|string>>>> */ - public function transformProductPriceProvider(): array + public static function transformProductPriceProvider(): array { //phpcs:enable return [ @@ -495,7 +492,7 @@ public function transformProductPriceProvider(): array /** * @return array|float|string>>>> */ - public function transformProductStockLevelProvider(): array + public static function transformProductStockLevelProvider(): array { return [ [ diff --git a/tests/src/Subscriber/SyncErrorSubscriberTest.php b/tests/src/Subscriber/SyncErrorSubscriberTest.php index 8c067cb2..f4cce978 100644 --- a/tests/src/Subscriber/SyncErrorSubscriberTest.php +++ b/tests/src/Subscriber/SyncErrorSubscriberTest.php @@ -55,7 +55,7 @@ public function testAfterFinishDoesNothingWhenNoErrors(): void // Should not throw $this->subscriber->afterFinish($event); - $this->assertTrue(true); + $this->assertFalse($this->collector->hasErrors()); } /** diff --git a/tests/src/TestCase.php b/tests/src/TestCase.php index fe3d9487..aff8532f 100755 --- a/tests/src/TestCase.php +++ b/tests/src/TestCase.php @@ -14,7 +14,6 @@ use org\bovigo\vfs\vfsStreamDirectory; use org\bovigo\vfs\vfsStreamException; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; /** * Class TestCase @@ -30,8 +29,7 @@ class TestCase extends \Jtl\Connector\MappingTables\TestCase /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ protected function tearDown(): void { @@ -61,8 +59,7 @@ protected function tearDown(): void * @param string $dirname * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ protected function removeDirRecursive(string $dirname): void { @@ -107,7 +104,7 @@ protected function createHostId(): int * @return array> * @throws \ReflectionException */ - protected function getCorrectConstantsTestCases(string $className): array + protected static function getCorrectConstantsTestCases(string $className): array { $reflection = new \ReflectionClass($className); $constants = \array_values($reflection->getConstants()); diff --git a/tests/src/Utilities/StrTest.php b/tests/src/Utilities/StrTest.php index 3c38b9b3..802f5a36 100755 --- a/tests/src/Utilities/StrTest.php +++ b/tests/src/Utilities/StrTest.php @@ -5,6 +5,7 @@ namespace Jtl\Connector\Core\Test\Utilities; use Jtl\Connector\Core\Utilities\Str; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; /** @@ -15,14 +16,13 @@ class StrTest extends TestCase { /** - * @dataProvider toCamelCaseDataProvider - * * @param string $data * @param string $expectedResult * * @return void * @throws \Exception */ + #[DataProvider('toCamelCaseDataProvider')] public function testToCamelCase(string $data, string $expectedResult): void { $this->assertSame($expectedResult, Str::toCamelCase($data)); @@ -31,7 +31,7 @@ public function testToCamelCase(string $data, string $expectedResult): void /** * @return array */ - public function toCamelCaseDataProvider(): array + public static function toCamelCaseDataProvider(): array { return [ ['snake_case', 'snakeCase',], @@ -48,14 +48,13 @@ public function toCamelCaseDataProvider(): array } /** - * @dataProvider toPascalCaseDataProvider - * * @param string $data * @param string $expectedResult * * @return void * @throws \Exception */ + #[DataProvider('toPascalCaseDataProvider')] public function testPascalCase(string $data, string $expectedResult): void { $this->assertSame($expectedResult, Str::toPascalCase($data)); @@ -64,7 +63,7 @@ public function testPascalCase(string $data, string $expectedResult): void /** * @return array */ - public function toPascalCaseDataProvider(): array + public static function toPascalCaseDataProvider(): array { return [ ['snake_case', 'SnakeCase',], @@ -81,14 +80,13 @@ public function toPascalCaseDataProvider(): array } /** - * @dataProvider toSnakeCaseDataProvider - * * @param string $data * @param string $expectedResult * * @return void * @throws \Exception */ + #[DataProvider('toSnakeCaseDataProvider')] public function testSnakeCase(string $data, string $expectedResult): void { $this->assertSame($expectedResult, Str::toSnakeCase($data)); @@ -97,7 +95,7 @@ public function testSnakeCase(string $data, string $expectedResult): void /** * @return array */ - public function toSnakeCaseDataProvider(): array + public static function toSnakeCaseDataProvider(): array { return [ ['snake_case', 'snake_case',], diff --git a/tests/src/dbc/ConnectionTest.php b/tests/src/dbc/ConnectionTest.php index 623f8ba7..dff3563b 100644 --- a/tests/src/dbc/ConnectionTest.php +++ b/tests/src/dbc/ConnectionTest.php @@ -4,15 +4,11 @@ namespace Jtl\Connector\Dbc; -use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\SchemaException; use Jtl\Connector\Dbc\Query\QueryBuilder; use Jtl\Connector\Dbc\Schema\TableRestriction; -use Jtl\Connector\MappingTables\Validator; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use Throwable; class ConnectionTest extends TestCase @@ -21,16 +17,13 @@ class ConnectionTest extends TestCase /** * @return void - * @throws DBALException * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws SchemaException - * @throws \Doctrine\DBAL\Driver\Exception + * @throws \InvalidArgumentException * @throws \PDOException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws SchemaException */ public function testInsertWithTableRestriction(): void { @@ -47,33 +40,29 @@ public function testInsertWithTableRestriction(): void $this->assertEquals(3, $this->countRows($this->table->getTableName())); $qb = $this->connection->createQueryBuilder(); $stmt = $qb - ->select($this->table->getColumnNames()) + ->select(...$this->table->getColumnNames()) ->from($this->table->getTableName()) ->where(TableStub::A . ' = :a') - ->setParameter('a', 25)->execute(); + ->setParameter('a', 25)->executeQuery(); - $result = Validator::returnResult($stmt, 'stmt')->fetchAll(); + $result = $stmt->fetchAllAssociative(); $this->assertCount(1, $result); $this->assertArrayHasKey(0, $result); $row = $result[0]; - $this->assertIsArray($row); $this->assertArrayHasKey(TableStub::B, $row); $this->assertEquals('b string', $row[TableStub::B]); } /** * @return void - * @throws DBALException * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws SchemaException - * @throws \Doctrine\DBAL\Driver\Exception + * @throws \InvalidArgumentException * @throws \PDOException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws SchemaException */ public function testUpdateWithTableRestriction(): void { @@ -91,33 +80,29 @@ public function testUpdateWithTableRestriction(): void $this->connection->update($this->table->getTableName(), $data, $identifier); $qb = $this->connection->createQueryBuilder(); $stmt = $qb - ->select($this->table->getColumnNames()) + ->select(...$this->table->getColumnNames()) ->from($this->table->getTableName()) ->where(TableStub::A . ' = :a') - ->setParameter('a', 25)->execute(); + ->setParameter('a', 25)->executeQuery(); - $result = Validator::returnResult($stmt, 'stmt')->fetchAll(); + $result = $stmt->fetchAllAssociative(); $this->assertCount(1, $result); $this->assertArrayHasKey(0, $result); $row = $result[0]; - $this->assertIsArray($row); $this->assertArrayHasKey(TableStub::B, $row); $this->assertEquals('b string', $row[TableStub::B]); } /** * @return void - * @throws DBALException * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws SchemaException - * @throws \Doctrine\DBAL\Driver\Exception + * @throws \InvalidArgumentException * @throws \PDOException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException - * @throws InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws SchemaException */ public function testDeleteWithTableRestriction(): void { @@ -129,26 +114,24 @@ public function testDeleteWithTableRestriction(): void $this->assertEquals(1, $this->countRows($this->table->getTableName())); $qb = $this->connection->createQueryBuilder(); $stmt = $qb - ->select($this->table->getColumnNames()) + ->select(...$this->table->getColumnNames()) ->from($this->table->getTableName()) - ->execute(); + ->executeQuery(); - $result = Validator::returnResult($stmt, 'stmt')->fetchAll(); + $result = $stmt->fetchAllAssociative(); $this->assertCount(0, $result); } /** * @return void - * @throws DBALException * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws SchemaException - * @throws \Doctrine\DBAL\Driver\Exception + * @throws \InvalidArgumentException * @throws \PDOException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws SchemaException */ public function testDeleteWithTableRestrictionAndAdditionalIdentifier(): void { @@ -162,11 +145,11 @@ public function testDeleteWithTableRestrictionAndAdditionalIdentifier(): void /** * @return void - * @throws DBALException - * @throws ExpectationFailedException - * @throws SchemaException * @throws DbcRuntimeException - * @throws InvalidArgumentException + * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws SchemaException */ public function testHasTableRestriction(): void { @@ -179,9 +162,9 @@ public function testHasTableRestriction(): void /** * @return void - * @throws DBALException - * @throws SchemaException + * @throws Exception * @throws \Exception + * @throws SchemaException */ public function testGetTableRestrictionsAll(): void { @@ -197,7 +180,6 @@ public function testGetTableRestrictionsAll(): void /** @var array> $restrictions */ $restrictions = $this->connection->getTableRestrictions(); $this->assertArrayHasKey($this->table->getTableName(), $restrictions); - $this->assertIsArray($restrictions[$this->table->getTableName()]); $this->assertArrayHasKey(TableStub::B, $restrictions[$this->table->getTableName()]); $this->assertEquals('b string', $restrictions[$this->table->getTableName()][TableStub::B]); @@ -208,9 +190,9 @@ public function testGetTableRestrictionsAll(): void /** * @return void - * @throws DBALException - * @throws SchemaException + * @throws Exception * @throws \Exception + * @throws SchemaException */ public function testGetTableRestrictionsFromTable(): void { @@ -230,9 +212,9 @@ public function testGetTableRestrictionsFromTable(): void /** * @return void + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws InvalidArgumentException - * @throws ExpectationFailedException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCreateQueryBuilder(): void { @@ -241,14 +223,11 @@ public function testCreateQueryBuilder(): void /** * @return void - * @throws DBALException * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws \Doctrine\DBAL\Driver\Exception + * @throws \InvalidArgumentException * @throws \PDOException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testInsert(): void { @@ -263,14 +242,11 @@ public function testInsert(): void /** * @return void - * @throws DBALException * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws \Doctrine\DBAL\Driver\Exception + * @throws \InvalidArgumentException * @throws \PDOException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testMultiInsert(): void { @@ -313,10 +289,9 @@ public function testMultiInsertThrowsException(): void * @return void * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testUpdateRow(): void { @@ -331,17 +306,16 @@ public function testUpdateRow(): void $this->assertEquals(1, $this->connection->update($this->table->getTableName(), $data, $identifier)); $stmt = $this->connection->createQueryBuilder() - ->select($this->table->getColumnNames()) + ->select(...$this->table->getColumnNames()) ->from($this->table->getTableName()) ->where(TableStub::ID . ' = :id') ->setParameter('id', 1) - ->execute(); + ->executeQuery(); - $result = Validator::returnResult($stmt, 'stmt')->fetchAll(); + $result = $stmt->fetchAllAssociative(); $this->assertCount(1, $result); $row = $result[0]; - $this->assertIsArray($row); $this->assertArrayHasKey(TableStub::ID, $row); $this->assertArrayHasKey(TableStub::A, $row); $this->assertArrayHasKey(TableStub::B, $row); @@ -354,15 +328,12 @@ public function testUpdateRow(): void /** * @return void - * @throws DBALException * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws \Doctrine\DBAL\Driver\Exception + * @throws \InvalidArgumentException * @throws \PDOException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testDeleteRow(): void { @@ -370,13 +341,13 @@ public function testDeleteRow(): void $this->assertEquals(1, $this->connection->delete($this->table->getTableName(), $identifier)); $stmt = $this->connection->createQueryBuilder() - ->select($this->table->getColumnNames()) + ->select(...$this->table->getColumnNames()) ->from($this->table->getTableName()) ->where(TableStub::ID . ' = :id') ->setParameter('id', 3) - ->execute(); + ->executeQuery(); - $result = Validator::returnResult($stmt, 'stmt')->fetchAll(); + $result = $stmt->fetchAllAssociative(); $this->assertCount(0, $result); $this->assertEquals(1, $this->countRows($this->table->getTableName())); @@ -385,7 +356,6 @@ public function testDeleteRow(): void /** * @return void * @throws Exception - * @throws DBALException * @throws \Exception * @throws Throwable */ @@ -394,13 +364,6 @@ protected function setUp(): void $this->table = new TableStub($this->getDBManager()); parent::setUp(); $this->insertFixtures($this->table, self::getTableStubFixtures()); - $params = [ - 'pdo' => $this->getPDO(), - 'wrapperClass' => Connection::class - ]; - $config = null; - /** @var Connection $connection */ - $connection = DriverManager::getConnection($params, $config); - $this->connection = $connection; + $this->connection = $this->getDBManager()->getConnection(); } } diff --git a/tests/src/dbc/CoordinatesStub.php b/tests/src/dbc/CoordinatesStub.php index b2f9e970..2b4e977a 100755 --- a/tests/src/dbc/CoordinatesStub.php +++ b/tests/src/dbc/CoordinatesStub.php @@ -5,10 +5,10 @@ namespace Jtl\Connector\Dbc; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\ForwardCompatibility\Result; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class CoordinatesStub extends AbstractTable { @@ -40,7 +40,7 @@ public function getName(): string public function addCoordinate(float $x, float $y, float $z): bool { $data = [self::COL_X => $x, self::COL_Y => $y, self::COL_Z => $z]; - $types = [self::COL_X => Type::FLOAT, self::COL_Y => Type::FLOAT, self::COL_Z => Type::FLOAT]; + $types = [self::COL_X => Types::FLOAT, self::COL_Y => Types::FLOAT, self::COL_Z => Types::FLOAT]; return $this->getConnection() ->insert($this->getTableName(), $data, $types) > 0; @@ -48,8 +48,8 @@ public function addCoordinate(float $x, float $y, float $z): bool /** * @return array|array{empty} - * @throws Exception * @throws DbcRuntimeException + * @throws Exception */ public function findAll(): array { @@ -60,8 +60,8 @@ public function findAll(): array * @param array $parameters * * @return array|array{empty} - * @throws Exception * @throws DbcRuntimeException + * @throws Exception */ protected function findBy(array $parameters = []): array { @@ -73,13 +73,10 @@ protected function findBy(array $parameters = []): array $qb->where($column . ' = :' . $column)->setParameter($column, $value); } - $result = $qb->execute(); + $result = $qb->executeQuery(); - if ($result instanceof Result === false) { - throw new DbcRuntimeException('$result must be type ' . Result::class); - } /** @var array|array{empty} $return */ - $return = $result->fetchAll(); + $return = $result->fetchAllAssociative(); return $return; } @@ -88,8 +85,8 @@ protected function findBy(array $parameters = []): array * @param float $x * * @return array|array{empty} - * @throws Exception * @throws DbcRuntimeException + * @throws Exception */ public function findByX(float $x): array { @@ -100,8 +97,8 @@ public function findByX(float $x): array * @param float $y * * @return array|array{empty} - * @throws Exception * @throws DbcRuntimeException + * @throws Exception */ public function findByY(float $y): array { @@ -112,8 +109,8 @@ public function findByY(float $y): array * @param float $z * * @return array|array{empty} - * @throws Exception * @throws DbcRuntimeException + * @throws Exception */ public function findByZ(float $z): array { @@ -129,9 +126,9 @@ public function findByZ(float $z): array */ protected function createTableSchema(Table $tableSchema): void { - $tableSchema->addColumn(self::COL_X, Type::FLOAT, ['default' => 0.0]); - $tableSchema->addColumn(self::COL_Y, Type::FLOAT, ['default' => 0.0]); - $tableSchema->addColumn(self::COL_Z, Type::FLOAT, ['default' => 0.0]); + $tableSchema->addColumn(self::COL_X, Types::FLOAT, ['default' => '0']); + $tableSchema->addColumn(self::COL_Y, Types::FLOAT, ['default' => '0']); + $tableSchema->addColumn(self::COL_Z, Types::FLOAT, ['default' => '0']); $tableSchema->setPrimaryKey([self::COL_X, self::COL_Y, self::COL_Z]); } } diff --git a/tests/src/dbc/DbManagerStub.php b/tests/src/dbc/DbManagerStub.php index 786e465b..51ec8b6b 100755 --- a/tests/src/dbc/DbManagerStub.php +++ b/tests/src/dbc/DbManagerStub.php @@ -4,27 +4,27 @@ namespace Jtl\Connector\Dbc; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use RuntimeException; class DbManagerStub extends DbManager { /** - * @return array + * @return array */ public function getTables(): array { - return parent::getTables(); + return \array_values(parent::getTables()); } /** - * @return array - * @throws DBALException + * @return array<\Doctrine\DBAL\Schema\Table> * @throws DbcRuntimeException * @throws DbcRuntimeException + * @throws Exception */ public function getSchemaTables(): array { - return parent::getSchemaTables(); + return \array_values(parent::getSchemaTables()); } } diff --git a/tests/src/dbc/DbManagerTest.php b/tests/src/dbc/DbManagerTest.php index 00dd7f40..5cadb6a1 100644 --- a/tests/src/dbc/DbManagerTest.php +++ b/tests/src/dbc/DbManagerTest.php @@ -4,21 +4,21 @@ namespace Jtl\Connector\Dbc; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception as DbalException; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; use Exception; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use RuntimeException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use Throwable; class DbManagerTest extends TestCase { /** * @return void - * @throws DBALException + * @throws DbalException * @throws Exception */ public function testRegisterTable(): void @@ -34,7 +34,7 @@ public function testRegisterTable(): void /** * @return void - * @throws DBALException + * @throws DbalException * @throws Exception */ public function testTablesPrefix(): void @@ -52,7 +52,7 @@ public function testTablesPrefix(): void /** * @return void - * @throws DBALException + * @throws DbalException * @throws Exception */ public function testHasSchemaUpdates(): void @@ -66,7 +66,7 @@ public function testHasSchemaUpdates(): void /** * @return void - * @throws DBALException + * @throws DbalException * @throws Exception */ public function testGetSchemaUpdates(): void @@ -79,8 +79,8 @@ public function testGetSchemaUpdates(): void /** * @return void + * @throws DbalException * @throws Throwable - * @throws DBALException */ public function testUpdateDatabaseSchema(): void { @@ -92,27 +92,27 @@ public function testUpdateDatabaseSchema(): void /** * @return void - * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws DbalException + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCreateFromParams(): void { - $dbm = DbManager::createFromParams(['url' => 'sqlite:///:memory:']); + $dbm = DbManager::createFromParams(['driver' => 'pdo_sqlite', 'memory' => true]); $this->assertInstanceOf(DbManager::class, $dbm); } /** * @return void - * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws DbalException * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCreateSchemaAssetsFilterCallback(): void { - $dbm = DbManager::createFromParams(['url' => 'sqlite:///:memory:']); + $dbm = DbManager::createFromParams(['driver' => 'pdo_sqlite', 'memory' => true]); $callback = $dbm->createSchemaAssetsFilterCallback(); $tables = $this->createTableStubs($dbm); @@ -184,42 +184,42 @@ protected function createTableSchema(Table $tableSchema): void } /** - * @dataProvider tableNameProvider - * * @param string $shortName * @param string|null $tablesPrefix * @param string $expectedTableName * * @return void - * @throws DBALException + * @throws DbalException * @throws DbcRuntimeException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('tableNameProvider')] public function testCreateTableName(string $shortName, ?string $tablesPrefix, string $expectedTableName): void { - $dbm = DbManager::createFromParams(['url' => 'sqlite:///:memory:'], null, $tablesPrefix); + $params = ['driver' => 'pdo_sqlite', 'memory' => true]; + $dbm = DbManager::createFromParams($params, null, $tablesPrefix); $actualTableName = $dbm->createTableName($shortName); $this->assertEquals($expectedTableName, $actualTableName); } /** * @return void - * @throws DBALException + * @throws DbalException * @throws DbcRuntimeException */ public function testCreateTableNameEmptyString(): void { $this->expectException(DbcRuntimeException::class); $this->expectExceptionCode(DbcRuntimeException::TABLE_NAME_EMPTY); - $dbm = DbManager::createFromParams(['url' => 'sqlite:///:memory:'], null, 'foo'); + $dbm = DbManager::createFromParams(['driver' => 'pdo_sqlite', 'memory' => true], null, 'foo'); $dbm->createTableName(''); } /** * @return array */ - public function tableNameProvider(): array + public static function tableNameProvider(): array { return [ ['foo', null, 'foo'], @@ -229,7 +229,7 @@ public function tableNameProvider(): array /** * @return void - * @throws DBALException + * @throws DbalException * @throws Exception * @throws Throwable */ diff --git a/tests/src/dbc/Mapping/TableTest.php b/tests/src/dbc/Mapping/TableTest.php index d1cd9dbb..34db81aa 100644 --- a/tests/src/dbc/Mapping/TableTest.php +++ b/tests/src/dbc/Mapping/TableTest.php @@ -4,12 +4,10 @@ namespace Jtl\Connector\Dbc\Mapping; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\InvalidArgumentException; -use Doctrine\DBAL\ForwardCompatibility\Result; use Doctrine\DBAL\Schema\SchemaException; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Jtl\Connector\Dbc\CoordinatesStub; use Jtl\Connector\Dbc\DbcRuntimeException; use Jtl\Connector\Dbc\TableStub; @@ -25,8 +23,8 @@ class TableTest extends TestCase /** * @return void - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ExpectationFailedException + * \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetName(): void { @@ -35,9 +33,8 @@ public function testGetName(): void /** * @return void - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws \RuntimeException - * @throws ExpectationFailedException + * \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetTableName(): void { @@ -46,9 +43,9 @@ public function testGetTableName(): void /** * @return void - * @throws SchemaException - * @throws DBALException + * @throws Exception * @throws \Exception + * @throws SchemaException */ public function testRestrict(): void { @@ -68,36 +65,34 @@ public function testRestrict(): void /** * @return void - * @throws DBALException - * @throws ExpectationFailedException * @throws DbcRuntimeException - * @throws SchemaException + * @throws Exception * @throws \PHPUnit\Framework\Exception - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws \RuntimeException + * \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws SchemaException */ public function testGetTableSchema(): void { $table = $this->coords->getTableSchema(); $columns = $table->getColumns(); $this->assertCount(3, $columns); - $this->assertArrayHasKey(CoordinatesStub::COL_X, $columns); - $this->assertEquals(CoordinatesStub::COL_X, $columns[CoordinatesStub::COL_X]->getName()); - $this->assertArrayHasKey(CoordinatesStub::COL_Y, $columns); - $this->assertEquals(CoordinatesStub::COL_Y, $columns[CoordinatesStub::COL_Y]->getName()); - $this->assertArrayHasKey(CoordinatesStub::COL_Z, $columns); - $this->assertEquals(CoordinatesStub::COL_Z, $columns[CoordinatesStub::COL_Z]->getName()); + $this->assertTrue($table->hasColumn(CoordinatesStub::COL_X)); + $this->assertEquals(CoordinatesStub::COL_X, $table->getColumn(CoordinatesStub::COL_X)->getName()); + $this->assertTrue($table->hasColumn(CoordinatesStub::COL_Y)); + $this->assertEquals(CoordinatesStub::COL_Y, $table->getColumn(CoordinatesStub::COL_Y)->getName()); + $this->assertTrue($table->hasColumn(CoordinatesStub::COL_Z)); + $this->assertEquals(CoordinatesStub::COL_Z, $table->getColumn(CoordinatesStub::COL_Z)->getName()); } /** * @return void - * @throws DBALException - * @throws ExpectationFailedException * @throws DbcRuntimeException - * @throws SchemaException + * @throws Exception * @throws \PHPUnit\Framework\Exception - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws \RuntimeException + * \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws SchemaException */ public function testGetColumnTypes(): void { @@ -106,19 +101,18 @@ public function testGetColumnTypes(): void $this->assertArrayHasKey(CoordinatesStub::COL_X, $columns); $this->assertArrayHasKey(CoordinatesStub::COL_Y, $columns); $this->assertArrayHasKey(CoordinatesStub::COL_Z, $columns); - $this->assertEquals(Type::FLOAT, $columns[CoordinatesStub::COL_X]); - $this->assertEquals(Type::FLOAT, $columns[CoordinatesStub::COL_Y]); - $this->assertEquals(Type::FLOAT, $columns[CoordinatesStub::COL_Y]); + $this->assertEquals(Types::FLOAT, $columns[CoordinatesStub::COL_X]); + $this->assertEquals(Types::FLOAT, $columns[CoordinatesStub::COL_Y]); + $this->assertEquals(Types::FLOAT, $columns[CoordinatesStub::COL_Y]); } /** * @return void - * @throws DBALException - * @throws ExpectationFailedException * @throws DbcRuntimeException + * @throws Exception * @throws \PHPUnit\Framework\Exception - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws \RuntimeException + * \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetColumnNames(): void { @@ -136,21 +130,19 @@ public function testGetColumnNames(): void * @return void * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws ReflectionException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testConvertToPhpValuesAssoc(): void { $connection = $this->table->getDbManager()->getConnection(); $result = $connection->createQueryBuilder() - ->select($this->table->getColumnNames()) + ->select(...$this->table->getColumnNames()) ->from($this->table->getTableName()) - ->execute(); + ->executeQuery(); - $rows = Validator::returnResult($result, 'result')->fetchAll(); + $rows = $result->fetchAllAssociative(); $this->assertCount(2, $rows); $mappedRow = $this->invokeMethodFromObject($this->table, 'convertToPhpValues', $rows[1]); @@ -170,25 +162,23 @@ public function testConvertToPhpValuesAssoc(): void /** * @return void - * @throws Exception - * @throws ExpectationFailedException - * @throws ReflectionException * @throws DbcRuntimeException + * @throws Exception * @throws \PHPUnit\Framework\Exception - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws \RuntimeException + * \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testConvertToPhpValuesPartiallyAssoc(): void { $connection = $this->table->getDbManager()->getConnection(); $result = $connection->createQueryBuilder() - ->select(['a', 'c']) + ->select('a', 'c') ->from($this->table->getTableName()) - ->execute(); - $rows = Validator::returnResult($result, 'result')->fetchAll(); + ->executeQuery(); + $rows = $result->fetchAllAssociative(); $this->assertCount(2, $rows); - /** @var array $mappedRow */ + /** @var array $mappedRow */ $mappedRow = $this->invokeMethodFromObject($this->table, 'convertToPhpValues', $rows[1]); $this->assertCount(2, $mappedRow); $this->assertArrayHasKey(TableStub::A, $mappedRow); @@ -200,25 +190,23 @@ public function testConvertToPhpValuesPartiallyAssoc(): void /** * @return void - * @throws DBALException - * @throws Exception - * @throws ExpectationFailedException - * @throws ReflectionException * @throws DbcRuntimeException + * @throws Exception + * @throws Exception * @throws \PHPUnit\Framework\Exception - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException|\RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testConvertToPhpValuesNumeric(): void { $connection = $this->table->getDbManager()->getConnection(); $result = $connection->createQueryBuilder() - ->select($this->table->getColumnNames()) + ->select(...$this->table->getColumnNames()) ->from($this->table->getTableName()) - ->execute(); - $rows = Validator::returnResult($result, 'result')->fetchAll(\PDO::FETCH_NUM); + ->executeQuery(); + $rows = $result->fetchAllNumeric(); $this->assertCount(2, $rows); - /** @var array $mappedRow */ + /** @var array $mappedRow */ $mappedRow = $this->invokeMethodFromObject($this->table, 'convertToPhpValues', $rows[1]); $this->assertArrayHasKey(0, $mappedRow); $this->assertIsInt($mappedRow[0]); @@ -235,13 +223,11 @@ public function testConvertToPhpValuesNumeric(): void /** * @return void - * @throws Exception - * @throws ReflectionException * @throws DbcRuntimeException + * @throws Exception * @throws \PHPUnit\Framework\Exception - * @throws ExpectationFailedException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException + * \RuntimeException */ public function testConvertToPhpValuesPartiallyNumericFails(): void { @@ -250,11 +236,11 @@ public function testConvertToPhpValuesPartiallyNumericFails(): void $connection = $this->table->getDbManager()->getConnection(); $result = $connection->createQueryBuilder() - ->select(['a', 'c']) + ->select('a', 'c') ->from($this->table->getTableName()) - ->execute(); + ->executeQuery(); - $rows = Validator::returnResult($result, 'result')->fetchAll(\PDO::FETCH_NUM); + $rows = $result->fetchAllNumeric(); $this->assertCount(2, $rows); $this->invokeMethodFromObject($this->table, 'convertToPhpValues', $rows[1]); @@ -262,7 +248,7 @@ public function testConvertToPhpValuesPartiallyNumericFails(): void /** * @return void - * @throws DBALException + * @throws Exception * @throws \Exception */ public function testInsertWithTableColumnTypes(): void @@ -276,7 +262,6 @@ public function testInsertWithTableColumnTypes(): void $this->assertCount(1, $rows); $data = \reset($rows); $this->assertIsNotBool($data); - $this->assertIsArray($data); $this->assertArrayHasKey('c', $data); $this->assertInstanceOf(\DateTimeImmutable::class, $data['c']); $this->assertEquals($c, $data['c']); @@ -284,7 +269,7 @@ public function testInsertWithTableColumnTypes(): void /** * @return void - * @throws DBALException + * @throws Exception * @throws \Exception */ public function testInsertWithoutTypes(): void @@ -298,14 +283,13 @@ public function testInsertWithoutTypes(): void $this->assertCount(1, $rows); $data = \reset($rows); $this->assertIsNotBool($data); - $this->assertIsArray($data); $this->assertArrayHasKey('c', $data); $this->assertEquals($c, $data['c']); } /** * @return void - * @throws DBALException + * @throws Exception * @throws \Exception * @throws \Exception */ @@ -324,7 +308,7 @@ public function testUpdateWithTableColumnTypes(): void /** * @return void - * @throws DBALException + * @throws Exception * @throws \Exception * @throws \Exception */ @@ -343,9 +327,9 @@ public function testUpdateWithoutTypes(): void /** * @return void - * @throws InvalidArgumentException - * @throws DBALException + * @throws Exception * @throws \Exception + * @throws \InvalidArgumentException */ public function testDeleteWithTableColumnTypes(): void { @@ -360,9 +344,9 @@ public function testDeleteWithTableColumnTypes(): void /** * @return void - * @throws InvalidArgumentException - * @throws DBALException + * @throws Exception * @throws \Exception + * @throws \InvalidArgumentException */ public function testDeleteWithoutTypes(): void { @@ -377,10 +361,10 @@ public function testDeleteWithoutTypes(): void /** * @return void - * @throws DBALException - * @throws Throwable + * @throws Exception * @throws \Exception * @throws \Exception + * @throws Throwable */ protected function setUp(): void { diff --git a/tests/src/dbc/Query/QueryBuilderTest.php b/tests/src/dbc/Query/QueryBuilderTest.php index fafa9e06..4f14eb8c 100644 --- a/tests/src/dbc/Query/QueryBuilderTest.php +++ b/tests/src/dbc/Query/QueryBuilderTest.php @@ -4,16 +4,13 @@ namespace Jtl\Connector\Dbc\Query; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\Query\QueryException; use Doctrine\DBAL\Schema\SchemaException; use Jtl\Connector\Dbc\CoordinatesStub; use Jtl\Connector\Dbc\DbcRuntimeException; use Jtl\Connector\Dbc\Schema\TableRestriction; use Jtl\Connector\Dbc\TestCase; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use Throwable; class QueryBuilderTest extends TestCase @@ -29,10 +26,10 @@ class QueryBuilderTest extends TestCase /** * @return void - * @throws QueryException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws Exception + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testTableRestrictionWithSelect(): void { @@ -50,10 +47,10 @@ public function testTableRestrictionWithSelect(): void /** * @return void - * @throws QueryException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws Exception + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testTableRestrictionWithInsert(): void { @@ -70,10 +67,10 @@ public function testTableRestrictionWithInsert(): void /** * @return void - * @throws QueryException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws Exception + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGlobalIdentifierWithUpdate(): void { @@ -105,10 +102,10 @@ public function testGlobalIdentifierWithUpdate(): void /** * @return void - * @throws QueryException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws Exception + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGlobalIdentifierWithDelete(): void { @@ -121,13 +118,12 @@ public function testGlobalIdentifierWithDelete(): void /** * @return void - * @throws DBALException + * @throws DbcRuntimeException + * @throws Exception * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws SchemaException - * @throws DbcRuntimeException - * @throws \RuntimeException|\Doctrine\DBAL\Driver\Exception */ public function testTableRestriction(): void { @@ -149,7 +145,7 @@ public function testTableRestriction(): void $qb->update($this->coordsTable->getTableName()) ->set('z', ':z') ->setParameter('z', 10.5) - ->execute(); + ->executeStatement(); $datasets = $this->coordsTable->findAll(); $this->assertEquals(10.5, $datasets[0]['z']); //@phpstan-ignore-line @@ -158,11 +154,10 @@ public function testTableRestriction(): void /** * @return void - * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws QueryException - * @throws \RuntimeException + * @throws Exception + * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSelectWithLockedFromTableAndCalledFromMethod(): void { @@ -176,11 +171,10 @@ public function testSelectWithLockedFromTableAndCalledFromMethod(): void /** * @return void - * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws QueryException - * @throws \RuntimeException + * @throws Exception + * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSelectWithLockedFromTableAndFromAliasAndNotCalledFromMethod(): void { @@ -195,11 +189,10 @@ public function testSelectWithLockedFromTableAndFromAliasAndNotCalledFromMethod( /** * @return void - * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws QueryException - * @throws \RuntimeException + * @throws Exception + * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testInsertWithLockedFromTableAndTableNameInInsert(): void { @@ -213,29 +206,27 @@ public function testInsertWithLockedFromTableAndTableNameInInsert(): void /** * @return void - * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws QueryException - * @throws \RuntimeException + * @throws Exception + * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testInsertWithLockedFromTableAndNotTableNameInInsert(): void { $fromTable = 'tableau'; $connection = $this->getDBManager()->getConnection(); $qb = new QueryBuilder($connection, [], $fromTable); - $actualSql = $qb->insert()->getSQL(); + $actualSql = $qb->insert($fromTable)->getSQL(); $expectedSql = 'INSERT INTO tableau () VALUES()'; $this->assertEquals($expectedSql, $actualSql); } /** * @return void - * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws QueryException - * @throws \RuntimeException + * @throws Exception + * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testUpdateWithLockedFromTableAndFromAliasAndTableNameInUpdate(): void { @@ -244,35 +235,33 @@ public function testUpdateWithLockedFromTableAndFromAliasAndTableNameInUpdate(): $connection = $this->getDBManager()->getConnection(); $qb = new QueryBuilder($connection, [], $fromTable, $fromAlias); $actualSql = $qb->update('foobar')->getSQL(); - $expectedSql = 'UPDATE tableau t SET '; + $expectedSql = 'UPDATE tableau SET '; $this->assertEquals($expectedSql, $actualSql); } /** * @return void - * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws QueryException - * @throws \RuntimeException + * @throws Exception + * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testUpdateWithLockedFromTableAndNotTableNameInUpdate(): void { $fromTable = 'tableau'; $connection = $this->getDBManager()->getConnection(); $qb = new QueryBuilder($connection, [], $fromTable); - $actualSql = $qb->update()->getSQL(); + $actualSql = $qb->update($fromTable)->getSQL(); $expectedSql = 'UPDATE tableau SET '; $this->assertEquals($expectedSql, $actualSql); } /** * @return void - * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws QueryException - * @throws \RuntimeException + * @throws Exception + * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testDeleteWithLockedFromTableAndTableNameInDelete(): void { @@ -286,11 +275,10 @@ public function testDeleteWithLockedFromTableAndTableNameInDelete(): void /** * @return void - * @throws DBALException - * @throws QueryException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws \RuntimeException + * @throws Exception + * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testDeleteWithLockedFromTableAndFromAliasAndTableNameNotInDelete(): void { @@ -298,8 +286,8 @@ public function testDeleteWithLockedFromTableAndFromAliasAndTableNameNotInDelete $fromAlias = 't'; $connection = $this->getDBManager()->getConnection(); $qb = new QueryBuilder($connection, [], $fromTable, $fromAlias); - $actualSql = $qb->delete()->getSQL(); - $expectedSql = 'DELETE FROM tableau t'; + $actualSql = $qb->delete($fromTable)->getSQL(); + $expectedSql = 'DELETE FROM tableau'; $this->assertEquals($expectedSql, $actualSql); } @@ -315,7 +303,7 @@ public function myTrim(string $str): string /** * @return void - * @throws DBALException + * @throws Exception * @throws \Exception * @throws Throwable */ diff --git a/tests/src/dbc/Schema/TableRestrictionTest.php b/tests/src/dbc/Schema/TableRestrictionTest.php index 205fd92e..bc6863d7 100644 --- a/tests/src/dbc/Schema/TableRestrictionTest.php +++ b/tests/src/dbc/Schema/TableRestrictionTest.php @@ -4,14 +4,13 @@ namespace Jtl\Connector\Dbc\Schema; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Schema\SchemaException; use Exception; use Jtl\Connector\Dbc\DbcRuntimeException; use Jtl\Connector\Dbc\TableStub; use Jtl\Connector\Dbc\TestCase; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use Throwable; class TableRestrictionTest extends TestCase @@ -19,11 +18,10 @@ class TableRestrictionTest extends TestCase /** * @return void * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws DbcRuntimeException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @throws SchemaException - * @throws \RuntimeException */ public function testInitializationSuccessful(): void { @@ -41,12 +39,10 @@ public function testInitializationSuccessful(): void * @throws DBALException * @throws DbcRuntimeException * @throws SchemaException - * @throws \RuntimeException */ public function testInitializationWithNotExistingColumn(): void { - $this->expectException(SchemaException::class); - $this->expectExceptionCode(SchemaException::COLUMN_DOESNT_EXIST); + $this->expectException(\Doctrine\DBAL\Schema\Exception\ColumnDoesNotExist::class); $tableSchema = $this->table->getTableSchema(); new TableRestriction($tableSchema, 'yolo', 'c'); } @@ -54,11 +50,10 @@ public function testInitializationWithNotExistingColumn(): void /** * @return void * @throws DBALException - * @throws SchemaException * @throws DbcRuntimeException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws \RuntimeException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws SchemaException */ public function testCreate(): void { @@ -74,8 +69,8 @@ public function testCreate(): void /** * @return void * @throws DBALException - * @throws Throwable * @throws Exception + * @throws Throwable */ protected function setUp(): void { diff --git a/tests/src/dbc/Session/SessionHandlerTest.php b/tests/src/dbc/Session/SessionHandlerTest.php index 02e5c21a..f4b30da0 100644 --- a/tests/src/dbc/Session/SessionHandlerTest.php +++ b/tests/src/dbc/Session/SessionHandlerTest.php @@ -4,32 +4,17 @@ namespace Jtl\Connector\Dbc\Session; -use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; -use Doctrine\DBAL\ForwardCompatibility\Result; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Exception; use Jtl\Connector\Dbc\Connection; use Jtl\Connector\Dbc\DbcRuntimeException; use Jtl\Connector\Dbc\DbManager; use Jtl\Connector\Dbc\TestCase; -use PHPUnit\Framework\ExpectationFailedException; -use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; -use PHPUnit\Framework\MockObject\ClassIsFinalException; -use PHPUnit\Framework\MockObject\ClassIsReadonlyException; -use PHPUnit\Framework\MockObject\DuplicateMethodException; -use PHPUnit\Framework\MockObject\IncompatibleReturnValueException; -use PHPUnit\Framework\MockObject\InvalidMethodNameException; -use PHPUnit\Framework\MockObject\MethodCannotBeConfiguredException; -use PHPUnit\Framework\MockObject\MethodNameAlreadyConfiguredException; -use PHPUnit\Framework\MockObject\MethodNameNotConfiguredException; -use PHPUnit\Framework\MockObject\MethodParametersAlreadyConfiguredException; +use PHPUnit\Framework\Attributes\RunInSeparateProcess; use PHPUnit\Framework\MockObject\MockObject; -use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; -use PHPUnit\Framework\MockObject\RuntimeException as MockRuntimeException; -use PHPUnit\Framework\MockObject\UnknownTypeException; use Random\RandomException; use ReflectionException; use Throwable; @@ -39,11 +24,10 @@ class SessionHandlerTest extends TestCase protected SessionHandler $handler; /** - * @runInSeparateProcess - * * @return void * @throws Exception */ + #[RunInSeparateProcess] public function testMaxLifetime(): void { $expected = '254'; @@ -58,11 +42,8 @@ public function testMaxLifetime(): void /** * @return void * @throws DBALException - * @throws ExpectationFailedException * @throws DbcRuntimeException - * @throws \Doctrine\DBAL\Driver\Exception - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testReadSessionSuccess(): void { @@ -83,12 +64,9 @@ public function testReadSessionSuccess(): void /** * @return void * @throws DBALException - * @throws ExpectationFailedException - * @throws DbcRuntimeException - * @throws \Doctrine\DBAL\Driver\Exception * @throws DBALException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws \RuntimeException + * @throws DbcRuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testReadSessionExpired(): void { @@ -109,12 +87,9 @@ public function testReadSessionExpired(): void /** * @return void - * @throws ExpectationFailedException - * @throws \Doctrine\DBAL\Driver\Exception * @throws DBALException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException * @throws DbcRuntimeException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testReadSessionDoesNotExist(): void { @@ -125,12 +100,9 @@ public function testReadSessionDoesNotExist(): void * @return void * @throws DBALException * @throws DbcRuntimeException - * @throws ExpectationFailedException - * @throws \Doctrine\DBAL\DBALException - * @throws \Doctrine\DBAL\Driver\Exception + * @throws \Doctrine\DBAL\Exception * @throws \PDOException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testWriteInsert(): void { @@ -146,11 +118,8 @@ public function testWriteInsert(): void * @return void * @throws DBALException * @throws DbcRuntimeException - * @throws ExpectationFailedException - * @throws \Doctrine\DBAL\DBALException - * @throws \Doctrine\DBAL\Driver\Exception - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \Doctrine\DBAL\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testWriteUpdate(): void { @@ -172,27 +141,11 @@ public function testWriteUpdate(): void /** * @return void - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws DBALException * @throws DbcRuntimeException - * @throws DuplicateMethodException - * @throws InvalidMethodNameException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws MethodNameNotConfiguredException - * @throws MethodParametersAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws UnknownTypeException - * @throws \Doctrine\DBAL\DBALException + * @throws \Doctrine\DBAL\Exception * @throws \PDOException * @throws \PHPUnit\Framework\Exception - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws MockRuntimeException - * @throws \RuntimeException */ public function testWriteInsertSimultaneouslySameSessionId(): void { @@ -201,7 +154,7 @@ public function testWriteInsertSimultaneouslySameSessionId(): void $handler = $this->getMockBuilder(SessionHandler::class) ->setConstructorArgs([$this->getDBManager()]) - ->setMethods(['insert', 'update']) + ->onlyMethods(['insert', 'update']) ->getMock(); $handler @@ -209,8 +162,8 @@ public function testWriteInsertSimultaneouslySameSessionId(): void ->method('insert') ->willThrowException( new UniqueConstraintViolationException( - 'Duplicate Key entry', - $this->createMock(DriverException::class) + $this->createMock(\Doctrine\DBAL\Driver\Exception::class), + null ) ); @@ -238,25 +191,10 @@ public function testWriteInsertSimultaneouslySameSessionId(): void /** * @return void - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException * @throws DBALException - * @throws DuplicateMethodException - * @throws ExpectationFailedException - * @throws IncompatibleReturnValueException - * @throws InvalidMethodNameException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws MockRuntimeException - * @throws OriginalConstructorInvocationRequiredException - * @throws UnknownTypeException - * @throws \Doctrine\DBAL\DBALException + * @throws \Doctrine\DBAL\Exception * @throws \PDOException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws \PHPUnit\Framework\MockObject\ReflectionException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testClose(): void { @@ -268,7 +206,7 @@ public function testClose(): void $handler = $this->getMockBuilder(SessionHandler::class) ->setConstructorArgs([$this->getDBManager()]) - ->setMethods(['getConnection']) + ->onlyMethods(['getConnection']) ->getMock(); $handler @@ -281,8 +219,7 @@ public function testClose(): void /** * @return void - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws ExpectationFailedException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testOpen(): void { @@ -293,13 +230,10 @@ public function testOpen(): void * @return void * @throws DBALException * @throws DbcRuntimeException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws \Doctrine\DBAL\DBALException - * @throws \Doctrine\DBAL\Driver\Exception + * @throws \Doctrine\DBAL\Exception + * @throws \InvalidArgumentException * @throws \PDOException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testDestroy(): void { @@ -323,12 +257,9 @@ public function testDestroy(): void * @return void * @throws DBALException * @throws DbcRuntimeException - * @throws ExpectationFailedException - * @throws \Doctrine\DBAL\DBALException - * @throws \Doctrine\DBAL\Driver\Exception + * @throws \Doctrine\DBAL\Exception * @throws \PDOException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @noinspection PhpDocMissingThrowsInspection - RandomException since 8.2, can't use in 8.1 */ public function testGc(): void @@ -357,12 +288,9 @@ public function testGc(): void /** * @return void * @throws DBALException - * @throws ExpectationFailedException - * @throws DbcRuntimeException - * @throws \Doctrine\DBAL\Driver\Exception * @throws DBALException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws \RuntimeException + * @throws DbcRuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testValidateIdSuccess(): void { @@ -383,12 +311,9 @@ public function testValidateIdSuccess(): void /** * @return void * @throws DBALException - * @throws ExpectationFailedException - * @throws DbcRuntimeException - * @throws \Doctrine\DBAL\Driver\Exception * @throws DBALException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException - * @throws \RuntimeException + * @throws DbcRuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testValidateIdSessionExpired(): void { @@ -408,12 +333,9 @@ public function testValidateIdSessionExpired(): void /** * @return void - * @throws ExpectationFailedException - * @throws \Doctrine\DBAL\Driver\Exception * @throws DBALException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException * @throws DbcRuntimeException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testValidateIdSessionDoesNotExist(): void { @@ -424,12 +346,9 @@ public function testValidateIdSessionDoesNotExist(): void * @return void * @throws DBALException * @throws DbcRuntimeException - * @throws ExpectationFailedException - * @throws ReflectionException - * @throws \Doctrine\DBAL\DBALException + * @throws \Doctrine\DBAL\Exception * @throws \PDOException - * @throws \RuntimeException - * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testUpdateTimestamp(): void { @@ -457,18 +376,14 @@ public function testUpdateTimestamp(): void ->from($this->handler->getTableName()) ->where(\sprintf('%s = :sessionId', SessionHandler::SESSION_ID)) ->setParameter('sessionId', $sessionId) - ->execute(); - - if ($stmt instanceof Result === false) { - throw new \RuntimeException('$stmt must be instance of ' . Result::class); - } + ->executeQuery(); /** @var \DateTimeImmutable $expiresAt */ - $expiresAt = Type::getType(Type::DATETIME_IMMUTABLE) - ->convertToPHPValue( - $stmt->fetchColumn(), - $this->getDBManager()->getConnection()->getDatabasePlatform() - ); + $expiresAt = \Doctrine\DBAL\Types\Type::getType(Types::DATETIME_IMMUTABLE) + ->convertToPHPValue( + $stmt->fetchOne(), + $this->getDBManager()->getConnection()->getDatabasePlatform() + ); $this->assertEquals($expectedExpiresAtTimestamp, $expiresAt->getTimestamp()); } diff --git a/tests/src/dbc/Table2Stub.php b/tests/src/dbc/Table2Stub.php index 3b4a0a35..22b0ba8c 100755 --- a/tests/src/dbc/Table2Stub.php +++ b/tests/src/dbc/Table2Stub.php @@ -7,7 +7,7 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class Table2Stub extends AbstractTable { @@ -32,8 +32,8 @@ public function getName(): string */ protected function createTableSchema(Table $tableSchema): void { - $tableSchema->addColumn(self::ID, Type::INTEGER, ['autoincrement' => true]); - $tableSchema->addColumn(self::A, Type::INTEGER, ['notnull' => false]); + $tableSchema->addColumn(self::ID, Types::INTEGER, ['autoincrement' => true]); + $tableSchema->addColumn(self::A, Types::INTEGER, ['notnull' => false]); $tableSchema->setPrimaryKey([self::ID]); } } diff --git a/tests/src/dbc/TableCollectionTest.php b/tests/src/dbc/TableCollectionTest.php index 866852ba..a34caf62 100644 --- a/tests/src/dbc/TableCollectionTest.php +++ b/tests/src/dbc/TableCollectionTest.php @@ -4,10 +4,9 @@ namespace Jtl\Connector\Dbc; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception as DBALException; use Exception; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use Throwable; class TableCollectionTest extends TestCase @@ -51,10 +50,10 @@ public function testRemoveByInstanceNotFound(): void /** * @return void - * @throws ExpectationFailedException * @throws DbcRuntimeException + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testRemoveByName(): void { @@ -65,9 +64,9 @@ public function testRemoveByName(): void /** * @return void - * @throws ExpectationFailedException + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testRemoveByNameNotFound(): void { @@ -78,9 +77,9 @@ public function testRemoveByNameNotFound(): void /** * @return void - * @throws InvalidArgumentException - * @throws ExpectationFailedException * @throws DbcRuntimeException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testHas(): void { @@ -89,8 +88,8 @@ public function testHas(): void /** * @return void - * @throws InvalidArgumentException - * @throws ExpectationFailedException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testHasNot(): void { @@ -184,9 +183,9 @@ public function testFilterOneByInstanceClass(): void /** * @return void - * @throws InvalidArgumentException * @throws DbcRuntimeException - * @throws ExpectationFailedException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testFilterOneByInstanceClassReturnNull(): void { @@ -197,8 +196,8 @@ public function testFilterOneByInstanceClassReturnNull(): void /** * @return void * @throws DBALException - * @throws Throwable * @throws Exception + * @throws Throwable */ protected function setUp(): void { diff --git a/tests/src/dbc/TableStub.php b/tests/src/dbc/TableStub.php index 13bf9836..fc793e43 100755 --- a/tests/src/dbc/TableStub.php +++ b/tests/src/dbc/TableStub.php @@ -4,12 +4,11 @@ namespace Jtl\Connector\Dbc; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Exception; -use Doctrine\DBAL\ForwardCompatibility\Result; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Table; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; class TableStub extends AbstractTable { @@ -31,8 +30,8 @@ public function getName(): string * @param mixed $value * * @return AbstractTable - * @throws DBALException * @throws DbcRuntimeException + * @throws Exception * @throws SchemaException|\RuntimeException */ public function restrict(string $column, mixed $value): AbstractTable @@ -41,52 +40,44 @@ public function restrict(string $column, mixed $value): AbstractTable } /** - * @param int $fetchType * @param array|null $columns * - * @return array> - * @throws DBALException - * @throws Exception + * @return array> * @throws DbcRuntimeException|\RuntimeException + * @throws Exception */ - public function findAll(int $fetchType = \PDO::FETCH_ASSOC, ?array $columns = null): array + public function findAll(?array $columns = null): array { if (\is_null($columns)) { $columns = $this->getColumnNames(); } - $stmt = $this->createQueryBuilder()->select($columns) + $stmt = $this->createQueryBuilder()->select(...$columns) ->from($this->getTableName()) - ->execute(); - - if ($stmt instanceof Result === false) { - throw new \RuntimeException('$stmt must be instance of ' . Result::class); - } + ->executeQuery(); /** @var array> $result */ - $result = $stmt->fetchAll($fetchType); + $result = $stmt->fetchAllAssociative(); return $this->convertAllToPhpValues($result); } /** * @param array $identifier - * @param int $fetchType * @param array|null $columns * - * @return array> - * @throws DBALException - * @throws Exception + * @return array> * @throws DbcRuntimeException + * @throws Exception * @throws \RuntimeException */ - public function find(array $identifier, int $fetchType = \PDO::FETCH_ASSOC, ?array $columns = null): array + public function find(array $identifier, ?array $columns = null): array { if (\is_null($columns)) { $columns = $this->getColumnNames(); } - $qb = $this->createQueryBuilder()->select($columns) + $qb = $this->createQueryBuilder()->select(...$columns) ->from($this->getTableName()); foreach ($identifier as $column => $value) { @@ -94,13 +85,10 @@ public function find(array $identifier, int $fetchType = \PDO::FETCH_ASSOC, ?arr ->setParameter($column, $value); } - $stmt = $qb->execute(); - if ($stmt instanceof Result === false) { - throw new \RuntimeException('$stmt must be instance of ' . Result::class); - } + $stmt = $qb->executeQuery(); /** @var array> $result */ - $result = $stmt->fetchAll($fetchType); + $result = $stmt->fetchAllAssociative(); return $this->convertAllToPhpValues($result); } @@ -114,10 +102,10 @@ public function find(array $identifier, int $fetchType = \PDO::FETCH_ASSOC, ?arr */ protected function createTableSchema(Table $tableSchema): void { - $tableSchema->addColumn(self::ID, Type::INTEGER, ['autoincrement' => true]); - $tableSchema->addColumn(self::A, Type::INTEGER, ['notnull' => false]); - $tableSchema->addColumn(self::B, Type::STRING, ['length' => 64]); - $tableSchema->addColumn(self::C, Type::DATETIME_IMMUTABLE); + $tableSchema->addColumn(self::ID, Types::INTEGER, ['autoincrement' => true]); + $tableSchema->addColumn(self::A, Types::INTEGER, ['notnull' => false]); + $tableSchema->addColumn(self::B, Types::STRING, ['length' => 64]); + $tableSchema->addColumn(self::C, Types::DATETIME_IMMUTABLE); $tableSchema->setPrimaryKey([self::ID]); } } diff --git a/tests/src/dbc/TestCase.php b/tests/src/dbc/TestCase.php index 1eba2d64..504c6103 100644 --- a/tests/src/dbc/TestCase.php +++ b/tests/src/dbc/TestCase.php @@ -4,23 +4,18 @@ namespace Jtl\Connector\Dbc; -use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Result; -use Jtl\UnitTest\TestCase as JtlTestCase; -use PDO; -use PDOException; use RuntimeException; use Throwable; -abstract class TestCase extends JtlTestCase +abstract class TestCase extends \PHPUnit\Framework\TestCase { public const string TABLE_PREFIX = 'pre_'; public const string SCHEMA = \TESTROOT . '/tmp/db.sqlite'; protected TableStub|\Jtl\Connector\MappingTables\TableStub $table; - private PDO $pdo; private DbManager $dbManager; /** @@ -49,8 +44,8 @@ public static function getCoordinatesFixtures(): array /** * @return void - * @throws Throwable * @throws DBALException + * @throws Throwable */ protected function setUp(): void { @@ -63,28 +58,11 @@ protected function setUp(): void /** * @return DbManager * @throws DBALException - * @throws PDOException - * @throws RuntimeException|\Doctrine\DBAL\DBALException + * @throws RuntimeException */ protected function getDBManager(): DbManager { if (!isset($this->dbManager)) { - /** @var DbManagerStub $dbManagerStub */ - $dbManagerStub = DbManagerStub::createFromParams(['pdo' => $this->getPDO()], null, self::TABLE_PREFIX); - $this->dbManager = $dbManagerStub; - } - - return $this->dbManager; - } - - /** - * @return PDO - * @throws RuntimeException - * @throws PDOException - */ - protected function getPDO(): PDO - { - if (!isset($this->pdo)) { if ( !\is_dir(\dirname(self::SCHEMA)) && !\mkdir($concurrentDirectory = \dirname(self::SCHEMA)) @@ -96,10 +74,17 @@ protected function getPDO(): PDO if (\file_exists(self::SCHEMA)) { \unlink(self::SCHEMA); } - $this->pdo = new PDO('sqlite:' . self::SCHEMA); + + /** @var DbManagerStub $dbManagerStub */ + $dbManagerStub = DbManagerStub::createFromParams( + ['driver' => 'pdo_sqlite', 'path' => self::SCHEMA], + null, + self::TABLE_PREFIX + ); + $this->dbManager = $dbManagerStub; } - return $this->pdo; + return $this->dbManager; } /** @@ -108,19 +93,14 @@ protected function getPDO(): PDO * * @return int * @throws DBALException - * @throws PDOException * @throws RuntimeException - * @throws Exception|\Doctrine\DBAL\DBALException - * @throws \Doctrine\DBAL\Driver\Exception */ protected function countRows(string $tableName, array $conditions = []): int { $connection = $this->getDbManager()->getConnection(); - /** @var AbstractPlatform $platform */ - $platform = $connection->getDatabasePlatform(); - $qb = (new QueryBuilder($connection)) - ->select($platform->getCountExpression('*')) + $qb = (new QueryBuilder($connection)) + ->select(\sprintf('COUNT(%s)', '*')) ->from($tableName); foreach ($conditions as $column => $value) { @@ -129,10 +109,7 @@ protected function countRows(string $tableName, array $conditions = []): int ->setParameter($column, $value); } - $result = $qb->execute(); - if ($result instanceof Result === false) { - throw new RuntimeException('unexpected Type, expected instance of Result'); - } + $result = $qb->executeQuery(); /** @var numeric-string $return */ $return = $result->fetchOne(); @@ -155,4 +132,60 @@ protected function insertFixtures(AbstractTable $table, array $fixtures): void $table->insert($fixture); } } + + /** + * @param object $object + * @param string $methodName + * @param mixed ...$arguments + * + * @return mixed + * @throws \ReflectionException + */ + protected function invokeMethodFromObject(object $object, string $methodName, mixed ...$arguments): mixed + { + $reflectionClass = new \ReflectionClass($object); + $reflectionMethod = $reflectionClass->getMethod($methodName); + + return $reflectionMethod->invoke($object, ...$arguments); + } + + /** + * @param object $object + * @param string $propertyName + * + * @return mixed + * @throws \RuntimeException + */ + protected function getPropertyValueFromObject(object $object, string $propertyName): mixed + { + $reflectionClass = new \ReflectionClass($object); + do { + if ($reflectionClass->hasProperty($propertyName)) { + break; + } + } while ($reflectionClass = $reflectionClass->getParentClass()); + + if (!$reflectionClass instanceof \ReflectionClass) { + throw new \RuntimeException(\sprintf('Property "%s" not found on %s', $propertyName, $object::class)); + } + + $reflectionProperty = $reflectionClass->getProperty($propertyName); + + return $reflectionProperty->getValue($object); + } + + /** + * @param object $object + * @param string $propertyName + * @param mixed $value + * + * @return void + * @throws \ReflectionException + */ + protected function setPropertyValueFromObject(object $object, string $propertyName, mixed $value): void + { + $reflectionClass = new \ReflectionClass($object); + $reflectionProperty = $reflectionClass->getProperty($propertyName); + $reflectionProperty->setValue($object, $value); + } } diff --git a/tests/src/dbc/Types/Uuid4TypeTest.php b/tests/src/dbc/Types/Uuid4TypeTest.php index 08d0aa6b..17e742c6 100644 --- a/tests/src/dbc/Types/Uuid4TypeTest.php +++ b/tests/src/dbc/Types/Uuid4TypeTest.php @@ -5,71 +5,26 @@ namespace Jtl\Connector\Dbc\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Platforms\MariaDb1027Platform; -use Doctrine\DBAL\Platforms\MySQL57Platform; -use Doctrine\DBAL\Platforms\MySQL80Platform; -use Doctrine\DBAL\Platforms\MySqlPlatform; -use Doctrine\DBAL\Platforms\SqlitePlatform; -use Doctrine\DBAL\Types\ConversionException; +use Doctrine\DBAL\Platforms\MariaDBPlatform; +use Doctrine\DBAL\Platforms\MySQLPlatform; +use Doctrine\DBAL\Platforms\SQLitePlatform; +use Doctrine\DBAL\Types\Exception\InvalidType; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; -use PHPUnit\Framework\MockObject\ClassIsFinalException; -use PHPUnit\Framework\MockObject\ClassIsReadonlyException; -use PHPUnit\Framework\MockObject\DuplicateMethodException; -use PHPUnit\Framework\MockObject\InvalidMethodNameException; -use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; -use PHPUnit\Framework\MockObject\ReflectionException; -use PHPUnit\Framework\MockObject\RuntimeException; -use PHPUnit\Framework\MockObject\UnknownClassException; -use PHPUnit\Framework\MockObject\UnknownTypeException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class Uuid4TypeTest extends TestCase { /** - * @return void - * @throws InvalidMethodNameException - * @throws ClassIsFinalException - * @throws ExpectationFailedException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws DuplicateMethodException - * @throws RuntimeException - * @throws ClassIsReadonlyException - * @throws ReflectionException - * @throws UnknownTypeException - * @throws OriginalConstructorInvocationRequiredException - * @throws InvalidArgumentException - * @throws ClassAlreadyExistsException - */ - public function testRequiresSQLCommentHint(): void - { - $platform = $this->createMock(AbstractPlatform::class); - $type = new Uuid4Type(); - $this->assertTrue($type->requiresSQLCommentHint($platform)); - } - - /** - * @dataProvider convertToDatabaseValueProvider - * * @param string $givenValue * @param string $convertedValue * * @return void - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws ConversionException - * @throws DuplicateMethodException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws \InvalidArgumentException + * @throws InvalidType + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('convertToDatabaseValueProvider')] public function testConvertToDatabaseValue(string $givenValue, string $convertedValue): void { $platform = $this->createMock(AbstractPlatform::class); @@ -78,25 +33,14 @@ public function testConvertToDatabaseValue(string $givenValue, string $converted } /** - * @dataProvider convertToPhpValueProvider - * * @param string $givenValue * @param string $convertedValue * * @return void - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('convertToPhpValueProvider')] public function testConvertToPHPValue(string $givenValue, string $convertedValue): void { $platform = $this->createMock(AbstractPlatform::class); @@ -105,16 +49,15 @@ public function testConvertToPHPValue(string $givenValue, string $convertedValue } /** - * @dataProvider convertToPHPValueSQLProvider - * * @param AbstractPlatform $platform * @param string $columnExpresion * @param string $expectedExpression * * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('convertToPHPValueSQLProvider')] public function testConvertToPHPValueSQL( AbstractPlatform $platform, string $columnExpresion, @@ -127,7 +70,7 @@ public function testConvertToPHPValueSQL( * @return array> * @throws \RuntimeException */ - public function convertToDatabaseValueProvider(): array + public static function convertToDatabaseValueProvider(): array { $firstDecode = \base64_decode('M23C0lBHSZWTeGvlPztRvg==', true); $secondDecode = \base64_decode('ZRBfJrVcTwSX0ErDbtYltw==', true); @@ -145,7 +88,7 @@ public function convertToDatabaseValueProvider(): array * @return array> * @throws \RuntimeException */ - public function convertToPhpValueProvider(): array + public static function convertToPhpValueProvider(): array { $decode = \base64_decode('M23C0lBHSZWTeGvlPztRvg==', true); if ($decode === false) { @@ -162,27 +105,16 @@ public function convertToPhpValueProvider(): array /** * @return array - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws UnknownClassException */ - public function convertToPHPValueSQLProvider(): array + public static function convertToPHPValueSQLProvider(): array { return [ - [new MySqlPlatform(), 'foo', 'LOWER(HEX(foo))'], - [new MariaDb1027Platform(), 'bar', 'LOWER(HEX(bar))'], - [new MySQL57Platform(), 'foobar', 'LOWER(HEX(foobar))'], - [new MySQL80Platform(), 'yeeha', 'LOWER(HEX(yeeha))'], - [new SqlitePlatform(), 'rofl', 'LOWER(HEX(rofl))'], - [$this->getMockForAbstractClass(AbstractPlatform::class), 'abcde', 'abcde'], + [new MySQLPlatform(), 'foo', 'LOWER(HEX(foo))'], + [new MariaDBPlatform(), 'bar', 'LOWER(HEX(bar))'], + [new MySQLPlatform(), 'foobar', 'LOWER(HEX(foobar))'], + [new MySQLPlatform(), 'yeeha', 'LOWER(HEX(yeeha))'], + [new SQLitePlatform(), 'rofl', 'LOWER(HEX(rofl))'], + [new SQLitePlatform(), 'abcde', 'LOWER(HEX(abcde))'], ]; } } diff --git a/tests/src/mapping-tables/AbstractTableTest.php b/tests/src/mapping-tables/AbstractTableTest.php index 2341cb0e..a7a28bf6 100755 --- a/tests/src/mapping-tables/AbstractTableTest.php +++ b/tests/src/mapping-tables/AbstractTableTest.php @@ -6,27 +6,16 @@ namespace Jtl\Connector\MappingTables; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Types\Types; use Jtl\Connector\Dbc\DbcRuntimeException; use Jtl\Connector\Dbc\DbManager; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; -use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; -use PHPUnit\Framework\MockObject\ClassIsFinalException; -use PHPUnit\Framework\MockObject\ClassIsReadonlyException; -use PHPUnit\Framework\MockObject\DuplicateMethodException; -use PHPUnit\Framework\MockObject\IncompatibleReturnValueException; -use PHPUnit\Framework\MockObject\InvalidMethodNameException; -use PHPUnit\Framework\MockObject\MethodCannotBeConfiguredException; -use PHPUnit\Framework\MockObject\MethodNameAlreadyConfiguredException; -use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; -use PHPUnit\Framework\MockObject\RuntimeException; -use PHPUnit\Framework\MockObject\UnknownTypeException; use ReflectionException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use Throwable; class AbstractTableTest extends TestCase @@ -34,10 +23,9 @@ class AbstractTableTest extends TestCase /** * @return void * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws DbcRuntimeException - * @throws \RuntimeException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testTableSchema(): void { @@ -53,12 +41,11 @@ public function testTableSchema(): void /** * @return void * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws SchemaException * @throws DbcRuntimeException + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws SchemaException */ public function testHostIndex(): void { @@ -78,12 +65,11 @@ public function testHostIndex(): void /** * @return void * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws SchemaException * @throws DbcRuntimeException + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws SchemaException */ public function testPrimaryIndex(): void { @@ -91,9 +77,8 @@ public function testPrimaryIndex(): void /** @var TableStub $tableStub */ $tableStub = $this->table; $tableSchema = $tableStub->getTableSchema(); - $this->assertTrue($tableSchema->hasPrimaryKey()); - $primaryKey = $tableSchema->getPrimaryKey(); - $this->assertNotNull($primaryKey); + $this->assertNotNull($tableSchema->getPrimaryKey()); + $primaryKey = $tableSchema->getPrimaryKey(); $primaryColumns = $primaryKey->getColumns(); $this->assertCount(3, $primaryColumns); $this->assertEquals(TableStub::COL_ID1, $primaryColumns[0]); @@ -104,12 +89,11 @@ public function testPrimaryIndex(): void /** * @return void * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws SchemaException * @throws DbcRuntimeException + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException + * @throws SchemaException */ public function testEndpointIndex(): void { @@ -130,11 +114,9 @@ public function testEndpointIndex(): void /** * @return void * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \Doctrine\DBAL\Driver\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetHostId(): void { @@ -148,12 +130,11 @@ public function testGetHostId(): void /** * @return void + * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws DbcRuntimeException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetEndpointId(): void { @@ -178,14 +159,13 @@ public function testGetEndpointId(): void * @return void * @throws DBALException * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Driver\Exception * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \Doctrine\DBAL\Driver\Exception * @throws \PDOException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSave(): void { @@ -200,14 +180,13 @@ public function testSave(): void * @return void * @throws DBALException * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Driver\Exception * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \Doctrine\DBAL\Driver\Exception * @throws \PDOException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testDeleteByEndpointId(): void { @@ -227,14 +206,13 @@ public function testDeleteByEndpointId(): void * @return void * @throws DBALException * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Driver\Exception * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \Doctrine\DBAL\Driver\Exception * @throws \PDOException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testDeleteByHostId(): void { @@ -251,20 +229,18 @@ public function testDeleteByHostId(): void } /** - * @dataProvider deleteByHostIdMultipleEntriesProvider - * * @param string|null $endpoint * * @return void * @throws DBALException + * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Driver\Exception * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \Doctrine\DBAL\Driver\Exception - * @throws DbcRuntimeException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('deleteByHostIdMultipleEntriesProvider')] public function testDeleteByHostIdMultipleEntries(?string $endpoint): void { $this->assertInstanceOf(TableStub::class, $this->table); @@ -284,7 +260,7 @@ public function testDeleteByHostIdMultipleEntries(?string $endpoint): void /** * @return array{0: array{null}, 1: array{string}} */ - public function deleteByHostIdMultipleEntriesProvider(): array + public static function deleteByHostIdMultipleEntriesProvider(): array { return [ [null], @@ -296,14 +272,13 @@ public function deleteByHostIdMultipleEntriesProvider(): array * @return void * @throws DBALException * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Driver\Exception * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \Doctrine\DBAL\Driver\Exception * @throws \PDOException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testClearDifferentTypes(): void { @@ -319,15 +294,14 @@ public function testClearDifferentTypes(): void /** * @return void * @throws DBALException + * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Driver\Exception * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \Doctrine\DBAL\Driver\Exception - * @throws DbcRuntimeException * @throws \PDOException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testClearAll(): void { @@ -341,10 +315,10 @@ public function testClearAll(): void /** * @return void + * @throws DbcRuntimeException * @throws Exception * @throws MappingTablesException - * @throws DbcRuntimeException - * @throws \RuntimeException|InvalidArgumentException + * @throws \RuntimeException|\InvalidArgumentException */ public function testClearUnknownType(): void { @@ -359,13 +333,12 @@ public function testClearUnknownType(): void /** * @return void * @throws DBALException + * @throws DbcRuntimeException + * @throws \Doctrine\DBAL\Driver\Exception * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \Doctrine\DBAL\Driver\Exception - * @throws DbcRuntimeException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCount(): void { @@ -383,11 +356,10 @@ public function testCount(): void /** * @return void * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws MappingTablesException * @throws \Doctrine\DBAL\Driver\Exception - * @throws \RuntimeException + * @throws \InvalidArgumentException + * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCountWithWhereCondition(): void { @@ -413,11 +385,10 @@ public function testCountWithWhereCondition(): void * @return void * @throws DBALException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testFindEndpointsByType(): void { @@ -436,12 +407,11 @@ public function testFindEndpointsByType(): void /** * @return void * @throws DBALException + * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws DbcRuntimeException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testFindAllEndpointsWithNoData(): void { @@ -450,20 +420,18 @@ public function testFindAllEndpointsWithNoData(): void $tableStub = $this->table; $tableStub->clear(TableStub::TYPE1); $endpoints = $tableStub->findEndpoints([], [], [], null, null, TableStub::TYPE1); - $this->assertIsArray($endpoints); $this->assertEmpty($endpoints); } /** * @return void * @throws DBALException + * @throws DbcRuntimeException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws DbcRuntimeException * @throws \PHPUnit\Framework\Exception - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testFilterMappedEndpoints(): void { @@ -490,10 +458,9 @@ public function testFilterMappedEndpoints(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws ReflectionException + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCreateEndpointData(): void { @@ -512,10 +479,9 @@ public function testCreateEndpointData(): void /** * @return void + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws ExpectationFailedException - * @throws \ReflectionException - * @throws InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCreateEndpointDataFailsTooMuchData(): void { @@ -528,10 +494,9 @@ public function testCreateEndpointDataFailsTooMuchData(): void /** * @return void + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws ExpectationFailedException - * @throws \ReflectionException - * @throws InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCreateEndpointDataFailsNotEnoughData(): void { @@ -544,9 +509,9 @@ public function testCreateEndpointDataFailsNotEnoughData(): void /** * @return void + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testBuildEndpoint(): void { @@ -560,30 +525,16 @@ public function testBuildEndpoint(): void } /** - * @dataProvider endpointWithColumnKeysProvider - * * @param array $endpointData * @param array $endpointColumnNames * @param string $expectedEndpoint * * @return void - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws ExpectationFailedException - * @throws IncompatibleReturnValueException - * @throws InvalidArgumentException - * @throws InvalidMethodNameException - * @throws MethodCannotBeConfiguredException - * @throws MethodNameAlreadyConfiguredException - * @throws OriginalConstructorInvocationRequiredException - * @throws RuntimeException - * @throws UnknownTypeException + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws \PHPUnit\Framework\MockObject\ReflectionException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('endpointWithColumnKeysProvider')] public function testBuildEndpointWithColumnKeys( array $endpointData, array $endpointColumnNames, @@ -604,7 +555,7 @@ public function testBuildEndpointWithColumnKeys( /** * @return array|array|string>> */ - public function endpointWithColumnKeysProvider(): array + public static function endpointWithColumnKeysProvider(): array { return [ [ @@ -618,11 +569,10 @@ public function endpointWithColumnKeysProvider(): array /** * @return void * @throws DBALException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws MappingTablesException * @throws DbcRuntimeException - * @throws \RuntimeException + * @throws \InvalidArgumentException + * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testExtractEndpoint(): void { @@ -643,10 +593,10 @@ public function testExtractEndpoint(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testExplodeEndpoint(): void { @@ -666,10 +616,10 @@ public function testExplodeEndpoint(): void /** * @return void + * @throws \InvalidArgumentException * @throws MappingTablesException * @throws \PHPUnit\Framework\Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testExplodeEndpointWithEmptyString(): void { @@ -685,7 +635,7 @@ public function testExplodeEndpointWithEmptyString(): void * @return void * @throws DBALException * @throws DbcRuntimeException - * @throws \RuntimeException|InvalidArgumentException + * @throws \RuntimeException|\InvalidArgumentException */ public function testExtractEndpointUnknownType(): void { @@ -700,11 +650,11 @@ public function testExtractEndpointUnknownType(): void /** * @return void - * @throws MappingTablesException - * @throws SchemaException * @throws DBALException * @throws Exception * @throws \Exception + * @throws MappingTablesException + * @throws SchemaException */ public function testAddColumnType(): void { @@ -712,15 +662,18 @@ public function testAddColumnType(): void $table->setEndpointColumn('test', Types::BINARY); $schema = $table->getTableSchema(); $column = $schema->getColumn('test'); - $this->assertEquals(Types::BINARY, $column->getType()->getName()); + $this->assertEquals( + Types::BINARY, + \Doctrine\DBAL\Types\Type::getTypeRegistry()->lookupName($column->getType()) + ); } /** * @return void - * @throws MappingTablesException * @throws DBALException * @throws Exception * @throws \Exception + * @throws MappingTablesException */ public function testAddColumn(): void { @@ -734,10 +687,10 @@ public function testAddColumn(): void /** * @return void - * @throws MappingTablesException * @throws DBALException * @throws Exception * @throws \Exception + * @throws MappingTablesException */ public function testAddColumnNotPrimary(): void { @@ -753,7 +706,6 @@ public function testAddColumnNotPrimary(): void /** * @return void * @throws DBALException - * @throws \RuntimeException */ public function testEmptyTypes(): void { @@ -771,20 +723,18 @@ public function getTypes(): array } /** - * @dataProvider extractValueFromEndpointProvider - * * @param string $field * @param string $endpoint * @param int|string $expectedValue * * @return void * @throws DBALException - * @throws MappingTablesException - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws DbcRuntimeException - * @throws \RuntimeException + * @throws \InvalidArgumentException + * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ + #[DataProvider('extractValueFromEndpointProvider')] public function testExtractValueFromEndpoint(string $field, string $endpoint, int|string $expectedValue): void { $this->assertInstanceOf(TableStub::class, $this->table); @@ -797,7 +747,7 @@ public function testExtractValueFromEndpoint(string $field, string $endpoint, in /** * @return array> */ - public function extractValueFromEndpointProvider(): array + public static function extractValueFromEndpointProvider(): array { return [ [TableStub::COL_ID1, \sprintf('%d||%d||%s||%d', 5, 42, 'strg', TableStub::TYPE1), 5], @@ -807,14 +757,12 @@ public function extractValueFromEndpointProvider(): array } /** - * @dataProvider wrongTypesProvider - * * @param mixed[] $types * * @return void * @throws DBALException - * @throws \RuntimeException */ + #[DataProvider('wrongTypesProvider')] public function testWrongTypes(array $types): void { $this->expectException(MappingTablesException::class); @@ -846,7 +794,7 @@ public function getTypes(): array /** * @return array>> */ - public function wrongTypesProvider(): array + public static function wrongTypesProvider(): array { return [ [['string']], diff --git a/tests/src/mapping-tables/TableCollectionTest.php b/tests/src/mapping-tables/TableCollectionTest.php index c3495411..32695f1e 100755 --- a/tests/src/mapping-tables/TableCollectionTest.php +++ b/tests/src/mapping-tables/TableCollectionTest.php @@ -4,19 +4,9 @@ namespace Jtl\Connector\MappingTables; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception as DBALException; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; -use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; -use PHPUnit\Framework\MockObject\ClassIsFinalException; -use PHPUnit\Framework\MockObject\ClassIsReadonlyException; -use PHPUnit\Framework\MockObject\DuplicateMethodException; -use PHPUnit\Framework\MockObject\InvalidMethodNameException; -use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; -use PHPUnit\Framework\MockObject\ReflectionException; -use PHPUnit\Framework\MockObject\RuntimeException; -use PHPUnit\Framework\MockObject\UnknownTypeException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class TableCollectionTest extends TestCase { @@ -24,9 +14,9 @@ class TableCollectionTest extends TestCase /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testToArray(): void { @@ -39,10 +29,10 @@ public function testToArray(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws MappingTablesException * @throws Exception + * @throws \InvalidArgumentException + * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSetAndGet(): void { @@ -59,8 +49,8 @@ public function testSetAndGet(): void /** * @return void - * @throws InvalidArgumentException * @throws ExpectationFailedException|Exception + * @throws \InvalidArgumentException */ public function testHas(): void { @@ -71,8 +61,8 @@ public function testHas(): void /** * @return void - * @throws InvalidArgumentException * @throws ExpectationFailedException|Exception + * @throws \InvalidArgumentException */ public function testHasNot(): void { @@ -83,19 +73,9 @@ public function testHasNot(): void /** * @return void - * @throws InvalidMethodNameException - * @throws RuntimeException - * @throws OriginalConstructorInvocationRequiredException - * @throws InvalidArgumentException - * @throws ClassIsFinalException - * @throws ExpectationFailedException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws DuplicateMethodException - * @throws ClassIsReadonlyException - * @throws ReflectionException - * @throws UnknownTypeException * @throws Exception - * @throws ClassAlreadyExistsException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testRemoveByType(): void { @@ -114,20 +94,10 @@ public function testRemoveByType(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws MappingTablesException - * @throws \PHPUnit\Framework\InvalidArgumentException - * @throws ClassAlreadyExistsException - * @throws ClassIsFinalException - * @throws ClassIsReadonlyException - * @throws DuplicateMethodException - * @throws InvalidMethodNameException - * @throws OriginalConstructorInvocationRequiredException - * @throws ReflectionException - * @throws RuntimeException - * @throws UnknownTypeException * @throws \Exception + * @throws \InvalidArgumentException + * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testRemoveByInstance(): void { @@ -142,10 +112,10 @@ public function testRemoveByInstance(): void /** * @return void - * @throws MappingTablesException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetNotExistingTableWithStrictModeEnabled(): void { @@ -159,10 +129,10 @@ public function testGetNotExistingTableWithStrictModeEnabled(): void /** * @return void - * @throws MappingTablesException * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetNotExistingTableWithStrictModeDisabled(): void { @@ -178,8 +148,8 @@ public function testGetNotExistingTableWithStrictModeDisabled(): void /** * @return void * @throws DBALException - * @throws \Throwable * @throws \Exception + * @throws \Throwable */ protected function setUp(): void { diff --git a/tests/src/mapping-tables/TableDummyTest.php b/tests/src/mapping-tables/TableDummyTest.php index 9e02257a..206ff682 100755 --- a/tests/src/mapping-tables/TableDummyTest.php +++ b/tests/src/mapping-tables/TableDummyTest.php @@ -7,7 +7,6 @@ use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; -use SebastianBergmann\RecursionContext\InvalidArgumentException; class TableDummyTest extends TestCase { @@ -15,8 +14,8 @@ class TableDummyTest extends TestCase /** * @return void - * @throws InvalidArgumentException - * @throws ExpectationFailedException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testClear(): void { @@ -27,8 +26,8 @@ public function testClear(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testFindEndpoints(): void { @@ -39,8 +38,8 @@ public function testFindEndpoints(): void /** * @return void - * @throws InvalidArgumentException - * @throws ExpectationFailedException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetTypeDefault(): void { @@ -49,8 +48,8 @@ public function testGetTypeDefault(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testRemove(): void { @@ -61,8 +60,8 @@ public function testRemove(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetHostId(): void { @@ -73,8 +72,8 @@ public function testGetHostId(): void /** * @return void - * @throws InvalidArgumentException - * @throws ExpectationFailedException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCount(): void { @@ -83,8 +82,8 @@ public function testCount(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetEndpointId(): void { @@ -95,9 +94,9 @@ public function testGetEndpointId(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException * @throws Exception + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSetType(): void { @@ -113,8 +112,8 @@ public function testSetType(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSave(): void { @@ -125,8 +124,8 @@ public function testSave(): void /** * @return void - * @throws InvalidArgumentException - * @throws ExpectationFailedException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException * @noinspection PhpExpressionResultUnusedInspection */ public function testFindNotFetchedEndpoints(): void diff --git a/tests/src/mapping-tables/TableManagerTest.php b/tests/src/mapping-tables/TableManagerTest.php index 14fe3cba..8bede5a4 100755 --- a/tests/src/mapping-tables/TableManagerTest.php +++ b/tests/src/mapping-tables/TableManagerTest.php @@ -4,11 +4,10 @@ namespace Jtl\Connector\MappingTables; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception as DBALException; use Exception; use Jtl\Connector\Dbc\DbcRuntimeException; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use Throwable; class TableManagerTest extends TestCase @@ -17,10 +16,10 @@ class TableManagerTest extends TestCase /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetMappingTable(): void { @@ -30,9 +29,9 @@ public function testGetMappingTable(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetHostId(): void { @@ -44,9 +43,9 @@ public function testGetHostId(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetEndpointId(): void { @@ -57,9 +56,9 @@ public function testGetEndpointId(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSave(): void { @@ -72,9 +71,9 @@ public function testSave(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testDeleteByEndpointId(): void { @@ -85,9 +84,9 @@ public function testDeleteByEndpointId(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testDeleteByHostId(): void { @@ -98,10 +97,10 @@ public function testDeleteByHostId(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testFindAllEndpointsIds(): void { @@ -111,10 +110,10 @@ public function testFindAllEndpointsIds(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException * @throws \PHPUnit\Framework\Exception + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testFindNotFetchedEndpoints(): void { @@ -140,13 +139,12 @@ public function testFindNotFetchedEndpoints(): void * @return void * @throws DBALException * @throws DbcRuntimeException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws MappingTablesException * @throws \Doctrine\DBAL\Driver\Exception * @throws \Doctrine\DBAL\Exception + * @throws \InvalidArgumentException + * @throws MappingTablesException * @throws \PDOException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testClear(): void { @@ -159,13 +157,12 @@ public function testClear(): void * @return void * @throws DBALException * @throws DbcRuntimeException - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws MappingTablesException * @throws \Doctrine\DBAL\Driver\Exception * @throws \Doctrine\DBAL\Exception + * @throws \InvalidArgumentException + * @throws MappingTablesException * @throws \PDOException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testClearByType(): void { @@ -180,9 +177,9 @@ public function testClearByType(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCount(): void { @@ -191,10 +188,10 @@ public function testCount(): void /** * @return void + * @throws \InvalidArgumentException * @throws MappingTablesException * @throws \PHPUnit\Framework\Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetNotExistingTableWithStrictModeDisabled(): void { @@ -219,8 +216,8 @@ public function testGetNotExistingTableWithStrictModeEnabled(): void /** * @return void * @throws DBALException - * @throws Throwable * @throws Exception + * @throws Throwable */ protected function setUp(): void { diff --git a/tests/src/mapping-tables/TableProxyTest.php b/tests/src/mapping-tables/TableProxyTest.php index 07f420e1..fe0eeeff 100755 --- a/tests/src/mapping-tables/TableProxyTest.php +++ b/tests/src/mapping-tables/TableProxyTest.php @@ -4,11 +4,9 @@ namespace Jtl\Connector\MappingTables; -use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Driver\Exception; +use Doctrine\DBAL\Exception as DBALException; use Jtl\Connector\Dbc\DbcRuntimeException; use PHPUnit\Framework\ExpectationFailedException; -use SebastianBergmann\RecursionContext\InvalidArgumentException; use Throwable; class TableProxyTest extends TestCase @@ -17,10 +15,10 @@ class TableProxyTest extends TestCase /** * @return void - * @throws MappingTablesException * @throws DBALException - * @throws Throwable * @throws \Exception + * @throws MappingTablesException + * @throws Throwable */ protected function setUp(): void { @@ -33,11 +31,9 @@ protected function setUp(): void /** * @return void * @throws DBALException - * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetHostId(): void { @@ -50,11 +46,9 @@ public function testGetHostId(): void /** * @return void * @throws DBALException - * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetHostIdFromNotSelectedType(): void { @@ -67,11 +61,9 @@ public function testGetHostIdFromNotSelectedType(): void /** * @return void * @throws DBALException - * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetHostIdWhichNotExists(): void { @@ -84,12 +76,10 @@ public function testGetHostIdWhichNotExists(): void /** * @return void * @throws DBALException - * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws MappingTablesException * @throws \Doctrine\DBAL\Exception - * @throws \RuntimeException + * @throws \InvalidArgumentException + * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testCountAndClear(): void { @@ -100,12 +90,11 @@ public function testCountAndClear(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws MappingTablesException * @throws DbcRuntimeException * @throws \Doctrine\DBAL\Exception - * @throws \RuntimeException + * @throws \InvalidArgumentException + * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetEndpoint(): void { @@ -117,12 +106,11 @@ public function testGetEndpoint(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws MappingTablesException * @throws DbcRuntimeException * @throws \Doctrine\DBAL\Exception - * @throws \RuntimeException + * @throws \InvalidArgumentException + * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetEndpointFromNotSelectedType(): void { @@ -136,11 +124,9 @@ public function testGetEndpointFromNotSelectedType(): void /** * @return void * @throws DBALException - * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testDeleteByHostId(): void { @@ -153,11 +139,9 @@ public function testDeleteByHostId(): void /** * @return void * @throws DBALException - * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testDeleteByHostIdWithMultipleEntries(): void { @@ -170,11 +154,9 @@ public function testDeleteByHostIdWithMultipleEntries(): void /** * @return void * @throws DBALException - * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testDeleteByEndpointId(): void { @@ -186,9 +168,9 @@ public function testDeleteByEndpointId(): void /** * @return void - * @throws ExpectationFailedException - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetAndSetType(): void { @@ -211,12 +193,10 @@ public function testSetWrongType(): void /** * @return void * @throws DBALException - * @throws Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws MappingTablesException * @throws DbcRuntimeException - * @throws \RuntimeException + * @throws \InvalidArgumentException + * @throws MappingTablesException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testSave(): void { @@ -232,11 +212,10 @@ public function testSave(): void /** * @return void * @throws DBALException + * @throws \InvalidArgumentException * @throws MappingTablesException * @throws \PHPUnit\Framework\Exception - * @throws ExpectationFailedException - * @throws InvalidArgumentException - * @throws \RuntimeException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testFindEndpoints(): void { @@ -245,9 +224,9 @@ public function testFindEndpoints(): void /** * @return void - * @throws InvalidArgumentException + * @throws \InvalidArgumentException * @throws \PHPUnit\Framework\Exception - * @throws ExpectationFailedException + * @throws \PHPUnit\Framework\ExpectationFailedException */ public function testGetTable(): void { diff --git a/tests/src/mapping-tables/TableStub.php b/tests/src/mapping-tables/TableStub.php index 954b8562..0303e26a 100755 --- a/tests/src/mapping-tables/TableStub.php +++ b/tests/src/mapping-tables/TableStub.php @@ -4,7 +4,7 @@ namespace Jtl\Connector\MappingTables; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception as DBALException; use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\SchemaException; @@ -42,8 +42,8 @@ public function getName(): string /** * @return void - * @throws MappingTablesException * @throws Exception + * @throws MappingTablesException */ public function defineEndpoint(): void { @@ -78,11 +78,11 @@ public function getTypes(): array * @param Table $tableSchema * * @return void + * @throws DbcRuntimeException * @throws Exception * @throws MappingTablesException - * @throws SchemaException - * @throws DbcRuntimeException * @throws \RuntimeException + * @throws SchemaException */ public function createTableSchema(Table $tableSchema): void { @@ -114,9 +114,9 @@ public function implodeEndpoint(array $data): string * @param mixed[] $data * * @return mixed[] + * @throws DBALException * @throws DbcRuntimeException * @throws MappingTablesException - * @throws DBALException * @throws \RuntimeException */ public function createEndpointData(array $data): array From dc8f215591d7f0ce2db18c48756d75976c4b9403 Mon Sep 17 00:00:00 2001 From: Patrick Gugelsberger Date: Mon, 1 Jun 2026 15:20:41 +0200 Subject: [PATCH 2/2] refactor: remove mockery/mockery dependency Replace the single Mockery usage in IdentityLinkerTest with PHPUnit's built-in createMock(). Sequential return values are handled via willReturnCallback() with array queues. This also removes the transitive hamcrest/hamcrest-php dependency. --- composer.json | 3 +- tests/src/Linker/IdentityLinkerTest.php | 44 ++++++++++++------------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index a4c7ad27..3bd2cc55 100755 --- a/composer.json +++ b/composer.json @@ -40,8 +40,7 @@ "phpstan/phpstan": "^2.0", "squizlabs/php_codesniffer": "^4.0", "micheh/phpcs-gitlab": "^2.0", - "slevomat/coding-standard": "^8.29", - "mockery/mockery": "^1.6" + "slevomat/coding-standard": "^8.29" }, "provide": { "jtl/connector-mapping-tables": "4.0.8", diff --git a/tests/src/Linker/IdentityLinkerTest.php b/tests/src/Linker/IdentityLinkerTest.php index e4bd8912..fae7c06c 100755 --- a/tests/src/Linker/IdentityLinkerTest.php +++ b/tests/src/Linker/IdentityLinkerTest.php @@ -17,11 +17,10 @@ use Jtl\Connector\Core\Model\ProductWarehouseInfo; use Jtl\Connector\Core\Model\ShippingClass; use Jtl\Connector\Core\Test\TestCase; -use Mockery\Exception\RuntimeException; -use Mockery\LegacyMockInterface; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Exception; use PHPUnit\Framework\ExpectationFailedException; +use PHPUnit\Framework\MockObject\MockObject; use ReflectionException; /** @@ -65,19 +64,30 @@ protected function createLinker(?PrimaryKeyMapperInterface $mockedPrimaryKeyMapp * @param array $hostId * @param array $endpointId * - * @return PrimaryKeyMapperInterface&LegacyMockInterface + * @return PrimaryKeyMapperInterface&MockObject */ public function createPrimaryKeyMapperMock( array $hostId = [1], array $endpointId = ['1'] - ): PrimaryKeyMapperInterface&LegacyMockInterface { - /** @var PrimaryKeyMapperInterface&LegacyMockInterface $primaryKeyMapper */ - $primaryKeyMapper = \Mockery::mock(PrimaryKeyMapperInterface::class); - $primaryKeyMapper->shouldReceive('save')->andReturnTrue(); //@phpstan-ignore-line - $primaryKeyMapper->shouldReceive('delete')->andReturnTrue(); //@phpstan-ignore-line - $primaryKeyMapper->shouldReceive('clear')->andReturnTrue(); //@phpstan-ignore-line - $primaryKeyMapper->shouldReceive('getHostId')->andReturn(...$hostId); //@phpstan-ignore-line - $primaryKeyMapper->shouldReceive('getEndpointId')->andReturn(...$endpointId); //@phpstan-ignore-line + ): PrimaryKeyMapperInterface&MockObject { + $primaryKeyMapper = $this->createMock(PrimaryKeyMapperInterface::class); + $primaryKeyMapper->method('save')->willReturn(true); + $primaryKeyMapper->method('delete')->willReturn(true); + $primaryKeyMapper->method('clear')->willReturn(true); + + $hostIdQueue = $hostId; + $primaryKeyMapper->method('getHostId')->willReturnCallback( + static function () use (&$hostIdQueue): ?int { + return \array_shift($hostIdQueue); + } + ); + + $endpointIdQueue = $endpointId; + $primaryKeyMapper->method('getEndpointId')->willReturnCallback( + static function () use (&$endpointIdQueue): ?string { + return \array_shift($endpointIdQueue); + } + ); return $primaryKeyMapper; } @@ -465,16 +475,4 @@ public function testLinkIdentityList(): void $endpointId = $linker->getEndpointId($modelName, 'id', $expectedHostId); $this->assertNotEquals($expectedEndpointId, $endpointId); } - - /** - * @return void - * @throws \InvalidArgumentException - * @throws \PHPUnit\Framework\ExpectationFailedException - */ - protected function tearDown(): void - { - parent::tearDown(); - - \Mockery::close(); - } }