diff --git a/packages/Annotation/src/AnnotationDecorator.php b/packages/Annotation/src/AnnotationDecorator.php index f7a401f44..fc03352df 100644 --- a/packages/Annotation/src/AnnotationDecorator.php +++ b/packages/Annotation/src/AnnotationDecorator.php @@ -6,8 +6,9 @@ use ApiGen\Reflection\Contract\Reflection\AbstractReflectionInterface; use phpDocumentor\Reflection\DocBlock\Tag; -# see: https://github.com/phpDocumentor/TypeResolver#resolving-an-fqsen - +/** + * @link https://github.com/phpDocumentor/TypeResolver#resolving-an-fqsen + */ final class AnnotationDecorator { /** diff --git a/packages/Element/src/ReflectionCollector/AnnotationReflectionCollector.php b/packages/Element/src/ReflectionCollector/AnnotationReflectionCollector.php index bd6b9a5f2..33f93cd59 100644 --- a/packages/Element/src/ReflectionCollector/AnnotationReflectionCollector.php +++ b/packages/Element/src/ReflectionCollector/AnnotationReflectionCollector.php @@ -2,7 +2,7 @@ namespace ApiGen\Element\ReflectionCollector; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Reflection\Contract\Reflection\AbstractReflectionInterface; use ApiGen\Reflection\Contract\Reflection\Class_\ClassConstantReflectionInterface; use ApiGen\Reflection\Contract\Reflection\Class_\ClassMethodReflectionInterface; @@ -20,7 +20,7 @@ final class AnnotationReflectionCollector extends AbstractReflectionCollector { /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; @@ -29,7 +29,7 @@ final class AnnotationReflectionCollector extends AbstractReflectionCollector */ private $activeAnnotation; - public function __construct(ConfigurationInterface $configuration) + public function __construct(Configuration $configuration) { $this->configuration = $configuration; } diff --git a/packages/Element/tests/ReflectionCollector/AnnotationReflectionCollectorTest.php b/packages/Element/tests/ReflectionCollector/AnnotationReflectionCollectorTest.php index c0f81771c..f9c286104 100644 --- a/packages/Element/tests/ReflectionCollector/AnnotationReflectionCollectorTest.php +++ b/packages/Element/tests/ReflectionCollector/AnnotationReflectionCollectorTest.php @@ -3,7 +3,7 @@ namespace ApiGen\Element\Tests\ReflectionCollector; use ApiGen\Annotation\AnnotationList; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Element\ReflectionCollector\AnnotationReflectionCollector; use ApiGen\ModularConfiguration\Option\AnnotationGroupsOption; use ApiGen\ModularConfiguration\Option\DestinationOption; @@ -20,8 +20,8 @@ final class AnnotationReflectionCollectorTest extends AbstractContainerAwareTest protected function setUp(): void { - /** @var ConfigurationInterface $configuration */ - $configuration = $this->container->getByType(ConfigurationInterface::class); + /** @var Configuration $configuration */ + $configuration = $this->container->getByType(Configuration::class); $configuration->resolveOptions([ SourceOption::NAME => [__DIR__], DestinationOption::NAME => TEMP_DIR, diff --git a/packages/Reflection/src/Reflection/Class_/ClassReflection.php b/packages/Reflection/src/Reflection/Class_/ClassReflection.php index 9aa274419..905f359bb 100644 --- a/packages/Reflection/src/Reflection/Class_/ClassReflection.php +++ b/packages/Reflection/src/Reflection/Class_/ClassReflection.php @@ -128,12 +128,13 @@ public function getInheritedDescription(): ?string public function getParentClass(): ?ClassReflectionInterface { - if (! $this->betterClassReflection->getParentClass()) { + $parentClassName = get_parent_class($this->getName()); + if ($parentClassName === false) { return null; } return $this->transformerCollector->transformSingle( - $this->betterClassReflection->getParentClass() + ReflectionClass::createFromName($parentClassName) ); } diff --git a/packages/Reflection/src/TransformerCollector.php b/packages/Reflection/src/TransformerCollector.php index 89d5ec03a..165a65e35 100644 --- a/packages/Reflection/src/TransformerCollector.php +++ b/packages/Reflection/src/TransformerCollector.php @@ -94,7 +94,7 @@ private function hasAllowedAccessLevel($transformedReflection): bool return true; } - // hardcoded @todo make service-like and using ConfigurationInterface + // hardcoded @todo make service-like and using Configuration if ($transformedReflection->isPublic() || $transformedReflection->isProtected()) { return true; } diff --git a/packages/StringRouting/tests/Route/SourceCodeRouteTest.php b/packages/StringRouting/tests/Route/SourceCodeRouteTest.php index 89486d532..f57868aae 100644 --- a/packages/StringRouting/tests/Route/SourceCodeRouteTest.php +++ b/packages/StringRouting/tests/Route/SourceCodeRouteTest.php @@ -2,7 +2,7 @@ namespace ApiGen\StringRouting\Tests\Route; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\ModularConfiguration\Option\DestinationOption; use ApiGen\ModularConfiguration\Option\SourceOption; use ApiGen\Reflection\Contract\Reflection\Class_\ClassConstantReflectionInterface; @@ -30,8 +30,8 @@ final class SourceCodeRouteTest extends AbstractContainerAwareTestCase protected function setUp(): void { $this->stringRouter = $this->container->getByType(StringRouter::class); - /** @var ConfigurationInterface $configuration */ - $configuration = $this->container->getByType(ConfigurationInterface::class); + /** @var Configuration $configuration */ + $configuration = $this->container->getByType(Configuration::class); $configuration->resolveOptions([ SourceOption::NAME => [__DIR__], DestinationOption::NAME => TEMP_DIR diff --git a/packages/ThemeDefault/src/404.latte b/packages/ThemeDefault/src/404.latte index 5ed3d8bde..623434909 100644 --- a/packages/ThemeDefault/src/404.latte +++ b/packages/ThemeDefault/src/404.latte @@ -3,10 +3,8 @@ {block title}Page not found{/block} {block content} -

{include title}

The requested page could not be found.

You have probably clicked on a link that is outdated and points to a page that does not exist any more or you have made an typing error in the address.

To continue please try to find requested page in the menu or use search field on the top.

