Skip to content

Commit

Permalink
Adds header to generated files
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelstolt committed Sep 13, 2023
1 parent ef14f96 commit 269bded
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 25 deletions.
17 changes: 14 additions & 3 deletions bin/release-version
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ foreach ($autoloads as $autoload) {
}
}

use Composer\Semver\Comparator;
use Stolt\LeanPackage\Helpers\Str as OsHelper;
use vierbergenlars\SemVer\version as SemVer;
use PHLAK\SemVer\Version;

$binApplicationName = 'lean-package-validator';
$binFile = __DIR__ . DIRECTORY_SEPARATOR . $binApplicationName;
Expand Down Expand Up @@ -130,7 +131,7 @@ if ($version === null) {
}

if ($version) {
if (SemVer::lte($version, $currentVersion)) {
if (Comparator::lessThanOrEqualTo($version, $currentVersion)) {
echo "Earlier version '{$version}' provided." . PHP_EOL;
exit(1);
}
Expand All @@ -156,7 +157,17 @@ if ($increment) {
exit(1);
}

$version = (new SemVer($currentVersion))->inc($increment)->getVersion();
switch ($increment) {
case 'major':
$version = (new Version($currentVersion))->incrementMajor()->__toString();
break;
case 'minor':
$version = (new Version($currentVersion))->incrementMinor()->__toString();
break;
case 'patch':
$version = (new Version($currentVersion))->incrementPatch()->__toString();
break;
}
}

if (!isset($version)) {
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"mockery/mockery": "^1.0",
"phlak/semver": "^4.1",
"php-mock/php-mock-phpunit": "^2.4||^1.1",
"phpstan/phpstan": "^1.6.2",
"phpunit/phpunit": "8.*",
"vierbergenlars/php-semver": "^3.0"
"phpunit/phpunit": "^10.3"
}
}
31 changes: 12 additions & 19 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true">
<testsuites>
<testsuite name="Lean Package Validator">
<directory>tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage/>
<testsuites>
<testsuite name="Lean Package Validator">
<directory>tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
4 changes: 4 additions & 0 deletions src/Commands/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$defaultGlobPatterns = $this->analyser->getDefaultGlobPatterns();
array_unshift(
$defaultGlobPatterns,
'This file was generated by the lean package validator (http://git.io/lean-package-validator).' . PHP_EOL
);
$lpvFileContent = implode("\n", $defaultGlobPatterns);

$bytesWritten = file_put_contents(
Expand Down
2 changes: 2 additions & 0 deletions src/Commands/ValidateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
if ($expectedGitattributesFileContent !== '') {
if ($createGitattributesFile || $overwriteGitattributesFile) {
try {
$expectedGitattributesFileContent = 'This file was partly modified by the lean package validator (http://git.io/lean-package-validator).'
. PHP_EOL . PHP_EOL . $expectedGitattributesFileContent;
$outputContent .= $this->createGitattributesFile(
$expectedGitattributesFileContent
);
Expand Down
2 changes: 2 additions & 0 deletions tests/Commands/InitCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public function createsExpectedDefaultLpvFile()
CONTENT;

$expectedDefaultLpvFileContent = <<<CONTENT
This file was generated by the lean package validator (http://git.io/lean-package-validator).
.*
*.lock
*.txt
Expand Down
6 changes: 5 additions & 1 deletion tests/Commands/ValidateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,8 @@ public function validateOnNonExistentGitattributesFilesWithCreationOptionCreates
Warning: There is no .gitattributes file present in {$this->temporaryDirectory}.
Created a .gitattributes file with the shown content:
This file was partly modified by the lean package validator (http://git.io/lean-package-validator).
* text=auto eol=lf
.gitattributes export-ignore
Expand Down Expand Up @@ -642,6 +644,8 @@ public function validateOnNonExistentGitattributesFilesWithCreationOptionCreates
Warning: There is no .gitattributes file present in {$this->temporaryDirectory}.
Created a .gitattributes file with the shown content:
This file was partly modified by the lean package validator (http://git.io/lean-package-validator).
* text=auto eol=lf
.gitattributes export-ignore
Expand Down Expand Up @@ -1819,7 +1823,7 @@ public function gitignoredFilesAreExcludedFromValidation()
/**
* @return array
*/
public function optionProvider()
public static function optionProvider()
{
return [
['--overwrite'],
Expand Down

0 comments on commit 269bded

Please sign in to comment.