From 5ad14f5c60597635efd23960114a6f4a02f00598 Mon Sep 17 00:00:00 2001 From: Joshua Estes Date: Thu, 28 Dec 2023 08:45:31 -0500 Subject: [PATCH] Housekeeping (#203) ## Description ## Checklist - [ ] Updated CHANGELOG files - [ ] Updated Documentation - [ ] Unit Tests Created - [ ] php-cs-fixer --- composer.json | 5 +-- phpunit.xml.dist | 6 +-- src/SonsOfPHP/Bard/.gitattributes | 4 ++ src/SonsOfPHP/Bard/.gitignore | 3 ++ src/SonsOfPHP/Bard/Tests/JsonFileTest.php | 44 +++++++++++++++++++ src/SonsOfPHP/Bard/Tests/fixtures/test.json | 9 ++++ src/SonsOfPHP/Bard/composer.json | 2 +- .../Bard/src/Console/Command/AddCommand.php | 12 ++--- .../Bard/src/Console/Command/CopyCommand.php | 12 ++--- .../src/Console/Command/ReleaseCommand.php | 14 +++--- src/SonsOfPHP/Bard/src/JsonFile.php | 17 +++---- 11 files changed, 94 insertions(+), 34 deletions(-) create mode 100644 src/SonsOfPHP/Bard/.gitattributes create mode 100644 src/SonsOfPHP/Bard/.gitignore create mode 100644 src/SonsOfPHP/Bard/Tests/JsonFileTest.php create mode 100644 src/SonsOfPHP/Bard/Tests/fixtures/test.json diff --git a/composer.json b/composer.json index 9ba6a593..7a7c66ff 100644 --- a/composer.json +++ b/composer.json @@ -5,6 +5,7 @@ "minimum-stability": "dev", "keywords": [ "php", + "sonsofphp", "sons of php", "mother repo" ], @@ -213,9 +214,7 @@ "symfony/serializer": "^5 || ^6", "symfony/phpunit-bridge": "^6 || ^7", "symfony/error-handler": "^6", - "symfony/messenger": "^5 || ^6", - "phpunit/phpunit": "^10.4", - "psr/simple-cache": "^1.0 || ^2.0 || ^3.0" + "phpunit/phpunit": "^10.4" }, "autoload-dev": { "psr-4": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 544af877..1d748e5f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,7 +11,7 @@ - + src/SonsOfPHP/Bard/Tests src/SonsOfPHP/Bridge/*/*/Tests src/SonsOfPHP/Bridge/*/*/*/Tests src/SonsOfPHP/Bundle/*/Tests @@ -19,7 +19,7 @@ - + src/SonsOfPHP/Bard/Tests @@ -111,7 +111,7 @@ src/* - + src/SonsOfPHP/Bard/Tests src/SonsOfPHP/Bard/vendor src/SonsOfPHP/Bridge/*/*/*/Tests src/SonsOfPHP/Bridge/*/*/*/vendor diff --git a/src/SonsOfPHP/Bard/.gitattributes b/src/SonsOfPHP/Bard/.gitattributes new file mode 100644 index 00000000..84c7add0 --- /dev/null +++ b/src/SonsOfPHP/Bard/.gitattributes @@ -0,0 +1,4 @@ +/Tests export-ignore +/phpunit.xml.dist export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore diff --git a/src/SonsOfPHP/Bard/.gitignore b/src/SonsOfPHP/Bard/.gitignore new file mode 100644 index 00000000..5414c2c6 --- /dev/null +++ b/src/SonsOfPHP/Bard/.gitignore @@ -0,0 +1,3 @@ +composer.lock +phpunit.xml +vendor/ diff --git a/src/SonsOfPHP/Bard/Tests/JsonFileTest.php b/src/SonsOfPHP/Bard/Tests/JsonFileTest.php new file mode 100644 index 00000000..ae731da4 --- /dev/null +++ b/src/SonsOfPHP/Bard/Tests/JsonFileTest.php @@ -0,0 +1,44 @@ +assertIsString($json->getFilename()); + } + + /** + * @covers ::__construct + * @covers ::load + * @covers ::getSection + */ + public function testGetSection(): void + { + $json = new JsonFile(__DIR__ . '/fixtures/test.json'); + + $this->assertSame('1.2.3', $json->getSection('version')); + } +} diff --git a/src/SonsOfPHP/Bard/Tests/fixtures/test.json b/src/SonsOfPHP/Bard/Tests/fixtures/test.json new file mode 100644 index 00000000..e4eb7479 --- /dev/null +++ b/src/SonsOfPHP/Bard/Tests/fixtures/test.json @@ -0,0 +1,9 @@ +{ + "version": "1.2.3", + "packages": [ + { + "path": "path/to/Repo", + "repository": "git@github.com:SonsOfPHP/read-only-repo.git" + } + ] +} diff --git a/src/SonsOfPHP/Bard/composer.json b/src/SonsOfPHP/Bard/composer.json index 151bdd29..f05dc3c7 100644 --- a/src/SonsOfPHP/Bard/composer.json +++ b/src/SonsOfPHP/Bard/composer.json @@ -67,4 +67,4 @@ "url": "https://tidelift.com/subscription/pkg/packagist-sonsofphp-sonsofphp" } ] -} +} \ No newline at end of file diff --git a/src/SonsOfPHP/Bard/src/Console/Command/AddCommand.php b/src/SonsOfPHP/Bard/src/Console/Command/AddCommand.php index 97818dfc..0b60d315 100644 --- a/src/SonsOfPHP/Bard/src/Console/Command/AddCommand.php +++ b/src/SonsOfPHP/Bard/src/Console/Command/AddCommand.php @@ -29,15 +29,15 @@ protected function configure(): void ->addArgument('repository', InputArgument::REQUIRED, 'Repository Uri') ->setHelp( <<<'HELP' -The add command will add additional repositories that need to be managed -into the `bard.json` file. + The add command will add additional repositories that need to be managed + into the `bard.json` file. -Examples: + Examples: - %command.full_name% src/SonsOfPHP/Bard git@github.com:vendor/package.git + %command.full_name% src/SonsOfPHP/Bard git@github.com:vendor/package.git -Read more at https://docs.sonsofphp.com/bard/ -HELP + Read more at https://docs.sonsofphp.com/bard/ + HELP ) ; } diff --git a/src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php b/src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php index c63df3dd..865ba4c9 100644 --- a/src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php +++ b/src/SonsOfPHP/Bard/src/Console/Command/CopyCommand.php @@ -28,15 +28,15 @@ protected function configure(): void ->addArgument('package', InputArgument::OPTIONAL, 'Which package?') ->setHelp( <<<'HELP' -The copy command will copy whatever file you give it to all the other -repositories it is managing. This is useful for LICENSE files. + The copy command will copy whatever file you give it to all the other + repositories it is managing. This is useful for LICENSE files. -Examples: + Examples: - %command.full_name% LICENSE + %command.full_name% LICENSE -Read more at https://docs.sonsofphp.com/bard/ -HELP + Read more at https://docs.sonsofphp.com/bard/ + HELP ) ; } diff --git a/src/SonsOfPHP/Bard/src/Console/Command/ReleaseCommand.php b/src/SonsOfPHP/Bard/src/Console/Command/ReleaseCommand.php index 98af86fe..c9e773a9 100644 --- a/src/SonsOfPHP/Bard/src/Console/Command/ReleaseCommand.php +++ b/src/SonsOfPHP/Bard/src/Console/Command/ReleaseCommand.php @@ -37,15 +37,15 @@ protected function configure(): void ->addArgument('release', InputArgument::REQUIRED, 'Next Release you want to start? Use format ..-+ or "major", "minor", "patch"') ->setHelp( <<<'EOT' -This command allows you to create a new release and will update the various -repos that have been configured. The current version can be found in the -`bard.json` file. This will will update the version based on the type of release -that you are doing. + This command allows you to create a new release and will update the various + repos that have been configured. The current version can be found in the + `bard.json` file. This will will update the version based on the type of release + that you are doing. - %command.full_name% + %command.full_name% -Read more at https://docs.SonsOfPHP.com -EOT + Read more at https://docs.SonsOfPHP.com + EOT ); } diff --git a/src/SonsOfPHP/Bard/src/JsonFile.php b/src/SonsOfPHP/Bard/src/JsonFile.php index 721d3359..43b5ddf6 100644 --- a/src/SonsOfPHP/Bard/src/JsonFile.php +++ b/src/SonsOfPHP/Bard/src/JsonFile.php @@ -36,9 +36,11 @@ public function getFilename(): string } /** + * Grabs and returns a section from the JSON file + * * @return array|int|string|null */ - public function getSection(string $section) + public function getSection(string $section): mixed { if (!isset($this->config)) { $this->load(); @@ -51,6 +53,8 @@ public function getSection(string $section) return null; } + /** + */ public function setSection(string $section, $value): self { if (!isset($this->config)) { @@ -63,6 +67,8 @@ public function setSection(string $section, $value): self return $clone; } + /** + */ public function toJson(): string { return $this->json->getEncoder() @@ -73,13 +79,8 @@ public function toJson(): string } /** - * The idea is something like this - * $newRootComposerJsonFile = $rootComposerJsonFile->with($updateReplaceSection, $pkgComposerJsonFile); - * or - * $newRootComposerJsonFile = $rootComposerJsonFile->with($bumpBranchAlias);. - * - * Can even use this for the package composer.json file - * $newPkgComposerJsonFile = $pkgComposerJsonFile->with($updateSupportSection, $rootComposerJsonFile); + * $operator = new Operator(); + * $jsonFile->with(new ExampleOperator()); */ public function with($operator): self {