From 7a58fc471b0e6c69fa3ee34f0accfe9a42ec6086 Mon Sep 17 00:00:00 2001 From: "Artem O. Architect" Date: Wed, 23 Feb 2022 11:21:55 +0200 Subject: [PATCH] * Update DataTypeInterface, add TYPE_RESOURCE * Update TestGenerator, update logic, that search default values for method arguments for DataProvider --- composer.json | 4 +-- src/Generator/DataTypeInterface.php | 1 + src/Generator/Mock/Mockery.php | 5 +++ src/Generator/TestGenerator.php | 52 ++++++++++++++--------------- src/Service/TestProject.php | 4 +-- 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/composer.json b/composer.json index eb456b9..68b5bb4 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,8 @@ "micro-module/faker": "^1.9" }, "require-dev": { - "jakub-onderka/php-console-highlighter": "^0.4", - "jakub-onderka/php-parallel-lint": "^1.0", + "php-parallel-lint/php-console-highlighter": "^0.4", + "php-parallel-lint/php-parallel-lint": "^1.1", "mockery/mockery": "^1.2", "phpmd/phpmd": "^2.6", "phpstan/phpstan": "^0.11", diff --git a/src/Generator/DataTypeInterface.php b/src/Generator/DataTypeInterface.php index aab3a6e..6c4030e 100644 --- a/src/Generator/DataTypeInterface.php +++ b/src/Generator/DataTypeInterface.php @@ -28,5 +28,6 @@ interface DataTypeInterface public const TYPE_SELF = 'self'; public const TYPE_STATIC = 'static'; public const TYPE_OBJECT = 'object'; + public const TYPE_RESOURCE = 'resource'; public const TYPE_ = ''; } diff --git a/src/Generator/Mock/Mockery.php b/src/Generator/Mock/Mockery.php index e549b54..e232414 100644 --- a/src/Generator/Mock/Mockery.php +++ b/src/Generator/Mock/Mockery.php @@ -243,6 +243,11 @@ class_exists('ReflectionUnionType') && break; + case DataTypeInterface::TYPE_RESOURCE: + $mockMethod .= '$mockMethod->andReturn(typeOf(\'resource\'));'; + + break; + default: if ( in_array($returnType, $extendedClasses, true) || diff --git a/src/Generator/TestGenerator.php b/src/Generator/TestGenerator.php index 1774e98..c4b400c 100644 --- a/src/Generator/TestGenerator.php +++ b/src/Generator/TestGenerator.php @@ -718,36 +718,34 @@ class_exists('ReflectionUnionType') && } if (!array_key_exists($i, $annotationParams)) { - if ('{@inheritdoc}' === $methodComment) { - if ($reflectionMethod->getDeclaringClass()->isInterface()) { - throw new Exception(sprintf( - 'In interface \'%s\' in method \'%s\' for argument \'%s\' annotation not exists.', - $reflectionClass->getName(), - $reflectionMethod->getName(), - $param->getName() - )); - } - $interfaces = $reflectionMethod->getDeclaringClass()->getInterfaces(); - - foreach ($interfaces as $interface) { - try { - $parentMethod = $interface->getMethod($reflectionMethod->getName()); - - return $this->processMethodDocComment($interface, $parentMethod); - break; - } catch (ReflectionException $e) { - continue; - } catch (RuntimeException $e) { - break; - } + if ($reflectionClass->isInterface()) { + throw new Exception(sprintf( + 'In interface \'%s\' in method \'%s\' for argument \'%s\' annotation not exists.', + $reflectionClass->getName(), + $reflectionMethod->getName(), + $param->getName() + )); + } + $interfaces = $reflectionClass->getInterfaces(); + + foreach ($interfaces as $interface) { + try { + $parentMethod = $interface->getMethod($reflectionMethod->getName()); + + return $this->processMethodDocComment($interface, $parentMethod); + break; + } catch (ReflectionException $e) { + continue; + } catch (RuntimeException $e) { + break; } - $parentClass = $reflectionMethod->getDeclaringClass()->getParentClass(); + } + $parentClass = $reflectionMethod->getDeclaringClass()->getParentClass(); - if ($parentClass) { - $parentMethod = $parentClass->getMethod($reflectionMethod->getName()); + if ($parentClass) { + $parentMethod = $parentClass->getMethod($reflectionMethod->getName()); - return $this->processMethodDocComment($parentClass, $parentMethod); - } + return $this->processMethodDocComment($parentClass, $parentMethod); } throw new RuntimeException( diff --git a/src/Service/TestProject.php b/src/Service/TestProject.php index a76171a..a2560cf 100644 --- a/src/Service/TestProject.php +++ b/src/Service/TestProject.php @@ -49,12 +49,12 @@ public function __construct(string $sourcePath, array $excludeFolders = []) * * @throws Exception */ - public function generate(): void + public function generate(bool $deepLevel = true): void { if (!file_exists($this->sourcePath)) { throw new Exception("Source file '{$this->sourcePath}' doesn't exists!"); } - $modules = $this->scanProjectSourceFolder($this->sourcePath, true); + $modules = $this->scanProjectSourceFolder($this->sourcePath, $deepLevel); foreach ($modules as $folder) { foreach ($folder as $file) {