66
77use Bizkit \VersioningBundle \DependencyInjection \Configuration ;
88use Bizkit \VersioningBundle \Tests \TestCase ;
9+ use Bizkit \VersioningBundle \VCS \TaggingMode ;
10+ use Symfony \Component \Config \Definition \Exception \InvalidConfigurationException ;
911use Symfony \Component \Config \Definition \Processor ;
1012
1113/**
@@ -26,7 +28,7 @@ public function testDefaultConfig(): void
2628 'vcs ' => [
2729 'handler ' => 'git ' ,
2830 'commit_message ' => 'Update application version to %s ' ,
29- 'tagging_mode ' => ' ask ' ,
31+ 'tagging_mode ' => TaggingMode::Ask ,
3032 'tag_message ' => 'Update application version to %s ' ,
3133 'name ' => null ,
3234 'email ' => null ,
@@ -45,7 +47,7 @@ public function testConfigWhenVCSIsTrue(): void
4547 self ::assertSame ([
4648 'handler ' => 'git ' ,
4749 'commit_message ' => 'Update application version to %s ' ,
48- 'tagging_mode ' => ' ask ' ,
50+ 'tagging_mode ' => TaggingMode::Ask ,
4951 'tag_message ' => 'Update application version to %s ' ,
5052 'name ' => null ,
5153 'email ' => null ,
@@ -63,11 +65,53 @@ public function testConfigWhenVCSIsFalse(): void
6365 self ::assertSame ([
6466 'handler ' => null ,
6567 'commit_message ' => 'Update application version to %s ' ,
66- 'tagging_mode ' => ' ask ' ,
68+ 'tagging_mode ' => TaggingMode::Ask ,
6769 'tag_message ' => 'Update application version to %s ' ,
6870 'name ' => null ,
6971 'email ' => null ,
7072 'path_to_executable ' => null ,
7173 ], $ config ['vcs ' ]);
7274 }
75+
76+ /**
77+ * @dataProvider provideVCSTaggingModeAsStringCases
78+ */
79+ public function testConfigWhenVCSTaggingModeIsString (string $ taggingMode , TaggingMode $ expectedTaggingMode ): void
80+ {
81+ $ config = (new Processor ())->processConfiguration (new Configuration (), ['bizkit_versioning ' => [
82+ 'vcs ' => [
83+ 'tagging_mode ' => $ taggingMode ,
84+ ],
85+ ]]);
86+
87+ self ::assertArrayHasKey ('vcs ' , $ config );
88+ self ::assertSame ([
89+ 'tagging_mode ' => $ expectedTaggingMode ,
90+ 'handler ' => 'git ' ,
91+ 'commit_message ' => 'Update application version to %s ' ,
92+ 'tag_message ' => 'Update application version to %s ' ,
93+ 'name ' => null ,
94+ 'email ' => null ,
95+ 'path_to_executable ' => null ,
96+ ], $ config ['vcs ' ]);
97+ }
98+
99+ public static function provideVCSTaggingModeAsStringCases (): iterable
100+ {
101+ yield ['always ' , TaggingMode::Always];
102+ yield ['ask ' , TaggingMode::Ask];
103+ yield ['never ' , TaggingMode::Never];
104+ }
105+
106+ public function testConfigWhenVCSTaggingModeIsInvalidString (): void
107+ {
108+ $ this ->expectException (InvalidConfigurationException::class);
109+ $ this ->expectExceptionMessage ('Invalid tagging mode provided: expected one of "always", "ask", "never", got "invalid_mode". ' );
110+
111+ (new Processor ())->processConfiguration (new Configuration (), ['bizkit_versioning ' => [
112+ 'vcs ' => [
113+ 'tagging_mode ' => 'invalid_mode ' ,
114+ ],
115+ ]]);
116+ }
73117}
0 commit comments