-
{/block} diff --git a/packages/ThemeDefault/src/@layout.latte b/packages/ThemeDefault/src/@layout.latte index e554e9a37..6da535b09 100644 --- a/packages/ThemeDefault/src/@layout.latte +++ b/packages/ThemeDefault/src/@layout.latte @@ -16,11 +16,11 @@ + {include "partial/menu.latte"} +
- {include searchForm} - {include "partial/menu.latte"} {include content} {include footer}
@@ -37,13 +37,6 @@ -{define searchForm} - -{/define} - - {define footer} {/block} diff --git a/packages/ThemeDefault/src/classes.latte b/packages/ThemeDefault/src/classes.latte new file mode 100644 index 000000000..f2b44aa55 --- /dev/null +++ b/packages/ThemeDefault/src/classes.latte @@ -0,0 +1,17 @@ +{layout '@layout.latte'} + +{block title}{$pageTitle}{/block} + +{block content} +

{$pageTitle}

+ + + {foreach $classes as $class} + + + + {/foreach} +
+ {$class->getName()} +
+{/block} diff --git a/packages/ThemeDefault/src/function.latte b/packages/ThemeDefault/src/function.latte index a38f8f478..9f127730f 100644 --- a/packages/ThemeDefault/src/function.latte +++ b/packages/ThemeDefault/src/function.latte @@ -1,64 +1,61 @@ {layout '@layout.latte'} -{var $activePage = 'function'} {block title} {if $function->isDeprecated()}Deprecated {/if}Function {$function->getName()} {/block} {block content} -
-

Function {$function->getShortName()}

+

Function {$function->getShortName()}

- {if $function->getDescription()} -
- {$function|description} -
- {/if} + {if $function->getDescription()} +
+ {$function|description} +
+ {/if} -
- {if $function->getNamespaceName()}Namespace: {$function->getNamespaceName()|linkAllNamespaceParts|noescape}
{/if} - {var $filteredAnnotations = ($function->getAnnotations()|annotationFilter: ['param', 'return', 'throws'])} - {foreach $filteredAnnotations as $annotation => $values} - {foreach $values as $value} - {$annotation}{if $value}:{/if} - {$value|annotation:$function|noescape}
- {/foreach} +
+ {if $function->getNamespaceName()}Namespace: {$function->getNamespaceName()|linkAllNamespaceParts|noescape}
{/if} + {var $filteredAnnotations = ($function->getAnnotations()|annotationFilter: ['param', 'return', 'throws'])} + {foreach $filteredAnnotations as $annotation => $values} + {foreach $values as $value} + {$annotation}{if $value}:{/if} + {$value|annotation:$function|noescape}
{/foreach} - Open source code -
-
+ {/foreach} + Open source code +
+
- {var $annotations = $function->getAnnotations()} + {var $annotations = $function->getAnnotations()} - - - +
Parameters Summary
+ + + + + + +
Parameters Summary
+ + {if $parameter->getTypeHintClassOrInterfaceReflection()} + {$parameter->getTypeHintClassOrInterfaceReflection()|linkReflection} + {else} + {$parameter->getTypeHint()} + {/if} + + {block|strip} + {if $parameter->isPassedByReference()}& {/if}${$parameter->getName()} + {if $parameter->isDefaultValueAvailable()} = {$parameter->getDefaultValueDefinition()|highlightValue:$function|noescape}{elseif $parameter->isVariadic()},…{/if} + {/block}{$parameter|description}
+ + {if isset($annotations['return']) && $annotations['return'][0] !== 'void'} + + + - -
Return value Summary
- - {if $parameter->getTypeHintClassOrInterfaceReflection()} - {$parameter->getTypeHintClassOrInterfaceReflection()|linkReflection} - {else} - {$parameter->getTypeHint()} - {/if} - + {$annotations['return'][0]|annotation:$function|noescape} {block|strip} - {if $parameter->isPassedByReference()}& {/if}${$parameter->getName()} - {if $parameter->isDefaultValueAvailable()} = {$parameter->getDefaultValueDefinition()|highlightValue:$function|noescape}{elseif $parameter->isVariadic()},…{/if} - {/block}{$parameter|description}
- - {if isset($annotations['return']) && $annotations['return'][0] !== 'void'} - - - - - -
Return value Summary
- {$annotations['return'][0]|annotation:$function|noescape} -
- {/if} -
+ {/if} {/block} diff --git a/packages/ThemeDefault/src/functions.latte b/packages/ThemeDefault/src/functions.latte new file mode 100644 index 000000000..b9785c249 --- /dev/null +++ b/packages/ThemeDefault/src/functions.latte @@ -0,0 +1,17 @@ +{layout '@layout.latte'} + +{block title}{$pageTitle}{/block} + +{block content} +

{$pageTitle}

+ + + {foreach $functions as $function} + + + + {/foreach} +
+ {$function->getName()} +
+{/block} diff --git a/packages/ThemeDefault/src/index.latte b/packages/ThemeDefault/src/index.latte index 518c9c9ca..19fb699ab 100644 --- a/packages/ThemeDefault/src/index.latte +++ b/packages/ThemeDefault/src/index.latte @@ -1,23 +1,20 @@ {layout '@layout.latte'} -{var $activePage = 'overview'} {block title}{$title ?: 'Overview'}{/block} {block content} -
-

{include title}

+

{include title}

- {if count($allNamespaces)} - - - - - -
Namespaces Summary
- {$namespace} -
- {/if} + {if count($allNamespaces)} + + + + + +
Namespaces Summary
+ {$namespace} +
+ {/if} - {include '@elementlist.latte'} -
+ {include '@elementlist.latte'} {/block} diff --git a/packages/ThemeDefault/src/interface.latte b/packages/ThemeDefault/src/interface.latte index 8d43c4aca..a2e4b017d 100644 --- a/packages/ThemeDefault/src/interface.latte +++ b/packages/ThemeDefault/src/interface.latte @@ -1,10 +1,8 @@ {layout '@layout.latte'} -{var $activePage = 'interface'} {block title}Interface {$interface->getName()}{/block} {block content} -

Interface {if $interface->getNamespaceName()}{$interface->getNamespaceName()|linkAllNamespaceParts|noescape}\{/if} @@ -85,7 +83,7 @@
- # + # {$constant->getValueDefinition()|highlightValue:$interface|noescape}
@@ -110,5 +108,4 @@ {/foreach} -

{/block} diff --git a/packages/ThemeDefault/src/interfaces.latte b/packages/ThemeDefault/src/interfaces.latte new file mode 100644 index 000000000..2f219f2c8 --- /dev/null +++ b/packages/ThemeDefault/src/interfaces.latte @@ -0,0 +1,17 @@ +{layout '@layout.latte'} + +{block title}{$pageTitle}{/block} + +{block content} +

{$pageTitle}

