Skip to content

Commit

Permalink
* Update DataTypeInterface, add TYPE_RESOURCE
Browse files Browse the repository at this point in the history
* Update TestGenerator, update logic, that search default values for method arguments for DataProvider
  • Loading branch information
Artem O. Architect committed Feb 23, 2022
1 parent f2e23a2 commit 7a58fc4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/Generator/DataTypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_ = '';
}
5 changes: 5 additions & 0 deletions src/Generator/Mock/Mockery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down
52 changes: 25 additions & 27 deletions src/Generator/TestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/Service/TestProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7a58fc4

Please sign in to comment.