|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace MarkWalet\Changelog\Tests\Commands; |
| 4 | + |
| 5 | +use MarkWalet\Changelog\Adapters\FeatureAdapter; |
| 6 | +use MarkWalet\Changelog\Change; |
| 7 | +use MarkWalet\Changelog\Feature; |
| 8 | +use MarkWalet\Changelog\Tests\LaravelTestCase; |
| 9 | +use MarkWalet\GitState\Drivers\GitDriver; |
| 10 | +use Mockery\MockInterface; |
| 11 | + |
| 12 | +class ChangelogCurrentCommandTest extends LaravelTestCase |
| 13 | +{ |
| 14 | + /** |
| 15 | + * Setup the test environment. |
| 16 | + * |
| 17 | + * @return void |
| 18 | + */ |
| 19 | + protected function setUp(): void |
| 20 | + { |
| 21 | + parent::setUp(); |
| 22 | + |
| 23 | + config()->set('changelog.path', 'fake-path'); |
| 24 | + $this->mock(GitDriver::class, function (MockInterface $git) { |
| 25 | + $git->expects('currentBranch')->once()->andReturn('test-branch'); |
| 26 | + }); |
| 27 | + } |
| 28 | + |
| 29 | + /** @test */ |
| 30 | + public function it_can_list_all_changes_for_all_releases() |
| 31 | + { |
| 32 | + $this->mock(FeatureAdapter::class, function (MockInterface $adapter) { |
| 33 | + $adapter->allows('exists')->andReturnUsing(function (string $branch) { |
| 34 | + return $branch === 'fake-path/unreleased/test-branch.xml'; |
| 35 | + }); |
| 36 | + |
| 37 | + $adapter->allows('read')->andReturn(tap(new Feature(), function (Feature $feature) { |
| 38 | + $feature->add(new Change('added', 'Added a new feature.')); |
| 39 | + $feature->add(new Change('fixed', 'Fixed a bug.')); |
| 40 | + })); |
| 41 | + }); |
| 42 | + |
| 43 | + $this->artisan('changelog:current') |
| 44 | + ->expectsOutput('Changes for test-branch:') |
| 45 | + ->expectsOutput(' - Added: Added a new feature.') |
| 46 | + ->expectsOutput(' - Fixed: Fixed a bug.'); |
| 47 | + } |
| 48 | + |
| 49 | + /** @test */ |
| 50 | + public function it_shows_a_warning_when_there_are_no_unreleased_changes_found_yet(): void |
| 51 | + { |
| 52 | + config()->set('changelog.path', 'fake-path'); |
| 53 | + $this->mock(FeatureAdapter::class, function (MockInterface $adapter) { |
| 54 | + $adapter->allows('exists')->andReturn(false); |
| 55 | + }); |
| 56 | + |
| 57 | + $this->artisan('changelog:current') |
| 58 | + ->expectsOutput('No changes found for test-branch'); |
| 59 | + } |
| 60 | +} |
0 commit comments