Skip to content

Commit ecc8909

Browse files
authored
Merge pull request #155 from context-hub/maintenance/feature-tests
tests: added feature tests for document compiler
2 parents 50be967 + 4afebaa commit ecc8909

File tree

62 files changed

+585
-96
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+585
-96
lines changed

src/Application/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
use Spiral\Boot\AbstractKernel;
3434
use Spiral\Boot\Exception\BootException;
3535

36-
final class Kernel extends AbstractKernel
36+
class Kernel extends AbstractKernel
3737
{
3838
#[\Override]
3939
protected function defineSystemBootloaders(): array

src/Document/Compiler/DocumentCompiler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Butschster\ContextGenerator\Document\Compiler;
66

7+
use Butschster\ContextGenerator\Application\FSPath;
78
use Butschster\ContextGenerator\Application\Logger\LoggerPrefix;
89
use Butschster\ContextGenerator\Document\Compiler\Error\ErrorCollection;
910
use Butschster\ContextGenerator\Document\Compiler\Error\SourceError;
@@ -50,7 +51,7 @@ public function compile(Document $document): CompiledDocument
5051
]);
5152

5253
$errors = new ErrorCollection();
53-
$resultPath = \rtrim($this->basePath, '/') . '/' . \ltrim($outputPath, '/');
54+
$resultPath = (string) FSPath::create($this->basePath)->join($outputPath);
5455

5556
if (!$document->overwrite && $this->files->exists($resultPath)) {
5657
$this->logger?->notice('Document already exists and overwrite is disabled', [

src/Lib/Content/ContentBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,6 @@ public function build(): string
168168

169169
public function __toString(): string
170170
{
171-
return $this->build();
171+
return (string) \preg_replace("/(\r\n|\n)+$/", '', $this->build());
172172
}
173173
}

src/Lib/Content/Renderer/AbstractRenderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function renderContent(array $blocks): string
2020
continue;
2121
}
2222

23-
$content .= $block->render($this);
23+
$content .= \preg_replace("/(\r\n|\n)+$/", "\n", $block->render($this));
2424
}
2525

2626
return $content;

tests/fixtures/Compiler/context.json

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/context-hub/generator/refs/heads/main/json-schema.json",
3+
"documents": [
4+
{
5+
"description": "Project structure",
6+
"outputPath": "structure.md",
7+
"sources": [
8+
{
9+
"type": "tree",
10+
"sourcePaths": [
11+
"src"
12+
],
13+
"showCharCount": true,
14+
"showSize": true
15+
}
16+
]
17+
},
18+
{
19+
"description": "This is a test document",
20+
"outputPath": "test-document.md",
21+
"sources": [
22+
{
23+
"type": "file",
24+
"sourcePaths": [
25+
"src/dir1"
26+
],
27+
"filePattern": "*.php"
28+
},
29+
{
30+
"type": "text",
31+
"content": "Foo Bar"
32+
}
33+
]
34+
},
35+
{
36+
"description": "This is a test document 1",
37+
"outputPath": "test-document1.md",
38+
"sources": [
39+
{
40+
"type": "file",
41+
"sourcePaths": [
42+
"src/dir2"
43+
],
44+
"filePattern": "*.php"
45+
},
46+
{
47+
"type": "text",
48+
"content": "Foo Bar"
49+
}
50+
]
51+
},
52+
{
53+
"description": "This is a test document 2",
54+
"outputPath": "test-document2.md",
55+
"sources": [
56+
{
57+
"type": "file",
58+
"sourcePaths": [
59+
"src"
60+
],
61+
"filePattern": "*.txt"
62+
},
63+
{
64+
"type": "text",
65+
"content": "Foo Bar"
66+
}
67+
]
68+
}
69+
]
70+
}

tests/fixtures/Compiler/context.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"$schema": https://raw.githubusercontent.com/context-hub/generator/refs/heads/main/json-schema.json
2+
3+
documents:
4+
- description: Project structure
5+
outputPath: structure.md
6+
sources:
7+
- type: tree
8+
sourcePaths:
9+
- src
10+
showCharCount: true
11+
showSize: true
12+
13+
- description: This is a test document
14+
outputPath: test-document.md
15+
sources:
16+
- type: file
17+
sourcePaths:
18+
- src/dir1
19+
filePattern: "*.php"
20+
- type: text
21+
content: Foo Bar
22+
23+
- description: This is a test document 1
24+
outputPath: test-document1.md
25+
sources:
26+
- type: file
27+
sourcePaths:
28+
- src/dir2
29+
filePattern: "*.php"
30+
- type: text
31+
content: Foo Bar
32+
33+
- description: This is a test document 2
34+
outputPath: test-document2.md
35+
sources:
36+
- type: file
37+
sourcePaths:
38+
- src
39+
filePattern: "*.txt"
40+
- type: text
41+
content: Foo Bar
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
final readonly class Test1Class {}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
final readonly class TestClass {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo baf
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
final readonly class Test3Class {}

0 commit comments

Comments
 (0)