Skip to content

Commit ff9ac96

Browse files
committed
Fixes failing regression test
1 parent 719d247 commit ff9ac96

6 files changed

Lines changed: 98 additions & 1 deletion

File tree

src/Analysers/AbstractExportIgnoreAnalyser.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public function setDirectory(string $directory = __DIR__): AbstractExportIgnoreA
222222
. '.gitattributes';
223223

224224
$this->gitattributesFileRepository->setWorkingDirectory($directory);
225+
$this->configuration = $this->configuration->withDirectory($directory);
225226

226227
return $this;
227228
}
@@ -242,13 +243,15 @@ public function enableStrictOrderComparison(): self
242243
public function sortFromDirectoriesToFiles(): self
243244
{
244245
$this->sortFromDirectoriesToFiles = true;
246+
$this->configuration = $this->configuration->sortFromDirectoriesToFiles(true);
245247

246248
return $this;
247249
}
248250

249251
public function sortAlphabetically(): self
250252
{
251253
$this->sortAlphabetically = true;
254+
$this->configuration = $this->configuration->sortAlphabetically(true);
252255

253256
return $this;
254257
}
@@ -364,6 +367,7 @@ public function setKeepGlobPattern(string $globPattern): AbstractExportIgnoreAna
364367
{
365368
$this->guardGlobPattern($globPattern);
366369
$this->keepGlobPattern = $globPattern;
370+
$this->configuration = $this->configuration->keepGlobPattern($globPattern);
367371

368372
return $this;
369373
}
@@ -425,6 +429,7 @@ public function getGitattributesFilePath(): string
425429
public function alignExportIgnores(): self
426430
{
427431
$this->alignExportIgnores = true;
432+
$this->configuration = $this->configuration->alignExportIgnores(true);
428433

429434
return $this;
430435
}
@@ -473,6 +478,7 @@ public function setGroupNonExportIgnores(bool $group = true): self
473478
public function setGlobPatternFromPreset(string $preset): void
474479
{
475480
$this->globPattern = '{' . \implode(',', $this->finder->getPresetGlobByLanguageName($preset)) . '}*';
481+
$this->configuration = $this->configuration->withGlobPattern($this->globPattern);
476482
}
477483

