15
15
use Psl \Filesystem ;
16
16
use Psl \Shell ;
17
17
use Psr \Http \Message \UriInterface ;
18
+ use Psr \Log \LoggerInterface ;
18
19
19
20
use function Psl \File \read ;
21
+ use function sprintf ;
20
22
21
23
/** @covers \Laminas\AutomaticReleases\Git\CreateTagViaConsole */
22
24
final class CreateTagViaConsoleTest extends TestCase
@@ -48,6 +50,9 @@ protected function setUp(): void
48
50
49
51
public function testCreatesSignedTag (): void
50
52
{
53
+ $ logger = $ this ->createMock (LoggerInterface::class);
54
+ $ logger ->expects (self ::never ())->method ('info ' );
55
+
51
56
$ sourceUri = $ this ->createMock (UriInterface::class);
52
57
$ sourceUri ->method ('__toString ' )->willReturn ($ this ->repository );
53
58
@@ -56,7 +61,7 @@ public function testCreatesSignedTag(): void
56
61
->with ($ this ->repository , 'name-of-the-tag ' )
57
62
->willReturn (false );
58
63
59
- (new CreateTagViaConsole ($ hasTag ))(
64
+ (new CreateTagViaConsole ($ hasTag, $ logger ))(
60
65
$ this ->repository ,
61
66
BranchName::fromName ('tag-branch ' ),
62
67
'name-of-the-tag ' ,
@@ -76,31 +81,41 @@ public function testCreatesSignedTag(): void
76
81
77
82
public function testSkipsIfTagAlreadyExists (): void
78
83
{
84
+ $ tagName = 'name-of-the-tag ' ;
85
+ $ logger = $ this ->createMock (LoggerInterface::class);
86
+ $ logger ->expects (self ::never ())
87
+ ->method ('info ' );
88
+
79
89
$ sourceUri = $ this ->createMock (UriInterface::class);
80
90
$ sourceUri ->method ('__toString ' )->willReturn ($ this ->repository );
81
91
82
92
$ hasTag = new HasTagViaConsole ();
83
93
84
- (new CreateTagViaConsole ($ hasTag ))(
94
+ (new CreateTagViaConsole ($ hasTag, $ logger ))(
85
95
$ this ->repository ,
86
96
BranchName::fromName ('tag-branch ' ),
87
- ' name-of-the-tag ' ,
97
+ $ tagName ,
88
98
'changelog text for the tag ' ,
89
99
$ this ->key ,
90
100
);
91
101
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 );
94
104
95
105
self ::assertStringContainsString ('tag name-of-the-tag ' , $ fetchedTag );
96
106
self ::assertStringContainsString ('changelog text for the tag ' , $ fetchedTag );
97
107
self ::assertStringContainsString ('a commit ' , $ fetchedTag );
98
108
self ::assertStringContainsString ('-----BEGIN PGP SIGNATURE----- ' , $ fetchedTag );
99
109
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 ))(
101
116
$ this ->repository ,
102
117
BranchName::fromName ('tag-branch ' ),
103
- ' name-of-the-tag ' ,
118
+ $ tagName ,
104
119
'changelog text for the tag ' ,
105
120
$ this ->key ,
106
121
);
0 commit comments