Skip to content

Commit 8b9f642

Browse files
committed
tests: overed with tests import loader
1 parent 91ebc16 commit 8b9f642

33 files changed

+2004
-286
lines changed

context.yaml

Lines changed: 23 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import:
2-
- path: src/**/context.yaml
3-
- path: src/ConfigLoader/context.yaml
2+
- path: src/*/context.yaml
43

54
documents:
65
- description: "Context Generator Project Structure"
@@ -55,117 +54,11 @@ documents:
5554
- 'FilesInterface.php'
5655
showTreeView: true
5756

58-
- description: Document Compilation System
59-
outputPath: core/document.md
57+
- description: Config parser
58+
outputPath: core/config-parser.md
6059
sources:
6160
- type: file
62-
sourcePaths: src/Document
63-
contains:
64-
- implements
65-
66-
- description: Source Implementations - File
67-
outputPath: sources/file-source.md
68-
sources:
69-
- type: file
70-
sourcePaths: src/Source/File
71-
filePattern: '*.php'
72-
showTreeView: true
73-
74-
- description: Source Implementations - GitHub
75-
outputPath: sources/github-source.md
76-
sources:
77-
- type: file
78-
sourcePaths: src/Source/Github
79-
filePattern: '*.php'
80-
showTreeView: true
81-
82-
- description: Source Implementations - URL
83-
outputPath: sources/url-source.md
84-
sources:
85-
- type: file
86-
sourcePaths: src/Source/Url
87-
filePattern: '*.php'
88-
showTreeView: true
89-
90-
- description: Source Implementations - Text
91-
outputPath: sources/text-source.md
92-
sources:
93-
- type: file
94-
sourcePaths: src/Source/Text
95-
filePattern: '*.php'
96-
showTreeView: true
97-
98-
- description: Source Implementations - Git Diff
99-
outputPath: sources/git-diff-source.md
100-
sources:
101-
- type: file
102-
sourcePaths: src/Source/GitDiff
103-
filePattern: '*.php'
104-
showTreeView: true
105-
106-
- description: Source Implementations - Composer
107-
outputPath: sources/composer-source.md
108-
sources:
109-
- type: file
110-
sourcePaths: src/Source/Composer
111-
filePattern: '*.php'
112-
showTreeView: true
113-
114-
- description: Source Implementations - Tree
115-
outputPath: sources/tree-source.md
116-
sources:
117-
- type: file
118-
sourcePaths: src/Source/Tree
119-
filePattern: '*.php'
120-
showTreeView: true
121-
122-
- description: Modifiers System
123-
outputPath: modifiers/modifiers-core.md
124-
sources:
125-
- type: file
126-
sourcePaths: src/Modifier
127-
filePattern:
128-
- '*.php'
129-
- 'Alias/*.php'
130-
notPath:
131-
- 'PhpContentFilter.php'
132-
- 'PhpSignature.php'
133-
- 'ContextSanitizerModifier.php'
134-
showTreeView: true
135-
136-
- description: PHP Content Modifiers
137-
outputPath: modifiers/php-modifiers.md
138-
sources:
139-
- type: file
140-
sourcePaths: src/Modifier
141-
filePattern:
142-
- 'PhpContentFilter.php'
143-
- 'PhpSignature.php'
144-
showTreeView: true
145-
146-
- description: Sanitizer Modifier
147-
outputPath: modifiers/sanitizer.md
148-
sources:
149-
- type: file
150-
sourcePaths:
151-
- src/Modifier/ContextSanitizerModifier.php
152-
- src/Lib/Sanitizer
153-
filePattern: '*.php'
154-
showTreeView: true
155-
156-
- description: Content Building System
157-
outputPath: utilities/content-builder.md
158-
sources:
159-
- type: file
160-
sourcePaths: src/Lib/Content
161-
filePattern: '*.php'
162-
showTreeView: true
163-
164-
- description: Content Block Types
165-
outputPath: utilities/content-blocks.md
166-
sources:
167-
- type: file
168-
sourcePaths: src/Lib/Content/Block
61+
sourcePaths: src/ConfigLoader
16962
filePattern: '*.php'
17063
showTreeView: true
17164

@@ -197,7 +90,9 @@ documents:
19790
outputPath: utilities/github-client.md
19891
sources:
19992
- type: file
200-
sourcePaths: src/Lib/GithubClient
93+
sourcePaths:
94+
- src/Lib/GithubClient
95+
- src/GithubClientFactory.php
20196
filePattern: '*.php'
20297
showTreeView: true
20398

@@ -232,22 +127,6 @@ documents:
232127
sourcePaths:
233128
- tests
234129

235-
- description: "MCP Server Actions"
236-
outputPath: "mcp/actions.md"
237-
sources:
238-
- type: file
239-
sourcePaths:
240-
- src/McpServer/Action
241-
242-
- description: "MCP Server routing"
243-
outputPath: "mcp/routing.md"
244-
sources:
245-
- type: file
246-
sourcePaths:
247-
- src/McpServer/Routing
248-
- src/McpServer/Server.php
249-
- src/McpServer/ServerFactory.php
250-
251130
- description: "Changes in the Project"
252131
outputPath: "changes.md"
253132
sources:
@@ -256,13 +135,25 @@ documents:
256135

257136
- description: Import documents docs
258137
outputPath: docs/import-docs.md
138+
overwrite: false
259139
sources:
260140
- type: file
261141
sourcePaths:
262142
- src/ConfigLoader/Import
143+
- tests/src/ConfigLoader/Import
144+
- tests/fixtures/ConfigLoader
263145
showTreeView: true
264-
- type: github
265-
repository: context-hub/docs
266-
branch: main
146+
147+
- description: Directories using
148+
outputPath: docs/dirs.md
149+
modifiers:
150+
- name: php-content-filter
151+
options:
152+
keep_doc_comments: false
153+
sources:
154+
- type: file
267155
sourcePaths:
268-
- docs/configuration.md
156+
- src
157+
showTreeView: true
158+
contains:
159+
- Directories

src/ConfigLoader/ConfigLoaderFactory.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Butschster\ContextGenerator\ConfigLoader\Import\ImportResolver;
99
use Butschster\ContextGenerator\ConfigLoader\Parser\CompositeConfigParser;
1010
use Butschster\ContextGenerator\ConfigLoader\Parser\ConfigParser;
11-
use Butschster\ContextGenerator\ConfigLoader\Parser\ConfigParserPluginInterface;
1211
use Butschster\ContextGenerator\ConfigLoader\Parser\ImportParserPlugin;
1312
use Butschster\ContextGenerator\ConfigLoader\Reader\JsonReader;
1413
use Butschster\ContextGenerator\ConfigLoader\Reader\PhpReader;
@@ -22,20 +21,14 @@
2221
/**
2322
* Factory for creating config loaders
2423
*/
25-
final readonly class ConfigLoaderFactory
24+
final readonly class ConfigLoaderFactory implements ConfigLoaderFactoryInterface
2625
{
2726
public function __construct(
2827
private FilesInterface $files,
2928
private Directories $dirs,
3029
private ?LoggerInterface $logger = null,
3130
) {}
3231

33-
/**
34-
* Create a loader for a specific config file
35-
*
36-
* @param array<ConfigParserPluginInterface> $parserPlugins Plugins for the config parser
37-
* @return ConfigLoaderInterface The config loader
38-
*/
3932
public function create(Directories $dirs, array $parserPlugins = []): ConfigLoaderInterface
4033
{
4134
\assert($this->logger instanceof HasPrefixLoggerInterface);
@@ -115,7 +108,6 @@ public function create(Directories $dirs, array $parserPlugins = []): ConfigLoad
115108
);
116109
}
117110

