Skip to content

Commit 7719818

Browse files
committed
Fixes generated or modified header
1 parent 922439d commit 7719818

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/Commands/ValidateCommand.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
307307
$globPattern = $input->getOption('glob-pattern');
308308
$globPatternFile = (string) $input->getOption('glob-pattern-file');
309309
$omitHeader = (boolean) $input->getOption('omit-header');
310-
311310
$showDifference = $input->getOption('diff');
312311
$reportStaleExportIgnores = $input->getOption('report-stale-export-ignores');
313312

@@ -477,7 +476,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
477476
try {
478477
$outputContent .= $this->gitattributesFileRepository->createGitattributesFile(
479478
$expectedGitattributesFileContent,
480-
$omitHeader
479+
$omitHeader === true ? false : true
481480
);
482481
$output->writeln($outputContent);
483482

src/GitattributesFileRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(Analyser $analyser)
2929
*/
3030
public function createGitattributesFile(string $content, bool $withHeader = true): string
3131
{
32-
// Ensure the "generated by" header is present when requested.
32+
// Ensure the generated or modified by header is present when requested
3333
if ($withHeader) {
3434
$content = $this->applyOverwriteHeaderPolicy($content);
3535
}

tests/Commands/ValidateCommandTest.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,9 @@ public function validateOnNonExistentGitattributesFilesWithCreationOptionCreates
848848

849849
$this->assertStringNotContainsString(GitattributesFileRepository::GENERATED_HEADER, $commandTester->getDisplay());
850850
$this->assertStringNotContainsString(GitattributesFileRepository::MODIFIED_HEADER, $commandTester->getDisplay());
851+
851852
$commandTester->assertCommandIsSuccessful();
853+
852854
$this->assertFileExists(
853855
WORKING_DIRECTORY . DIRECTORY_SEPARATOR . '.gitattributes'
854856
);
@@ -1566,6 +1568,35 @@ public function createdHeaderIsReplacedByModifiedHeader(): void
15661568
);
15671569
}
15681570

1571+
#[Test]
1572+
public function addsCreatedHeaderAsExpected(): void
1573+
{
1574+
$artifactFilenames = ['phpspec.yml.dist', 'version-increase-command'];
1575+
1576+
$this->createTemporaryFiles(
1577+
$artifactFilenames,
1578+
['specs']
1579+
);
1580+
1581+
$command = $this->application->find('validate');
1582+
$commandTester = new CommandTester($command);
1583+
$commandTester->execute([
1584+
'command' => $command->getName(),
1585+
'directory' => WORKING_DIRECTORY,
1586+
'--create' => true,
1587+
'--omit-header' => false,
1588+
]);
1589+
1590+
$commandTester->assertCommandIsSuccessful();
1591+
$this->assertFileExists(
1592+
WORKING_DIRECTORY . DIRECTORY_SEPARATOR . '.gitattributes'
1593+
);
1594+
$this->assertStringContainsString(
1595+
GitattributesFileRepository::GENERATED_HEADER,
1596+
\file_get_contents(WORKING_DIRECTORY . DIRECTORY_SEPARATOR . '.gitattributes')
1597+
);
1598+
}
1599+
15691600
#[Test]
15701601
#[Ticket('https://github.com/raphaelstolt/lean-package-validator/issues/8')]
15711602
#[DataProvider('optionProvider')]
@@ -1588,15 +1619,7 @@ public function incompleteGitattributesFileIsOverwritten(string $option): void
15881619
['specs']
15891620
);
15901621

1591-
$header = GitattributesFileRepository::GENERATED_HEADER . PHP_EOL . PHP_EOL;
1592-
1593-
if ($option === '--overwrite') {
1594-
$header = GitattributesFileRepository::MODIFIED_HEADER . PHP_EOL;
1595-
}
1596-
1597-
if ($option === '--create') {
1598-
$header = GitattributesFileRepository::MODIFIED_HEADER . PHP_EOL . PHP_EOL;
1599-
}
1622+
$header = GitattributesFileRepository::MODIFIED_HEADER . PHP_EOL;
16001623

16011624
$command = $this->application->find('validate');
16021625
$commandTester = new CommandTester($command);

0 commit comments

Comments
 (0)