Skip to content

Commit

Permalink
Various udpates and more tests (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaEstes authored Oct 20, 2024
1 parent 775dae5 commit 51dc3e0
Show file tree
Hide file tree
Showing 47 changed files with 880 additions and 416 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ jobs:
XDEBUG_MODE: coverage
PHPUNIT_OPTIONS: --coverage-clover coverage.xml --log-junit junit.xml
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results to Codecov
if: ${{ !cancelled() }}
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
token: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,4 @@
"@php -r \"if(file_exists('./.git')&&file_exists('./build/hooks/pre-commit')){copy('./build/hooks/pre-commit','./.git/hooks/pre-commit');chmod('./.git/hooks/pre-commit',0755);}\""
]
}
}
}
7 changes: 6 additions & 1 deletion docs/bard/commands.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Commands
---
title: Bard Commands
---

All commands have usage examples along with help documentation in the commands.
To view more details, run `bard <command> -h`.

## init

Expand Down
13 changes: 11 additions & 2 deletions docs/bard/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@
title: Bard
---

# Bard

Bard is used to manage monorepos.

## Installing

Bard is meant to be installed into a "tools" folder for use with your project.

```shell
mkdir tools/bard
composer require --working-dir=tools/bard sonsofphp/bard
echo "composer.lock\nvendor/" > tools/bard/.gitignore
php tools/bard/vendor/bin/bard
```

## Usage

Initialize a new bard.json file for new monorepos.
Expand Down
4 changes: 2 additions & 2 deletions src/SonsOfPHP/Bard/Tests/Console/Command/AddCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use SonsOfPHP\Bard\Console\Command\SplitCommand;
use SonsOfPHP\Bard\Console\Command\UpdateCommand;
use SonsOfPHP\Bard\JsonFile;
use SonsOfPHP\Bard\Worker\File\Bard\AddPackageWorker;
use SonsOfPHP\Bard\Operation\Bard\AddPackageOperation;
use Symfony\Component\Console\Tester\CommandTester;

