5
5
namespace Laminas \AutomaticReleases \Test \Unit \Git ;
6
6
7
7
use Laminas \AutomaticReleases \Git \CreateTagViaConsole ;
8
+ use Laminas \AutomaticReleases \Git \HasTag ;
9
+ use Laminas \AutomaticReleases \Git \HasTagViaConsole ;
8
10
use Laminas \AutomaticReleases \Git \Value \BranchName ;
9
11
use Laminas \AutomaticReleases \Gpg \ImportGpgKeyFromStringViaTemporaryFile ;
10
12
use Laminas \AutomaticReleases \Gpg \SecretKeyId ;
@@ -47,18 +49,20 @@ protected function setUp(): void
47
49
public function testCreatesSignedTag (): void
48
50
{
49
51
$ sourceUri = $ this ->createMock (UriInterface::class);
52
+ $ sourceUri ->method ('__toString ' )->willReturn ($ this ->repository );
50
53
51
- $ sourceUri ->method ('__toString ' )
52
- ->willReturn ($ this ->repository );
54
+ $ hasTag = $ this ->createMock (HasTag::class);
55
+ $ hasTag ->method ('__invoke ' )
56
+ ->with ($ this ->repository , 'name-of-the-tag ' )
57
+ ->willReturn (false );
53
58
54
- (new CreateTagViaConsole ())
55
- ->__invoke (
56
- $ this ->repository ,
57
- BranchName::fromName ('tag-branch ' ),
58
- 'name-of-the-tag ' ,
59
- 'changelog text for the tag ' ,
60
- $ this ->key ,
61
- );
59
+ (new CreateTagViaConsole ($ hasTag ))(
60
+ $ this ->repository ,
61
+ BranchName::fromName ('tag-branch ' ),
62
+ 'name-of-the-tag ' ,
63
+ 'changelog text for the tag ' ,
64
+ $ this ->key ,
65
+ );
62
66
63
67
Shell \execute ('git ' , ['tag ' , '-v ' , 'name-of-the-tag ' ], $ this ->repository );
64
68
@@ -69,4 +73,36 @@ public function testCreatesSignedTag(): void
69
73
self ::assertStringContainsString ('a commit ' , $ fetchedTag );
70
74
self ::assertStringContainsString ('-----BEGIN PGP SIGNATURE----- ' , $ fetchedTag );
71
75
}
76
+
77
+ public function testSkipsIfTagAlreadyExists (): void
78
+ {
79
+ $ sourceUri = $ this ->createMock (UriInterface::class);
80
+ $ sourceUri ->method ('__toString ' )->willReturn ($ this ->repository );
81
+
82
+ $ hasTag = new HasTagViaConsole ();
83
+
84
+ (new CreateTagViaConsole ($ hasTag ))(
85
+ $ this ->repository ,
86
+ BranchName::fromName ('tag-branch ' ),
87
+ 'name-of-the-tag ' ,
88
+ 'changelog text for the tag ' ,
89
+ $ this ->key ,
90
+ );
91
+
92
+ Shell \execute ('git ' , ['tag ' , '-v ' , 'name-of-the-tag ' ], $ this ->repository );
93
+ $ fetchedTag = Shell \execute ('git ' , ['show ' , 'name-of-the-tag ' ], $ this ->repository );
94
+
95
+ self ::assertStringContainsString ('tag name-of-the-tag ' , $ fetchedTag );
96
+ self ::assertStringContainsString ('changelog text for the tag ' , $ fetchedTag );
97
+ self ::assertStringContainsString ('a commit ' , $ fetchedTag );
98
+ self ::assertStringContainsString ('-----BEGIN PGP SIGNATURE----- ' , $ fetchedTag );
99
+
100
+ (new CreateTagViaConsole ($ hasTag ))(
101
+ $ this ->repository ,
102
+ BranchName::fromName ('tag-branch ' ),
103
+ 'name-of-the-tag ' ,
104
+ 'changelog text for the tag ' ,
105
+ $ this ->key ,
106
+ );
107
+ }
72
108
}
0 commit comments