Skip to content

Commit

Permalink
[#76] Moved functionality from Artifact class to ArtifactCommand clas…
Browse files Browse the repository at this point in the history
…s. (#80)

* Move functionality from Artifact class to ArtifactCommand class.

* Update coverage test name.

* Check branch exisiting before do remove.

* Revert to standard app entry
  • Loading branch information
tannguyen04 authored Mar 19, 2024
1 parent 8f8307c commit 22c667c
Show file tree
Hide file tree
Showing 9 changed files with 993 additions and 993 deletions.
963 changes: 0 additions & 963 deletions src/Artifact.php

This file was deleted.

980 changes: 973 additions & 7 deletions src/Commands/ArtifactCommand.php

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions src/GitArtifactGitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ public function removeBranch($name, bool $force = FALSE): GitArtifactGitReposito
return $this;
}

$branches = $this->getBranches();
if (empty($branches)) {
return $this;
}
if (!in_array($name, $branches)) {
return $this;
}

if (!$force) {
return parent::removeBranch($name);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Functional/BranchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @group integration
*
* @covers \DrevOps\GitArtifact\GitTrait
* @covers \DrevOps\GitArtifact\Artifact
* @covers \DrevOps\GitArtifact\Commands\ArtifactCommand
* @covers \DrevOps\GitArtifact\FilesystemTrait
*/
class BranchTest extends AbstractFunctionalTestCase {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Functional/ForcePushTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*
* @covers \DrevOps\GitArtifact\GitTrait
* @covers \DrevOps\GitArtifact\Artifact
* @covers \DrevOps\GitArtifact\Commands\ArtifactCommand
* @covers \DrevOps\GitArtifact\FilesystemTrait
*/
class ForcePushTest extends AbstractFunctionalTestCase {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Functional/GeneralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @group integration
*
* @covers \DrevOps\GitArtifact\Artifact
* @covers \DrevOps\GitArtifact\Commands\ArtifactCommand
* @covers \DrevOps\GitArtifact\FilesystemTrait
*/
class GeneralTest extends AbstractFunctionalTestCase {
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/Functional/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @group integration
*
* @covers \DrevOps\GitArtifact\GitTrait
* @covers \DrevOps\GitArtifact\Artifact
* @covers \DrevOps\GitArtifact\Commands\ArtifactCommand
* @covers \DrevOps\GitArtifact\FilesystemTrait
*/
class TagTest extends AbstractFunctionalTestCase {
Expand Down
21 changes: 5 additions & 16 deletions tests/phpunit/Unit/AbstractUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,24 @@

namespace DrevOps\GitArtifact\Tests\Unit;

use DrevOps\GitArtifact\Artifact;
use DrevOps\GitArtifact\GitArtifactGit;
use DrevOps\GitArtifact\Commands\ArtifactCommand;
use DrevOps\GitArtifact\Tests\AbstractTestCase;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Filesystem\Filesystem;

/**
* Class AbstractUnitTestCase.
*/
abstract class AbstractUnitTestCase extends AbstractTestCase {

/**
* Mock of the class.
*
* @var \PHPUnit\Framework\MockObject\MockObject
* Artifact command.
*/
protected $mock;
protected ArtifactCommand $command;

protected function setUp(): void {
parent::setUp();

$mockBuilder = $this->getMockBuilder(Artifact::class);
$fileSystem = new Filesystem();
$gitWrapper = new GitArtifactGit();
$output = new ConsoleOutput();

$mockBuilder->setConstructorArgs([$gitWrapper, $fileSystem, $output]);
$this->mock = $mockBuilder->getMock();
$this->callProtectedMethod($this->mock, 'fsSetRootDir', [$this->fixtureDir]);
$this->command = new ArtifactCommand();
$this->callProtectedMethod($this->command, 'fsSetRootDir', [$this->fixtureDir]);
}

}
6 changes: 3 additions & 3 deletions tests/phpunit/Unit/ExcludeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @group unit
*
* @covers \DrevOps\GitArtifact\Artifact
* @covers \DrevOps\GitArtifact\Commands\ArtifactCommand
*/
class ExcludeTest extends AbstractUnitTestCase {

Expand All @@ -19,7 +19,7 @@ class ExcludeTest extends AbstractUnitTestCase {
public function testExcludeExists(): void {
$this->createFixtureExcludeFile();

$actual = $this->callProtectedMethod($this->mock, 'localExcludeExists', [$this->fixtureDir]);
$actual = $this->callProtectedMethod($this->command, 'localExcludeExists', [$this->fixtureDir]);

$this->assertTrue($actual);
}
Expand All @@ -40,7 +40,7 @@ public function testExcludeExists(): void {
public function testExcludeEmpty(array $lines, bool $strict, bool $expected): void {
$this->createFixtureExcludeFile(implode(PHP_EOL, $lines));

$actual = $this->callProtectedMethod($this->mock, 'localExcludeEmpty', [$this->fixtureDir, $strict]);
$actual = $this->callProtectedMethod($this->command, 'localExcludeEmpty', [$this->fixtureDir, $strict]);

$this->assertEquals($expected, $actual);
}
Expand Down

0 comments on commit 22c667c

Please sign in to comment.