#[Group('bard')]
Expand All @@ -38,7 +38,7 @@
#[UsesClass(SplitCommand::class)]
#[UsesClass(UpdateCommand::class)]
#[UsesClass(JsonFile::class)]
#[UsesClass(AddPackageWorker::class)]
#[UsesClass(AddPackageOperation::class)]
final class AddCommandTest extends TestCase
{
private Application $application;
Expand Down
4 changes: 2 additions & 2 deletions src/SonsOfPHP/Bard/Tests/Console/Command/CopyCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use SonsOfPHP\Bard\Console\Command\SplitCommand;
use SonsOfPHP\Bard\Console\Command\UpdateCommand;
use SonsOfPHP\Bard\JsonFile;
use SonsOfPHP\Bard\Worker\File\Bard\AddPackageWorker;
use SonsOfPHP\Bard\Operation\Bard\AddPackageOperation;
use Symfony\Component\Console\Tester\CommandTester;

#[Group('bard')]
Expand All @@ -38,7 +38,7 @@
#[UsesClass(SplitCommand::class)]
#[UsesClass(UpdateCommand::class)]
#[UsesClass(JsonFile::class)]
#[UsesClass(AddPackageWorker::class)]
#[UsesClass(AddPackageOperation::class)]
final class CopyCommandTest extends TestCase
{
private Application $application;
Expand Down
44 changes: 22 additions & 22 deletions src/SonsOfPHP/Bard/Tests/Console/Command/MergeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
use SonsOfPHP\Bard\Console\Command\SplitCommand;
use SonsOfPHP\Bard\Console\Command\UpdateCommand;
use SonsOfPHP\Bard\JsonFile;
use SonsOfPHP\Bard\Worker\File\Composer\Package\Authors;
use SonsOfPHP\Bard\Worker\File\Composer\Package\BranchAlias;
use SonsOfPHP\Bard\Worker\File\Composer\Package\Funding;
use SonsOfPHP\Bard\Worker\File\Composer\Package\Support;
use SonsOfPHP\Bard\Worker\File\Composer\Root\ClearSection;
use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateAutoloadDevSection;
use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateAutoloadSection;
use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateProvideSection;
use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateReplaceSection;
use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateRequireDevSection;
use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateRequireSection;
use SonsOfPHP\Bard\Operation\ClearSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Package\CopyAuthorsSectionFromRootToPackageOperation;
use SonsOfPHP\Bard\Operation\Composer\Package\CopyBranchAliasValueFromRootToPackageOperation;
use SonsOfPHP\Bard\Operation\Composer\Package\CopyFundingSectionFromRootToPackageOperation;
use SonsOfPHP\Bard\Operation\Composer\Package\CopySupportSectionFromRootToPackageOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateAutoloadDevSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateAutoloadSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateProvideSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateReplaceSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateRequireDevSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateRequireSectionOperation;
use Symfony\Component\Console\Tester\CommandTester;

#[Group('bard')]
Expand All @@ -48,17 +48,17 @@
#[UsesClass(SplitCommand::class)]
#[UsesClass(UpdateCommand::class)]
#[UsesClass(JsonFile::class)]
#[UsesClass(Authors::class)]
#[UsesClass(BranchAlias::class)]
#[UsesClass(Funding::class)]
#[UsesClass(Support::class)]
#[UsesClass(ClearSection::class)]
#[UsesClass(UpdateAutoloadDevSection::class)]
#[UsesClass(UpdateAutoloadSection::class)]
#[UsesClass(UpdateProvideSection::class)]
#[UsesClass(UpdateReplaceSection::class)]
#[UsesClass(UpdateRequireSection::class)]
#[UsesClass(UpdateRequireDevSection::class)]
#[UsesClass(CopyAuthorsSectionFromRootToPackageOperation::class)]
#[UsesClass(CopyBranchAliasValueFromRootToPackageOperation::class)]
#[UsesClass(CopyFundingSectionFromRootToPackageOperation::class)]
#[UsesClass(CopySupportSectionFromRootToPackageOperation::class)]
#[UsesClass(ClearSectionOperation::class)]
#[UsesClass(UpdateAutoloadDevSectionOperation::class)]
#[UsesClass(UpdateAutoloadSectionOperation::class)]
#[UsesClass(UpdateProvideSectionOperation::class)]
#[UsesClass(UpdateReplaceSectionOperation::class)]
#[UsesClass(UpdateRequireSectionOperation::class)]
#[UsesClass(UpdateRequireDevSectionOperation::class)]
final class MergeCommandTest extends TestCase
{
private Application $application;
Expand Down
4 changes: 2 additions & 2 deletions src/SonsOfPHP/Bard/Tests/Console/Command/PushCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use SonsOfPHP\Bard\Console\Command\SplitCommand;
use SonsOfPHP\Bard\Console\Command\UpdateCommand;
use SonsOfPHP\Bard\JsonFile;
use SonsOfPHP\Bard\Worker\File\Bard\AddPackageWorker;
use SonsOfPHP\Bard\Operation\Bard\AddPackageOperation;
use Symfony\Component\Console\Tester\CommandTester;

#[Group('bard')]
Expand All @@ -38,7 +38,7 @@
#[UsesClass(SplitCommand::class)]
#[UsesClass(UpdateCommand::class)]
#[UsesClass(JsonFile::class)]
#[UsesClass(AddPackageWorker::class)]
#[UsesClass(AddPackageOperation::class)]
final class PushCommandTest extends TestCase
{
private Application $application;
Expand Down
30 changes: 24 additions & 6 deletions src/SonsOfPHP/Bard/Tests/Console/Command/ReleaseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,18 @@
use SonsOfPHP\Bard\Console\Command\SplitCommand;
use SonsOfPHP\Bard\Console\Command\UpdateCommand;
use SonsOfPHP\Bard\JsonFile;
use SonsOfPHP\Bard\Worker\File\Bard\UpdateVersionWorker;
use SonsOfPHP\Bard\Worker\File\Composer\Package\BranchAlias;
use SonsOfPHP\Bard\Worker\File\Composer\Root\UpdateReplaceSection;
use SonsOfPHP\Bard\Operation\Bard\UpdateVersionOperation;
use SonsOfPHP\Bard\Operation\ClearSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Package\CopyAuthorsSectionFromRootToPackageOperation;
use SonsOfPHP\Bard\Operation\Composer\Package\CopyBranchAliasValueFromRootToPackageOperation;
use SonsOfPHP\Bard\Operation\Composer\Package\CopyFundingSectionFromRootToPackageOperation;
use SonsOfPHP\Bard\Operation\Composer\Package\CopySupportSectionFromRootToPackageOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateAutoloadDevSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateAutoloadSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateProvideSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateReplaceSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateRequireDevSectionOperation;
use SonsOfPHP\Bard\Operation\Composer\Root\UpdateRequireSectionOperation;
use SonsOfPHP\Component\Version\Version;
use Symfony\Component\Console\Tester\CommandTester;

Expand All @@ -41,9 +50,18 @@
#[UsesClass(SplitCommand::class)]
#[UsesClass(UpdateCommand::class)]
#[UsesClass(JsonFile::class)]
#[UsesClass(UpdateVersionWorker::class)]
#[UsesClass(BranchAlias::class)]
#[UsesClass(UpdateReplaceSection::class)]
#[UsesClass(CopyAuthorsSectionFromRootToPackageOperation::class)]
#[UsesClass(CopyBranchAliasValueFromRootToPackageOperation::class)]
#[UsesClass(CopyFundingSectionFromRootToPackageOperation::class)]
#[UsesClass(CopySupportSectionFromRootToPackageOperation::class)]
#[UsesClass(ClearSectionOperation::class)]
#[UsesClass(UpdateAutoloadDevSectionOperation::class)]
#[UsesClass(UpdateAutoloadSectionOperation::class)]
#[UsesClass(UpdateProvideSectionOperation::class)]
#[UsesClass(UpdateReplaceSectionOperation::class)]
#[UsesClass(UpdateRequireSectionOperation::class)]
#[UsesClass(UpdateRequireDevSectionOperation::class)]
#[UsesClass(UpdateVersionOperation::class)]
#[UsesClass(Version::class)]
final class ReleaseCommandTest extends TestCase
{
Expand Down
10 changes: 10 additions & 0 deletions src/SonsOfPHP/Bard/Tests/JsonFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Bard\JsonFile;
use SonsOfPHP\Bard\Operation\OperationInterface;

#[Group('bard')]
#[CoversClass(JsonFile::class)]
Expand Down Expand Up @@ -67,4 +68,13 @@ public function testItCanConvertUpdatedConfigToJson(): void
$this->assertArrayHasKey('version', $json);
$this->assertSame('1.2.4', $json['version']);
}

public function testItWillApplyOperation(): void
{
$file = new JsonFile(__DIR__ . '/fixtures/test.json');
$operation = $this->createMock(OperationInterface::class);
$operation->expects($this->once())->method('apply')->willReturn($file);

$file->with($operation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

declare(strict_types=1);

namespace SonsOfPHP\Bard\Tests\File\Bard;
namespace SonsOfPHP\Bard\Tests\Operation\Bard;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Bard\JsonFileInterface;
use SonsOfPHP\Bard\Worker\File\Bard\AddPackageWorker;
use SonsOfPHP\Bard\Worker\WorkerInterface;
use SonsOfPHP\Bard\Operation\Bard\AddPackageOperation;
use SonsOfPHP\Bard\Operation\OperationInterface;

#[Group('bard')]
#[CoversClass(AddPackageWorker::class)]
final class AddPackageWorkerTest extends TestCase
#[CoversClass(AddPackageOperation::class)]
final class AddPackageOperationTest extends TestCase
{
private AddPackageWorker $worker;
private AddPackageOperation $worker;

private JsonFileInterface&MockObject $jsonFile;

protected function setUp(): void
{
$this->worker = new AddPackageWorker([
$this->worker = new AddPackageOperation([
'path' => 'src/test',
'repository' => 'git@github.com:vendor/repo.git',
]);
Expand All @@ -32,7 +32,7 @@ protected function setUp(): void

public function testItImplementsCorrectInterface(): void
{
$this->assertInstanceOf(WorkerInterface::class, $this->worker);
$this->assertInstanceOf(OperationInterface::class, $this->worker);
}

public function testItWillThrowExceptionWhenPackageAtSamePathExists(): void
Expand All @@ -53,13 +53,10 @@ public function testItWillAddNewPackage(): void
$this->jsonFile->expects($this->once())->method('setSection')
->with(
'packages',
$this->callback(function ($packages): true {
$this->assertSame([[
'path' => 'src/test',
'repository' => 'git@github.com:vendor/repo.git',
]], $packages);
return true;
})
$this->callback(fn($packages): true => [[
'path' => 'src/test',
'repository' => 'git@github.com:vendor/repo.git',
]] === $packages)
)
;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace SonsOfPHP\Bard\Tests\Operation\Bard;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use SonsOfPHP\Bard\JsonFileInterface;
use SonsOfPHP\Bard\Operation\Bard\UpdateVersionOperation;
use SonsOfPHP\Bard\Operation\OperationInterface;
use SonsOfPHP\Component\Version\VersionInterface;

#[Group('bard')]
#[CoversClass(UpdateVersionOperation::class)]
final class UpdateVersionOperationTest extends TestCase
{
private UpdateVersionOperation $worker;

private JsonFileInterface&MockObject $jsonFile;

private VersionInterface&MockObject $version;

protected function setUp(): void
{
$this->version = $this->createMock(VersionInterface::class);
$this->worker = new UpdateVersionOperation($this->version);

$this->jsonFile = $this->createMock(JsonFileInterface::class);
}

public function testItImplementsCorrectInterface(): void
{
$this->assertInstanceOf(OperationInterface::class, $this->worker);
}

public function testItWillUpdateVersionSection(): void
{
$this->version->method('toString')->willReturn('1.2.3');
$this->jsonFile->expects($this->once())->method('setSection')->with(
'version',
$this->callback(fn($version): true => '1.2.3' === $version)
);

$this->worker->apply($this->jsonFile);
}
}
Loading

0 comments on commit 51dc3e0

Please sign in to comment.