118-
// Add a new method to ConfigLoaderFactory to create a loader for a specific file path
119111
public function createForFile(Directories $dirs, array $parserPlugins = []): ConfigLoaderInterface
120112
{
121113
\assert($this->logger instanceof HasPrefixLoggerInterface);
@@ -172,13 +164,6 @@ public function createForFile(Directories $dirs, array $parserPlugins = []): Con
172164
);
173165
}
174166

175-
/**
176-
* Create a loader for an inline JSON configuration string
177-
*
178-
* @param string $jsonConfig The JSON configuration string
179-
* @param array<ConfigParserPluginInterface> $parserPlugins Plugins for the config parser
180-
* @return ConfigLoaderInterface The config loader
181-
*/
182167
public function createFromString(string $jsonConfig, array $parserPlugins = []): ConfigLoaderInterface
183168
{
184169
\assert($this->logger instanceof HasPrefixLoggerInterface);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Butschster\ContextGenerator\ConfigLoader;
6+
7+
use Butschster\ContextGenerator\ConfigLoader\Parser\ConfigParserPluginInterface;
8+
use Butschster\ContextGenerator\Directories;
9+
10+
/**
11+
* Interface for factories that create config loaders
12+
*/
13+
interface ConfigLoaderFactoryInterface
14+
{
15+
/**
16+
* Create a loader for a specific config file
17+
*
18+
* @param array<ConfigParserPluginInterface> $parserPlugins Plugins for the config parser
19+
* @return ConfigLoaderInterface The config loader
20+
*/
21+
public function create(Directories $dirs, array $parserPlugins = []): ConfigLoaderInterface;
22+
23+
/**
24+
* Create a loader for a specific file path
25+
*
26+
* @param array<ConfigParserPluginInterface> $parserPlugins Plugins for the config parser
27+
* @return ConfigLoaderInterface The config loader
28+
*/
29+
public function createForFile(Directories $dirs, array $parserPlugins = []): ConfigLoaderInterface;
30+
31+
/**
32+
* Create a loader for an inline JSON configuration string
33+
*
34+
* @param string $jsonConfig The JSON configuration string
35+
* @param array<ConfigParserPluginInterface> $parserPlugins Plugins for the config parser
36+
* @return ConfigLoaderInterface The config loader
37+
*/
38+
public function createFromString(string $jsonConfig, array $parserPlugins = []): ConfigLoaderInterface;
39+
}

src/ConfigLoader/ConfigurationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
final readonly class ConfigurationProvider
1616
{
1717
public function __construct(
18-
private ConfigLoaderFactory $loaderFactory,
18+
private ConfigLoaderFactoryInterface $loaderFactory,
1919
private FilesInterface $files,
2020
private Directories $dirs,
2121
private ?LoggerInterface $logger = null,

src/ConfigLoader/Import/CircularImportDetector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Detects circular dependencies in imports
99
*/
10-
final class CircularImportDetector
10+
final class CircularImportDetector implements CircularImportDetectorInterface
1111
{
1212
/**
1313
* @var array<string> Stack of import paths being processed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Butschster\ContextGenerator\ConfigLoader\Import;
6+
7+
/**
8+
* Interface for detecting circular dependencies in imports
9+
*/
10+
interface CircularImportDetectorInterface
11+
{
12+
/**
13+
* Check if adding this path would create a circular dependency
14+
*/
15+
public function wouldCreateCircularDependency(string $path): bool;
16+
17+
/**
18+
* Begin processing an import path
19+
*/
20+
public function beginProcessing(string $path): void;
21+
22+
/**
23+
* Finish processing an import path
24+
*/
25+
public function endProcessing(string $path): void;
26+
}

src/ConfigLoader/Import/ImportConfig.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,47 @@
99
*/
1010
final readonly class ImportConfig
1111
{
12+
/**
13+
* Creates a new ImportConfig instance.
14+
*
15+
* @param string $path The path to the configuration file to import
16+
* @param string $absolutePath The resolved absolute path to the import file
17+
* @param string|null $pathPrefix An optional prefix to add to the output path for documents from this import
18+
* @param bool $hasWildcard Whether the path contains wildcard characters for pattern matching
19+
*/
1220
public function __construct(
1321
public string $path,
1422
public string $absolutePath,
1523
public ?string $pathPrefix = null,
1624
public bool $hasWildcard = false,
1725
) {}
1826

27+
public function configDirectory(bool $absolute = false): string
28+
{
29+
return \dirname($absolute ? $this->absolutePath : $this->path);
30+
}
31+
1932
/**
2033
* Create from an array configuration
34+
*
35+
* Example:
36+
* ```php
37+
* // Simple import with no prefix
38+
* $config = ImportConfig::fromArray(['path' => 'configs/api.json'], '/app');
39+
*
40+
* // Import with output path prefix
41+
* $config = ImportConfig::fromArray(
42+
* ['path' => 'configs/api.json', 'pathPrefix' => 'api/v1'],
43+
* '/app'
44+
* );
45+
*
46+
* // With this configuration, documents from api.json will be
47+
* // generated with the path prefix 'api/v1/' in the output directory
48+
* ```
49+
*
50+
* @param array $config Import configuration array with 'path' and optional 'pathPrefix'
51+
* @param string $basePath Base path for resolving relative import paths
52+
* @throws \InvalidArgumentException If required 'path' property is missing
2153
*/
2254
public static function fromArray(array $config, string $basePath): self
2355
{
@@ -26,6 +58,9 @@ public static function fromArray(array $config, string $basePath): self
2658
throw new \InvalidArgumentException("Import configuration must have a 'path' property");
2759
}
2860
$path = $config['path'];
61+
62+
// The pathPrefix is used to specify a subdirectory in the output path
63+
// where documents from this import should be generated
2964
$pathPrefix = $config['pathPrefix'] ?? null;
3065

3166
// Check if the path contains wildcards

0 commit comments

Comments
 (0)