+ + + {foreach $interfaces as $interface} + + + + {/foreach} +
+ {$interface->getName()} +
+{/block} diff --git a/packages/ThemeDefault/src/namespace.latte b/packages/ThemeDefault/src/namespace.latte index 92ecb874e..d635caa9e 100644 --- a/packages/ThemeDefault/src/namespace.latte +++ b/packages/ThemeDefault/src/namespace.latte @@ -1,10 +1,8 @@ {layout '@layout.latte'} -{var $activePage = 'namespace'} {block title}{if $activeNamespace !== 'None'}Namespace {$activeNamespace}{else}No namespace{/if}{/block} {block content} -

{if $activeNamespace !== 'None'}Namespace {$activeNamespace|linkAllNamespaceParts|noescape}{else}No namespace{/if}

{if $childNamespaces} @@ -17,5 +15,4 @@ {/if} {include '@elementlist.latte'} -
{/block} diff --git a/packages/ThemeDefault/src/namespaces.latte b/packages/ThemeDefault/src/namespaces.latte new file mode 100644 index 000000000..048e66547 --- /dev/null +++ b/packages/ThemeDefault/src/namespaces.latte @@ -0,0 +1,17 @@ +{layout '@layout.latte'} + +{block title}{$pageTitle}{/block} + +{block content} +

{$pageTitle}

+ + + {foreach $namespaces as $namespace} + + + + {/foreach} +
+ {$namespace} +
+{/block} diff --git a/packages/ThemeDefault/src/partial/constant.latte b/packages/ThemeDefault/src/partial/constant.latte index 08e22ec13..a1e358844 100644 --- a/packages/ThemeDefault/src/partial/constant.latte +++ b/packages/ThemeDefault/src/partial/constant.latte @@ -6,21 +6,25 @@ {$constant->getName()} -
- {$constant|description} - {var $filteredAnnotations = ($constant->getAnnotations()|annotationFilter: ['var'])} - {foreach $filteredAnnotations as $annotation} -

{$annotation->getName()}

-
- {$annotation|annotation:$constant|noescape}
-
- {/foreach} -
+ {var $filteredAnnotations = ($constant->getAnnotations()|annotationFilter: ['var'])} + + {if $constant->getDescription() || count($filteredAnnotations)} +
+ {$constant|description} + + {foreach $filteredAnnotations as $annotation} +

{$annotation->getName()}

