1515use Psl \Filesystem ;
1616use Psl \Shell ;
1717use Psr \Http \Message \UriInterface ;
18+ use Psr \Log \LoggerInterface ;
1819
1920use function Psl \File \read ;
21+ use function sprintf ;
2022
2123/** @covers \Laminas\AutomaticReleases\Git\CreateTagViaConsole */
2224final class CreateTagViaConsoleTest extends TestCase
@@ -48,6 +50,9 @@ protected function setUp(): void
4850
4951 public function testCreatesSignedTag (): void
5052 {
53+ $ logger = $ this ->createMock (LoggerInterface::class);
54+ $ logger ->expects (self ::never ())->method ('info ' );
55+
5156 $ sourceUri = $ this ->createMock (UriInterface::class);
5257 $ sourceUri ->method ('__toString ' )->willReturn ($ this ->repository );
5358
@@ -56,7 +61,7 @@ public function testCreatesSignedTag(): void
5661 ->with ($ this ->repository , 'name-of-the-tag ' )
5762 ->willReturn (false );
5863
59- (new CreateTagViaConsole ($ hasTag ))(
64+ (new CreateTagViaConsole ($ hasTag, $ logger ))(
6065 $ this ->repository ,
6166 BranchName::fromName ('tag-branch ' ),
6267 'name-of-the-tag ' ,
@@ -76,31 +81,41 @@ public function testCreatesSignedTag(): void
7681
7782 public function testSkipsIfTagAlreadyExists (): void
7883 {
84+ $ tagName = 'name-of-the-tag ' ;
85+ $ logger = $ this ->createMock (LoggerInterface::class);
86+ $ logger ->expects (self ::never ())
87+ ->method ('info ' );
88+
7989 $ sourceUri = $ this ->createMock (UriInterface::class);
8090 $ sourceUri ->method ('__toString ' )->willReturn ($ this ->repository );
8191
8292 $ hasTag = new HasTagViaConsole ();
8393
84- (new CreateTagViaConsole ($ hasTag ))(
94+ (new CreateTagViaConsole ($ hasTag, $ logger ))(
8595 $ this ->repository ,
8696 BranchName::fromName ('tag-branch ' ),
87- ' name-of-the-tag ' ,
97+ $ tagName ,
8898 'changelog text for the tag ' ,
8999 $ this ->key ,
90100 );
91101
92- Shell \execute ('git ' , ['tag ' , '-v ' , ' name-of-the-tag ' ], $ this ->repository );
93- $ fetchedTag = Shell \execute ('git ' , ['show ' , ' name-of-the-tag ' ], $ this ->repository );
102+ Shell \execute ('git ' , ['tag ' , '-v ' , $ tagName ], $ this ->repository );
103+ $ fetchedTag = Shell \execute ('git ' , ['show ' , $ tagName ], $ this ->repository );
94104
95105 self ::assertStringContainsString ('tag name-of-the-tag ' , $ fetchedTag );
96106 self ::assertStringContainsString ('changelog text for the tag ' , $ fetchedTag );
97107 self ::assertStringContainsString ('a commit ' , $ fetchedTag );
98108 self ::assertStringContainsString ('-----BEGIN PGP SIGNATURE----- ' , $ fetchedTag );
99109
100- (new CreateTagViaConsole ($ hasTag ))(
110+ $ logger = $ this ->createMock (LoggerInterface::class);
111+ $ logger ->expects (self ::once ())
112+ ->method ('info ' )
113+ ->with (sprintf ('[CreateTagViaConsole] Skipping this step; tag "%s" already exists. ' , $ tagName ));
114+
115+ (new CreateTagViaConsole ($ hasTag , $ logger ))(
101116 $ this ->repository ,
102117 BranchName::fromName ('tag-branch ' ),
103- ' name-of-the-tag ' ,
118+ $ tagName ,
104119 'changelog text for the tag ' ,
105120 $ this ->key ,
106121 );
0 commit comments