|
22 | 22 | use Exception; |
23 | 23 | use DateTimeImmutable; |
24 | 24 | use FastForward\DevTools\Composer\Json\ComposerJsonInterface; |
| 25 | +use FastForward\DevTools\Composer\Json\Schema\Author; |
25 | 26 | use FastForward\DevTools\Composer\Json\Schema\AuthorInterface; |
26 | 27 | use FastForward\DevTools\Filesystem\FilesystemInterface; |
27 | 28 | use FastForward\DevTools\License\Generator; |
28 | 29 | use FastForward\DevTools\License\ResolverInterface; |
29 | 30 | use PHPUnit\Framework\Attributes\CoversClass; |
30 | 31 | use PHPUnit\Framework\Attributes\Test; |
| 32 | +use PHPUnit\Framework\Attributes\UsesClass; |
31 | 33 | use PHPUnit\Framework\TestCase; |
32 | 34 | use Prophecy\Argument; |
33 | 35 | use Prophecy\Prophecy\ObjectProphecy; |
34 | 36 | use Prophecy\PhpUnit\ProphecyTrait; |
35 | 37 | use Psr\Clock\ClockInterface; |
36 | 38 | use Twig\Environment; |
| 39 | +use Twig\Loader\ArrayLoader; |
37 | 40 |
|
38 | 41 | #[CoversClass(Generator::class)] |
| 42 | +#[UsesClass(Author::class)] |
39 | 43 | final class GeneratorTest extends TestCase |
40 | 44 | { |
41 | 45 | use ProphecyTrait; |
@@ -144,6 +148,43 @@ public function generateWithValidLicenseWillCreateFile(): void |
144 | 148 | self::assertSame($renderedContent, $result); |
145 | 149 | } |
146 | 150 |
|
| 151 | + /** |
| 152 | + * @return void |
| 153 | + */ |
| 154 | + #[Test] |
| 155 | + public function generateContentWillPreserveLiteralAuthorEmailAngleBrackets(): void |
| 156 | + { |
| 157 | + $generator = new Generator( |
| 158 | + $this->resolver->reveal(), |
| 159 | + $this->composer->reveal(), |
| 160 | + $this->clock->reveal(), |
| 161 | + new Environment(new ArrayLoader([ |
| 162 | + 'licenses/mit.txt' => 'Copyright (c) {{ year }} {{ copyright_holder }}', |
| 163 | + ]), [ |
| 164 | + 'autoescape' => 'html', |
| 165 | + ]), |
| 166 | + $this->filesystem->reveal(), |
| 167 | + ); |
| 168 | + |
| 169 | + $this->composer->getLicense() |
| 170 | + ->willReturn('MIT'); |
| 171 | + $this->resolver->resolve('MIT') |
| 172 | + ->willReturn('mit.txt'); |
| 173 | + $this->composer->getAuthors(true) |
| 174 | + ->willReturn(new Author('Felipe Sayão Lobato Abreu', 'github@mentordosnerds.com')); |
| 175 | + $this->clock->now() |
| 176 | + ->willReturn(new DateTimeImmutable('2026-04-23')); |
| 177 | + |
| 178 | + $content = $generator->generateContent(); |
| 179 | + |
| 180 | + self::assertSame( |
| 181 | + 'Copyright (c) 2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com>', |
| 182 | + $content, |
| 183 | + ); |
| 184 | + self::assertStringNotContainsString('<', (string) $content); |
| 185 | + self::assertStringNotContainsString('>', (string) $content); |
| 186 | + } |
| 187 | + |
147 | 188 | /** |
148 | 189 | * @return void |
149 | 190 | */ |
|
0 commit comments