+
+ {$annotation|annotation:$constant|noescape}
+
+ {/foreach} +
+ {/if}
- # + # {$constant->getValue()}
diff --git a/packages/ThemeDefault/src/partial/menu.latte b/packages/ThemeDefault/src/partial/menu.latte index 9b24e132c..3bf6718b2 100644 --- a/packages/ThemeDefault/src/partial/menu.latte +++ b/packages/ThemeDefault/src/partial/menu.latte @@ -1,32 +1,60 @@ diff --git a/packages/ThemeDefault/src/partial/property.latte b/packages/ThemeDefault/src/partial/property.latte index 3a5562309..3d0f39b39 100644 --- a/packages/ThemeDefault/src/partial/property.latte +++ b/packages/ThemeDefault/src/partial/property.latte @@ -29,7 +29,7 @@
- # + # {$property->getDefaultValueDefinition()}
diff --git a/packages/ThemeDefault/src/resources/style.css b/packages/ThemeDefault/src/resources/style.css index 51a17cea1..f94bb8978 100644 --- a/packages/ThemeDefault/src/resources/style.css +++ b/packages/ThemeDefault/src/resources/style.css @@ -17,7 +17,7 @@ h1 { } h2 { - font-size: 1em; + font-size: 1.2em; font-weight: bold; } @@ -40,6 +40,7 @@ a, td a { a:hover, a:active, a:focus, a:hover b, a:hover var { background-color: #006aeb; color: #ffffff !important; + text-decoration: none; } code, var, pre { @@ -55,50 +56,14 @@ pre { opacity: .5; } -/* Menu */ -#menu { - padding: 10px; -} - -#menu ul { - list-style: none; - padding: 0; - margin: 0; -} - -#menu ul ul { - padding-left: 10px; -} - -#menu li { - white-space: nowrap; - position: relative; -} - -#menu a { - display: block; - padding: 0 2px; -} - -#menu .active > a, #menu > span { - color: #333333; - background: none; - font-weight: bold; -} - -#menu .active > a:hover, #menu .active > a:active, #menu .active > a:focus { - background-color: #006aeb; -} - /* Search */ #search { - float: right; - margin: 3px 8px; + margin-top: .3em; + margin-bottom: -.1em; } #search input.text { - padding: 3px 5px; - width: 250px; + width: 25em; } /* Autocomplete */ @@ -148,57 +113,38 @@ pre { /* Navigation */ #navigation { - padding: .3em .7em; - background-color: #f6f6f4; - height: 30px; + background: #f6f6f4; } -#navigation ul { - list-style: none; - margin: 0 8px 4px 0; - padding: 0; - overflow: hidden; - float: left; +.navbar { + min-height: 1em; + margin-bottom: .4em; } -#navigation ul + ul { +#navigation .separator { border-left: 1px solid #000000; - padding-left: 8px; + padding: 0 .5em; } #navigation ul li { - float: left; - margin: 2px; - padding: 0 3px; + margin: .35em 0 0 0; + padding: 0 .3em; font-family: Verdana, 'Geneva CE', lucida, sans-serif; - color: #808080; -} - -#navigation ul li.active { - background-color: #053368; - color: #ffffff; - font-weight: bold; } #navigation ul li a { color: #000000; + padding: .35em .6em; font-weight: bold; - padding: 0; } -#navigation ul li span { - float: left; - padding: 0 3px; +#navigation ul li a:hover { + background: #006aeb; } -#navigation ul li a:hover span, #navigation ul li a:active span, #navigation ul li a:focus span { - background-color: #006aeb; -} - -/* Content */ -#content { - clear: both; - padding: 5px 15px; +#navigation ul li a.active { + color: white; + background: #053368; } .description pre { @@ -206,13 +152,13 @@ pre { background: #fcfcf7; } -#content > .description { +.description { background: #ecede5; padding: 1px 8px; margin: 1.2em 0; } -#content > .description pre { +.description pre { margin: .5em 0; } @@ -397,7 +343,8 @@ code { background: none; } -a:hover, a:focus { - text-decoration: none; +.form-control { + border-radius: 0; + margin-bottom: 0; + height: 2.3em; } - diff --git a/packages/ThemeDefault/src/trait.latte b/packages/ThemeDefault/src/trait.latte index 133863e23..64830a475 100644 --- a/packages/ThemeDefault/src/trait.latte +++ b/packages/ThemeDefault/src/trait.latte @@ -1,10 +1,8 @@ {layout '@layout.latte'} -{var $activePage = 'trait'} {block title}Trait {$trait->getName()}{/block} {block content} -

Trait {if $trait->getNamespaceName()}{$trait->getNamespaceName()|linkAllNamespaceParts|noescape}\{/if} @@ -62,7 +60,7 @@ {/if} - +
Methods used from {$usedTrait->getName()} trait
@@ -85,5 +83,4 @@ {/foreach}
{/if} -

{/block} diff --git a/packages/ThemeDefault/src/traits.latte b/packages/ThemeDefault/src/traits.latte new file mode 100644 index 000000000..06bcb42b2 --- /dev/null +++ b/packages/ThemeDefault/src/traits.latte @@ -0,0 +1,17 @@ +{layout '@layout.latte'} + +{block title}{$pageTitle}{/block} + +{block content} +

{$pageTitle}

+ + + {foreach $traits as $trait} + + + + {/foreach} +
+ {$trait->getName()} +
+{/block} diff --git a/src/Application/ApiGenApplication.php b/src/Application/ApiGenApplication.php index d818f983f..804da6adc 100644 --- a/src/Application/ApiGenApplication.php +++ b/src/Application/ApiGenApplication.php @@ -3,7 +3,7 @@ namespace ApiGen\Application; use ApiGen\Application\Command\RunCommand; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Contract\Generator\GeneratorQueueInterface; use ApiGen\ModularConfiguration\Option\DestinationOption; use ApiGen\ModularConfiguration\Option\OverwriteOption; @@ -14,7 +14,7 @@ final class ApiGenApplication { /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; @@ -34,7 +34,7 @@ final class ApiGenApplication private $fileSystem; public function __construct( - ConfigurationInterface $configuration, + Configuration $configuration, ParserInterface $parser, GeneratorQueueInterface $generatorQueue, FileSystem $fileSystem diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index 94349a692..ab75680d4 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -2,7 +2,6 @@ namespace ApiGen\Configuration; -use ApiGen\Contract\Configuration\ConfigurationInterface; use ApiGen\ModularConfiguration\Contract\ConfigurationResolverInterface; use ApiGen\ModularConfiguration\Option\AnnotationGroupsOption; use ApiGen\ModularConfiguration\Option\BaseUrlOption; @@ -14,7 +13,7 @@ use ApiGen\ModularConfiguration\Parameter\ParameterProvider; use ApiGen\Utils\NamingHelper; -final class Configuration implements ConfigurationInterface +final class Configuration { /** * @var mixed[] diff --git a/src/Contract/Configuration/ConfigurationInterface.php b/src/Contract/Configuration/ConfigurationInterface.php deleted file mode 100644 index e32f3776f..000000000 --- a/src/Contract/Configuration/ConfigurationInterface.php +++ /dev/null @@ -1,59 +0,0 @@ -configuration = $configuration; } diff --git a/src/Generator/AnnotationGroupsGenerator.php b/src/Generator/AnnotationGroupsGenerator.php index beb344d6e..fc8ba9660 100644 --- a/src/Generator/AnnotationGroupsGenerator.php +++ b/src/Generator/AnnotationGroupsGenerator.php @@ -2,7 +2,7 @@ namespace ApiGen\Generator; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Contract\Generator\GeneratorInterface; use ApiGen\Element\ReflectionCollector\AnnotationReflectionCollector; use ApiGen\Templating\TemplateRenderer; @@ -10,7 +10,7 @@ final class AnnotationGroupsGenerator implements GeneratorInterface { /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; @@ -25,7 +25,7 @@ final class AnnotationGroupsGenerator implements GeneratorInterface private $annotationReflectionCollector; public function __construct( - ConfigurationInterface $configuration, + Configuration $configuration, TemplateRenderer $templateRenderer, AnnotationReflectionCollector $annotationReflectionCollector ) { @@ -50,6 +50,7 @@ private function generateForAnnotation(string $annotation): void $this->configuration->getDestinationWithPrefixName('annotation-group-', $annotation), [ 'annotation' => $annotation, + 'activePage' => 'annotation-group-' . $annotation, 'hasElements' => $this->annotationReflectionCollector->hasAnyElements(), 'classes' => $this->annotationReflectionCollector->getClassReflections(), 'interfaces' => $this->annotationReflectionCollector->getInterfaceReflections(), diff --git a/src/Generator/ClassGenerator.php b/src/Generator/ClassGenerator.php index 5a670439e..9abf6b512 100644 --- a/src/Generator/ClassGenerator.php +++ b/src/Generator/ClassGenerator.php @@ -2,11 +2,11 @@ namespace ApiGen\Generator; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Contract\Generator\GeneratorInterface; -use ApiGen\SourceCodeHighlighter\SourceCodeHighlighter; use ApiGen\Reflection\Contract\Reflection\Class_\ClassReflectionInterface; use ApiGen\Reflection\Contract\ReflectionStorageInterface; +use ApiGen\SourceCodeHighlighter\SourceCodeHighlighter; use ApiGen\Templating\TemplateRenderer; final class ClassGenerator implements GeneratorInterface @@ -17,7 +17,7 @@ final class ClassGenerator implements GeneratorInterface private $reflectionStorage; /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; @@ -33,7 +33,7 @@ final class ClassGenerator implements GeneratorInterface public function __construct( ReflectionStorageInterface $reflectionStorage, - ConfigurationInterface $configuration, + Configuration $configuration, SourceCodeHighlighter $sourceCodeHighlighter, TemplateRenderer $templateRenderer ) { @@ -57,6 +57,7 @@ private function generateForClass(ClassReflectionInterface $classReflection): vo $this->configuration->getTemplateByName('class'), $this->configuration->getDestinationWithPrefixName('class-', $classReflection->getName()), [ + 'activePage' => 'class', 'class' => $classReflection, ] ); @@ -71,6 +72,7 @@ private function generateSourceCodeForClass(ClassReflectionInterface $classRefle $this->configuration->getTemplateByName('source'), $this->configuration->getDestinationWithPrefixName('source-class-', $classReflection->getName()), [ + 'activePage' => 'class', 'activeClass' => $classReflection, 'fileName' => $classReflection->getFileName(), 'source' => $highlightedContent diff --git a/src/Generator/ClassesGenerator.php b/src/Generator/ClassesGenerator.php new file mode 100644 index 000000000..1af636c19 --- /dev/null +++ b/src/Generator/ClassesGenerator.php @@ -0,0 +1,58 @@ +configuration = $configuration; + $this->templateRenderer = $templateRenderer; + $this->reflectionStorage = $reflectionStorage; + } + + public function generate(): void + { + if (count($this->reflectionStorage->getClassReflections()) < 1) { + return; + } + + $this->templateRenderer->renderToFile( + $this->configuration->getTemplateByName(self::NAME), + $this->configuration->getDestinationWithName(self::NAME), + [ + 'activePage' => self::NAME, + 'pageTitle' => ucfirst(self::NAME), + self::NAME => $this->reflectionStorage->getClassReflections() + ] + ); + } +} diff --git a/src/Generator/ElementListGenerator.php b/src/Generator/ElementListGenerator.php index 526fc64bb..dbb2241c0 100644 --- a/src/Generator/ElementListGenerator.php +++ b/src/Generator/ElementListGenerator.php @@ -2,14 +2,14 @@ namespace ApiGen\Generator; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Contract\Generator\GeneratorInterface; use ApiGen\Templating\TemplateRenderer; final class ElementListGenerator implements GeneratorInterface { /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; @@ -18,7 +18,7 @@ final class ElementListGenerator implements GeneratorInterface */ private $templateRenderer; - public function __construct(ConfigurationInterface $configuration, TemplateRenderer $templateRenderer) + public function __construct(Configuration $configuration, TemplateRenderer $templateRenderer) { $this->configuration = $configuration; $this->templateRenderer = $templateRenderer; diff --git a/src/Generator/FunctionGenerator.php b/src/Generator/FunctionGenerator.php index 3c7d529fe..8c394d1e2 100644 --- a/src/Generator/FunctionGenerator.php +++ b/src/Generator/FunctionGenerator.php @@ -2,11 +2,11 @@ namespace ApiGen\Generator; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Contract\Generator\GeneratorInterface; -use ApiGen\SourceCodeHighlighter\SourceCodeHighlighter; use ApiGen\Reflection\Contract\Reflection\Function_\FunctionReflectionInterface; use ApiGen\Reflection\Contract\ReflectionStorageInterface; +use ApiGen\SourceCodeHighlighter\SourceCodeHighlighter; use ApiGen\Templating\TemplateRenderer; use ApiGen\Utils\RelativePathResolver; @@ -18,7 +18,7 @@ final class FunctionGenerator implements GeneratorInterface private $reflectionStorage; /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; @@ -39,7 +39,7 @@ final class FunctionGenerator implements GeneratorInterface public function __construct( ReflectionStorageInterface $reflectionStorage, - ConfigurationInterface $configuration, + Configuration $configuration, SourceCodeHighlighter $sourceCodeHighlighter, TemplateRenderer $templateRenderer, RelativePathResolver $relativePathResolver @@ -65,6 +65,7 @@ private function generateForFunction(FunctionReflectionInterface $reflectionFunc $this->configuration->getTemplateByName('function'), $this->configuration->getDestinationWithPrefixName('function-', $reflectionFunction->getName()), [ + 'activePage' => 'function', 'function' => $reflectionFunction ] ); @@ -89,6 +90,7 @@ private function generateSourceCodeForFunction(FunctionReflectionInterface $func $this->configuration->getTemplateByName('source'), $destination, [ + 'activePage' => 'function', 'fileName' => $functionReflection->getFileName(), 'source' => $highlightedContent, ] diff --git a/src/Generator/FunctionsGenerator.php b/src/Generator/FunctionsGenerator.php new file mode 100644 index 000000000..f0fd0e08d --- /dev/null +++ b/src/Generator/FunctionsGenerator.php @@ -0,0 +1,58 @@ +configuration = $configuration; + $this->templateRenderer = $templateRenderer; + $this->reflectionStorage = $reflectionStorage; + } + + public function generate(): void + { + if (count($this->reflectionStorage->getFunctionReflections()) < 1) { + return; + } + + $this->templateRenderer->renderToFile( + $this->configuration->getTemplateByName(self::NAME), + $this->configuration->getDestinationWithName(self::NAME), + [ + 'activePage' => self::NAME, + 'pageTitle' => ucfirst(self::NAME), + self::NAME => $this->reflectionStorage->getFunctionReflections() + ] + ); + } +} diff --git a/src/Generator/IndexGenerator.php b/src/Generator/IndexGenerator.php index 5089ba8d7..919584c09 100644 --- a/src/Generator/IndexGenerator.php +++ b/src/Generator/IndexGenerator.php @@ -2,14 +2,14 @@ namespace ApiGen\Generator; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Contract\Generator\GeneratorInterface; use ApiGen\Templating\TemplateRenderer; final class IndexGenerator implements GeneratorInterface { /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; @@ -18,7 +18,7 @@ final class IndexGenerator implements GeneratorInterface */ private $templateRenderer; - public function __construct(ConfigurationInterface $configuration, TemplateRenderer $templateRenderer) + public function __construct(Configuration $configuration, TemplateRenderer $templateRenderer) { $this->configuration = $configuration; $this->templateRenderer = $templateRenderer; @@ -28,7 +28,10 @@ public function generate(): void { $this->templateRenderer->renderToFile( $this->configuration->getTemplateByName('index'), - $this->configuration->getDestinationWithName('index') + $this->configuration->getDestinationWithName('index'), + [ + 'activePage' => 'overview' + ] ); } } diff --git a/src/Generator/InterfaceGenerator.php b/src/Generator/InterfaceGenerator.php index 572280e8f..57d999d0f 100644 --- a/src/Generator/InterfaceGenerator.php +++ b/src/Generator/InterfaceGenerator.php @@ -2,11 +2,11 @@ namespace ApiGen\Generator; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Contract\Generator\GeneratorInterface; -use ApiGen\SourceCodeHighlighter\SourceCodeHighlighter; use ApiGen\Reflection\Contract\Reflection\Interface_\InterfaceReflectionInterface; use ApiGen\Reflection\Contract\ReflectionStorageInterface; +use ApiGen\SourceCodeHighlighter\SourceCodeHighlighter; use ApiGen\Templating\TemplateRenderer; final class InterfaceGenerator implements GeneratorInterface @@ -17,7 +17,7 @@ final class InterfaceGenerator implements GeneratorInterface private $reflectionStorage; /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; @@ -33,7 +33,7 @@ final class InterfaceGenerator implements GeneratorInterface public function __construct( ReflectionStorageInterface $reflectionStorage, - ConfigurationInterface $configuration, + Configuration $configuration, SourceCodeHighlighter $sourceCodeHighlighter, TemplateRenderer $templateRenderer ) { @@ -57,6 +57,7 @@ private function generateForInterface(InterfaceReflectionInterface $interfaceRef $this->configuration->getTemplateByName('interface'), $this->configuration->getDestinationWithPrefixName('interface-', $interfaceReflection->getName()), [ + 'activePage' => 'interface', 'interface' => $interfaceReflection, ] ); @@ -75,6 +76,7 @@ private function generateSourceCodeForInterface(InterfaceReflectionInterface $in $this->configuration->getTemplateByName('source'), $destination, [ + 'activePage' => 'interface', 'fileName' => $interfaceReflection->getFileName(), 'source' => $highlightedContent, ] diff --git a/src/Generator/InterfacesGenerator.php b/src/Generator/InterfacesGenerator.php new file mode 100644 index 000000000..83a8f64e3 --- /dev/null +++ b/src/Generator/InterfacesGenerator.php @@ -0,0 +1,58 @@ +configuration = $configuration; + $this->templateRenderer = $templateRenderer; + $this->reflectionStorage = $reflectionStorage; + } + + public function generate(): void + { + if (count($this->reflectionStorage->getInterfaceReflections()) < 1) { + return; + } + + $this->templateRenderer->renderToFile( + $this->configuration->getTemplateByName(self::NAME), + $this->configuration->getDestinationWithName(self::NAME), + [ + 'activePage' => self::NAME, + 'pageTitle' => ucfirst(self::NAME), + self::NAME => $this->reflectionStorage->getInterfaceReflections() + ] + ); + } +} diff --git a/src/Generator/NamespaceGenerator.php b/src/Generator/NamespaceGenerator.php index d4dd6ebd7..52193256b 100644 --- a/src/Generator/NamespaceGenerator.php +++ b/src/Generator/NamespaceGenerator.php @@ -2,7 +2,7 @@ namespace ApiGen\Generator; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Contract\Generator\GeneratorInterface; use ApiGen\Element\Namespaces\NamespaceStorage; use ApiGen\Element\Namespaces\SingleNamespaceStorage; @@ -11,7 +11,7 @@ final class NamespaceGenerator implements GeneratorInterface { /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; @@ -26,7 +26,7 @@ final class NamespaceGenerator implements GeneratorInterface public function __construct( NamespaceStorage $namespaceStorage, - ConfigurationInterface $configuration, + Configuration $configuration, TemplateRenderer $templateRenderer ) { $this->namespaceStorage = $namespaceStorage; @@ -53,6 +53,7 @@ private function generateForNamespace(SingleNamespaceStorage $singleNamespaceSto 'namespace-', $singleNamespaceStorage->getNamespace() ), [ + 'activePage' => 'namespace', 'activeNamespace' => $singleNamespaceStorage->getNamespace(), 'childNamespaces' => $this->resolveChildNamespaces($singleNamespaceStorage->getNamespace()), 'classes' => $singleNamespaceStorage->getClassReflections(), diff --git a/src/Generator/NamespacesGenerator.php b/src/Generator/NamespacesGenerator.php new file mode 100644 index 000000000..111e0e65b --- /dev/null +++ b/src/Generator/NamespacesGenerator.php @@ -0,0 +1,57 @@ +namespaceStorage = $namespaceStorage; + $this->configuration = $configuration; + $this->templateRenderer = $templateRenderer; + } + + public function generate(): void + { + if (count($this->namespaceStorage->getNamespaces()) < 1) { + return; + } + + $this->templateRenderer->renderToFile( + $this->configuration->getTemplateByName(self::NAME), + $this->configuration->getDestinationWithName(self::NAME), + [ + 'activePage' => self::NAME, + 'pageTitle' => ucfirst(self::NAME), + self::NAME => $this->namespaceStorage->getNamespaces() + ] + ); + } +} diff --git a/src/Generator/TraitGenerator.php b/src/Generator/TraitGenerator.php index 0279132da..a46c86c27 100644 --- a/src/Generator/TraitGenerator.php +++ b/src/Generator/TraitGenerator.php @@ -2,11 +2,11 @@ namespace ApiGen\Generator; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Contract\Generator\GeneratorInterface; -use ApiGen\SourceCodeHighlighter\SourceCodeHighlighter; use ApiGen\Reflection\Contract\Reflection\Trait_\TraitReflectionInterface; use ApiGen\Reflection\Contract\ReflectionStorageInterface; +use ApiGen\SourceCodeHighlighter\SourceCodeHighlighter; use ApiGen\Templating\TemplateRenderer; final class TraitGenerator implements GeneratorInterface @@ -17,7 +17,7 @@ final class TraitGenerator implements GeneratorInterface private $reflectionStorage; /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; @@ -33,7 +33,7 @@ final class TraitGenerator implements GeneratorInterface public function __construct( ReflectionStorageInterface $reflectionStorage, - ConfigurationInterface $configuration, + Configuration $configuration, SourceCodeHighlighter $sourceCodeHighlighter, TemplateRenderer $templateRenderer ) { @@ -57,6 +57,7 @@ private function generateForTrait(TraitReflectionInterface $traitReflection): vo $this->configuration->getTemplateByName('trait'), $this->configuration->getDestinationWithPrefixName('trait-',$traitReflection->getName()), [ + 'activePage' => 'trait', 'trait' => $traitReflection, ] ); @@ -73,6 +74,7 @@ private function generateSourceCodeForTrait(TraitReflectionInterface $traitRefle $this->configuration->getTemplateByName('source'), $destination, [ + 'activePage' => 'trait', 'fileName' => $traitReflection->getFileName(), 'source' => $highlightedContent, ] diff --git a/src/Generator/TraitsGenerator.php b/src/Generator/TraitsGenerator.php new file mode 100644 index 000000000..190b2274c --- /dev/null +++ b/src/Generator/TraitsGenerator.php @@ -0,0 +1,58 @@ +configuration = $configuration; + $this->templateRenderer = $templateRenderer; + $this->reflectionStorage = $reflectionStorage; + } + + public function generate(): void + { + if (count($this->reflectionStorage->getTraitReflections()) < 1) { + return; + } + + $this->templateRenderer->renderToFile( + $this->configuration->getTemplateByName(self::NAME), + $this->configuration->getDestinationWithName(self::NAME), + [ + 'activePage' => self::NAME, + 'pageTitle' => ucfirst(self::NAME), + self::NAME => $this->reflectionStorage->getTraitReflections() + ] + ); + } +} diff --git a/src/Utils/RelativePathResolver.php b/src/Utils/RelativePathResolver.php index 13bb6c5fd..09db90c9e 100644 --- a/src/Utils/RelativePathResolver.php +++ b/src/Utils/RelativePathResolver.php @@ -2,13 +2,13 @@ namespace ApiGen\Utils; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use InvalidArgumentException; final class RelativePathResolver { /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; @@ -17,7 +17,7 @@ final class RelativePathResolver */ private $fileSystem; - public function __construct(ConfigurationInterface $configuration, FileSystem $fileSystem) + public function __construct(Configuration $configuration, FileSystem $fileSystem) { $this->configuration = $configuration; $this->fileSystem = $fileSystem; diff --git a/src/config/services.neon b/src/config/services.neon index 65eea5a73..e382f71fe 100644 --- a/src/config/services.neon +++ b/src/config/services.neon @@ -27,6 +27,12 @@ - ApiGen\Generator\TraitGenerator - ApiGen\Generator\FunctionGenerator +- ApiGen\Generator\InterfacesGenerator +- ApiGen\Generator\FunctionsGenerator +- ApiGen\Generator\TraitsGenerator +- ApiGen\Generator\ClassesGenerator +- ApiGen\Generator\NamespacesGenerator + # Templating - ApiGen\Templating\TemplateRenderer - ApiGen\EventSubscriber\ConfigurationTemplateVariablesEventSubscriber diff --git a/tests/AbstractContainerAwareTestCase.php b/tests/AbstractContainerAwareTestCase.php index 345ae4dbd..0d4b623a0 100644 --- a/tests/AbstractContainerAwareTestCase.php +++ b/tests/AbstractContainerAwareTestCase.php @@ -2,7 +2,7 @@ namespace ApiGen\Tests; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\DI\Container\ContainerFactory; use ApiGen\ModularConfiguration\Option\DestinationOption; use ApiGen\ModularConfiguration\Option\SourceOption; @@ -16,16 +16,6 @@ abstract class AbstractContainerAwareTestCase extends TestCase */ protected $container; - /** - * @var string - */ - protected $sourceDir; - - /** - * @var string - */ - protected $destinationDir; - /** * @param mixed[] $data */ @@ -35,10 +25,7 @@ public function __construct(?string $name = null, array $data = [], string $data $this->container = (new ContainerFactory)->create(); -// $this->sourceDir = $this->container->getParameters()['appDir'] . '/Project'; -// $this->destinationDir = $this->container->getParameters()['tempDir'] . '/api'; - - $configuration = $this->container->getByType(ConfigurationInterface::class); + $configuration = $this->container->getByType(Configuration::class); $configuration->resolveOptions([ SourceOption::NAME => [__DIR__], DestinationOption::NAME => TEMP_DIR, diff --git a/tests/AbstractParserAwareTestCase.php b/tests/AbstractParserAwareTestCase.php index 2c505397d..ef219fa81 100644 --- a/tests/AbstractParserAwareTestCase.php +++ b/tests/AbstractParserAwareTestCase.php @@ -2,7 +2,7 @@ namespace ApiGen\Tests; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\DI\Container\ContainerFactory; use ApiGen\ModularConfiguration\Option\DestinationOption; use ApiGen\ModularConfiguration\Option\SourceOption; @@ -10,8 +10,6 @@ use ApiGen\Reflection\Contract\ReflectionStorageInterface; use Nette\DI\Container; use PHPUnit\Framework\TestCase; -use Symplify\EasyCodingStandard\Configuration\ConfigurationNormalizer; -use Symplify\EasyCodingStandard\Configuration\ConfigurationOptions; abstract class AbstractParserAwareTestCase extends TestCase { @@ -39,8 +37,8 @@ public function __construct(?string $name = null, array $data = [], string $data $this->container = (new ContainerFactory)->create(); - /** @var ConfigurationInterface $configuration */ - $configuration = $this->container->getByType(ConfigurationInterface::class); + /** @var Configuration $configuration */ + $configuration = $this->container->getByType(Configuration::class); $configuration->resolveOptions([ SourceOption::NAME => [__DIR__], DestinationOption::NAME => TEMP_DIR diff --git a/tests/Configuration/ConfigurationTest.php b/tests/Configuration/ConfigurationTest.php index 072b89f4c..ef29291ff 100644 --- a/tests/Configuration/ConfigurationTest.php +++ b/tests/Configuration/ConfigurationTest.php @@ -2,7 +2,7 @@ namespace ApiGen\Tests\Configuration; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\ModularConfiguration\Exception\ConfigurationException; use ApiGen\ModularConfiguration\Option\AnnotationGroupsOption; use ApiGen\ModularConfiguration\Option\BaseUrlOption; @@ -17,13 +17,13 @@ final class ConfigurationTest extends AbstractContainerAwareTestCase { /** - * @var ConfigurationInterface + * @var Configuration */ private $configuration; protected function setUp(): void { - $this->configuration = $this->container->getByType(ConfigurationInterface::class); + $this->configuration = $this->container->getByType(Configuration::class); } public function testResolve(): void diff --git a/tests/Generator/AnnotationGroupsGeneratorTest.php b/tests/Generator/AnnotationGroupsGeneratorTest.php index 40f2308fe..44858bdd9 100644 --- a/tests/Generator/AnnotationGroupsGeneratorTest.php +++ b/tests/Generator/AnnotationGroupsGeneratorTest.php @@ -2,7 +2,7 @@ namespace ApiGen\Tests\Generator; -use ApiGen\Contract\Configuration\ConfigurationInterface; +use ApiGen\Configuration\Configuration; use ApiGen\Generator\AnnotationGroupsGenerator; use ApiGen\Reflection\Contract\ParserInterface; use ApiGen\Tests\AbstractContainerAwareTestCase; @@ -18,8 +18,8 @@ final class AnnotationGroupsGeneratorTest extends AbstractContainerAwareTestCase protected function setUp(): void { - /** @var ConfigurationInterface $configuration */ - $configuration = $this->container->getByType(ConfigurationInterface::class); + /** @var Configuration $configuration */ + $configuration = $this->container->getByType(Configuration::class); $configuration->resolveOptions([ 'source' => [TEMP_DIR], 'destination' => TEMP_DIR, diff --git a/tests/Generator/ClassesGeneratorTest.php b/tests/Generator/ClassesGeneratorTest.php new file mode 100644 index 000000000..fc16ebf42 --- /dev/null +++ b/tests/Generator/ClassesGeneratorTest.php @@ -0,0 +1,23 @@ +container->getByType(ParserInterface::class); + $parser->parseDirectories([__DIR__ . '/Source']); + + /** @var ClassesGenerator $classesGenerator */ + $classesGenerator = $this->container->getByType(ClassesGenerator::class); + $classesGenerator->generate(); + + $this->assertFileExists(TEMP_DIR . '/classes.html'); + } +} diff --git a/tests/Generator/FunctionsGeneratorTest.php b/tests/Generator/FunctionsGeneratorTest.php new file mode 100644 index 000000000..6d87bbd72 --- /dev/null +++ b/tests/Generator/FunctionsGeneratorTest.php @@ -0,0 +1,23 @@ +container->getByType(ParserInterface::class); + $parser->parseDirectories([__DIR__ . '/Source']); + + /** @var FunctionsGenerator $functionsGenerator */ + $functionsGenerator = $this->container->getByType(FunctionsGenerator::class); + $functionsGenerator->generate(); + + $this->assertFileExists(TEMP_DIR . '/functions.html'); + } +} diff --git a/tests/Generator/InterfacesGeneratorTest.php b/tests/Generator/InterfacesGeneratorTest.php new file mode 100644 index 000000000..b68ec479f --- /dev/null +++ b/tests/Generator/InterfacesGeneratorTest.php @@ -0,0 +1,23 @@ +container->getByType(ParserInterface::class); + $parser->parseDirectories([__DIR__ . '/Source']); + + /** @var InterfacesGenerator $interfacesGenerator */ + $interfacesGenerator = $this->container->getByType(InterfacesGenerator::class); + $interfacesGenerator->generate(); + + $this->assertFileExists(TEMP_DIR . '/interfaces.html'); + } +} diff --git a/tests/Generator/NamespacesGeneratorTest.php b/tests/Generator/NamespacesGeneratorTest.php new file mode 100644 index 000000000..677d9eaf0 --- /dev/null +++ b/tests/Generator/NamespacesGeneratorTest.php @@ -0,0 +1,23 @@ +container->getByType(ParserInterface::class); + $parser->parseDirectories([__DIR__ . '/Source']); + + /** @var NamespacesGenerator $namespacesGenerator */ + $namespacesGenerator = $this->container->getByType(NamespacesGenerator::class); + $namespacesGenerator->generate(); + + $this->assertFileExists(TEMP_DIR . '/namespaces.html'); + } +} diff --git a/tests/Generator/TraitsGeneratorTest.php b/tests/Generator/TraitsGeneratorTest.php new file mode 100644 index 000000000..1625d0cab --- /dev/null +++ b/tests/Generator/TraitsGeneratorTest.php @@ -0,0 +1,23 @@ +container->getByType(ParserInterface::class); + $parser->parseDirectories([__DIR__ . '/Source']); + + /** @var TraitsGenerator $traitsGenerator */ + $traitsGenerator = $this->container->getByType(TraitsGenerator::class); + $traitsGenerator->generate(); + + $this->assertFileExists(TEMP_DIR . '/traits.html'); + } +} diff --git a/tests/Utils/RelativePathResolverTest.php b/tests/Utils/RelativePathResolverTest.php index 57abe0ba1..d298fdcb0 100644 --- a/tests/Utils/RelativePathResolverTest.php +++ b/tests/Utils/RelativePathResolverTest.php @@ -2,70 +2,55 @@ namespace ApiGen\Tests\Generator\Resolvers; -use ApiGen\Contract\Configuration\ConfigurationInterface; -use ApiGen\Utils\FileSystem; +use ApiGen\Configuration\Configuration; +use ApiGen\ModularConfiguration\Option\DestinationOption; +use ApiGen\ModularConfiguration\Option\SourceOption; +use ApiGen\Tests\AbstractContainerAwareTestCase; use ApiGen\Utils\RelativePathResolver; use InvalidArgumentException; -use PHPUnit\Framework\TestCase; -final class RelativePathResolverTest extends TestCase +final class RelativePathResolverTest extends AbstractContainerAwareTestCase { - public function testGetRelativePath(): void + /** + * @var Configuration + */ + private $configuration; + + /** + * @var RelativePathResolver + */ + private $relativePathResolver; + + protected function setUp(): void { - $configurationMock = $this->createMock(ConfigurationInterface::class); - $configurationMock->method('getSource') - ->willReturn([TEMP_DIR]); + $this->configuration = $this->container->getByType(Configuration::class); + $this->relativePathResolver = $this->container->getByType(RelativePathResolver::class); + } - $relativePathResolver = new RelativePathResolver($configurationMock, new FileSystem); + public function testGetRelativePath(): void + { + $this->configuration->resolveOptions([ + DestinationOption::NAME => TEMP_DIR, + SourceOption::NAME => [TEMP_DIR] + ]); - $this->assertSame('some-file.txt', $relativePathResolver->getRelativePath(TEMP_DIR . '/some-file.txt')); + $this->assertSame('some-file.txt', $this->relativePathResolver->getRelativePath(TEMP_DIR . '/some-file.txt')); $testPath = 'some' .DIRECTORY_SEPARATOR. 'dir' .DIRECTORY_SEPARATOR. 'file.txt'; $this->assertSame( $testPath, - $relativePathResolver->getRelativePath(TEMP_DIR . DIRECTORY_SEPARATOR . $testPath) + $this->relativePathResolver->getRelativePath(TEMP_DIR . DIRECTORY_SEPARATOR . $testPath) ); } - public function testGetRelativePathWithWindowsPath(): void - { - $configurationMock = $this->createMock(ConfigurationInterface::class); - $configurationMock->method('getSource') - ->willReturn(['C:\some\dir']); - $relativePathResolver = new RelativePathResolver($configurationMock, new FileSystem); - $this->assertSame('file.txt', $relativePathResolver->getRelativePath('C:\some\dir\file.txt')); - $this->assertSame( - 'more-dir' . DIRECTORY_SEPARATOR . 'file.txt', - $relativePathResolver->getRelativePath('C:\some\dir\more-dir\file.txt')); - } - public function testGetRelativePathInvalid(): void { - $configurationMock = $this->createMock(ConfigurationInterface::class); - $configurationMock->method('getSource') - ->willReturn([TEMP_DIR]); - $relativePathResolver = new RelativePathResolver($configurationMock, new FileSystem); - + $this->configuration->resolveOptions([ + DestinationOption::NAME => TEMP_DIR, + SourceOption::NAME => [TEMP_DIR] + ]); $this->expectException(InvalidArgumentException::class); - $relativePathResolver->getRelativePath('/var/dir/some-strange-file.txt'); - } - - /** - * Issue #408 - */ - public function testGetRelativePathWithSourceEndingSlash(): void - { - $configurationMock = $this->createMock(ConfigurationInterface::class); - $configurationMock->method('getSource') - ->willReturn(['ProjectBeta']); - - $relativePathResolver = new RelativePathResolver($configurationMock, new FileSystem); - $fileName = 'ProjectBeta/entities/Category.php'; - - $this->assertSame( - 'entities' . DIRECTORY_SEPARATOR . 'Category.php', - $relativePathResolver->getRelativePath($fileName) - ); + $this->relativePathResolver->getRelativePath('/var/dir/some-strange-file.txt'); } }