478484
/**
@@ -591,6 +597,7 @@ public function setGlobPattern(string $pattern): AbstractExportIgnoreAnalyser
591597
{
592598
$this->globPattern = \trim($pattern);
593599
$this->guardGlobPattern($this->globPattern);
600+
$this->configuration = $this->configuration->withGlobPattern($this->globPattern);
594601

595602
return $this;
596603
}

src/Analysers/ExportIgnoreConfiguration.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,51 @@ public function withGlobPattern(string $globPattern): self
4747
);
4848
}
4949

50+
public function sortFromDirectoriesToFiles(bool $enabled = true): self
51+
{
52+
return new self(
53+
directory: $this->directory,
54+
globPattern: $this->globPattern,
55+
sortFromDirectoriesToFiles: $enabled,
56+
sortAlphabetically: $this->sortAlphabetically,
57+
keepLicense: $this->keepLicense,
58+
keepReadme: $this->keepReadme,
59+
keepGlobPattern: $this->keepGlobPattern,
60+
alignExportIgnores: $this->alignExportIgnores,
61+
enforceStrictOrderComparison: $this->enforceStrictOrderComparison,
62+
);
63+
}
64+
65+
public function sortAlphabetically(bool $enabled = true): self
66+
{
67+
return new self(
68+
directory: $this->directory,
69+
globPattern: $this->globPattern,
70+
sortFromDirectoriesToFiles: $this->sortFromDirectoriesToFiles,
71+
sortAlphabetically: $enabled,
72+
keepLicense: $this->keepLicense,
73+
keepReadme: $this->keepReadme,
74+
keepGlobPattern: $this->keepGlobPattern,
75+
alignExportIgnores: $this->alignExportIgnores,
76+
enforceStrictOrderComparison: $this->enforceStrictOrderComparison,
77+
);
78+
}
79+
80+
public function keepGlobPattern(string $keepGlobPattern): self
81+
{
82+
return new self(
83+
directory: $this->directory,
84+
globPattern: $this->globPattern,
85+
sortFromDirectoriesToFiles: $this->sortFromDirectoriesToFiles,
86+
sortAlphabetically: $this->sortAlphabetically,
87+
keepLicense: $this->keepLicense,
88+
keepReadme: $this->keepReadme,
89+
keepGlobPattern: $keepGlobPattern,
90+
alignExportIgnores: $this->alignExportIgnores,
91+
enforceStrictOrderComparison: $this->enforceStrictOrderComparison,
92+
);
93+
}
94+
5095
public function keepLicense(bool $enabled = true): self
5196
{
5297
return new self(

src/Presets/JavaScriptPreset.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function getPresetGlob(): array
2727
'webpack.config.*',
2828
'rollup.config.*',
2929
'jest.config.*',
30+
'node_modules',
3031
]));
3132
}
3233
}

src/Presets/PhpPreset.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public function getPresetGlob(): array
3131
'phpinsights*',
3232
'ecs*',
3333
'RMT',
34-
'{{M,m}ake,{B,b}ox,{V,v}agrant,{P,p}hulp}file'
34+
'{{M,m}ake,{B,b}ox,{V,v}agrant,{P,p}hulp}file',
35+
'vendor*',
3536
]));
3637
}
3738
}

tests/AnalyserTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,6 +1867,7 @@ public function returnsExpectedDefaultGlobPatterns(): void
18671867
'rector*',
18681868
'renovate.json',
18691869
'sonar*',
1870+
'vendor*',
18701871
'{A,a}rt*',
18711872
'{A,a}sset*',
18721873
'{B,b}enchmark*',

tests/Commands/CreateCommandTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,48 @@ public function createsAGitattributesFileWithNegatedExportIgnoreDirectives(): vo
9898
);
9999
}
100100

101+
#[Test]
102+
public function createsAGitattributesFileWithNegatedAndAlignedExportIgnoreDirectives(): void
103+
{
104+
$artifactFilenames = ['LICENSE.md', '.gitignore', 'composer.json'];
105+
106+
$this->createTemporaryFiles(
107+
$artifactFilenames,
108+
['tests', 'src', 'bin', 'vendor']
109+
);
110+
111+
$this->createTemporaryFilesInDirectory($this->temporaryDirectory . DIRECTORY_SEPARATOR . 'bin', ['lpv']);
112+
$this->createTemporaryFilesInDirectory($this->temporaryDirectory . DIRECTORY_SEPARATOR . 'src', ['Fake.php', 'AnotherFake.php']);
113+
$this->createTemporaryFilesInDirectory($this->temporaryDirectory . DIRECTORY_SEPARATOR . 'vendor', ['FakeFileA', 'FakeFileB']);
114+
115+
TestCommand::for($this->getCommandInstance())
116+
->addArgument($this->temporaryDirectory)
117+
->addOption('flavour', NegatedExportIgnoreAnalyser::EXPORT_IGNORE_NEGATED)
118+
->addOption('align-export-ignores')
119+
->execute()
120+
->assertSuccessful();
121+
122+
$expectedGitattributesContent = <<<CONTENT
123+
# This file was generated by the lean package validator (http://git.io/lean-package-validator).
124+
125+
* text=auto eol=lf
126+
127+
* export-ignore
128+
129+
bin/ -export-ignore
130+
bin/lpv -export-ignore
131+
composer.json -export-ignore
132+
src/ -export-ignore
133+
src/** -export-ignore
134+
CONTENT;
135+
136+
$this->assertFileExists($this->temporaryDirectory . DIRECTORY_SEPARATOR . '.gitattributes');
137+
$this->assertStringContainsStringIgnoringLineEndings(
138+
$expectedGitattributesContent,
139+
\file_get_contents($this->temporaryDirectory . DIRECTORY_SEPARATOR . '.gitattributes')
140+
);
141+
}
142+
101143
#[Test]
102144
public function createsNewGitattributesFileWithHeaderAndExpectedContent(): void
103145
{

0 commit comments

Comments
 (0)