@@ -48,56 +48,71 @@ protected function setUp(): void
4848 #[DataProvider('provideCreateNewChangelog ' )]
4949 public function testCreateNewChangelog (string $ mode ): void
5050 {
51- $ output = exec ('git status --porcelain | wc -l ' );
52-
53- if ($ output !== '0 ' ) {
51+ $ currentVersion = $ this ->currentVersion ;
52+ $ newVersion = $ this ->incrementVersion ($ currentVersion , $ mode );
53+ $ versionWithoutDots = str_replace ('. ' , '' , $ newVersion );
54+ $ changelogPath = "./user_guide_src/source/changelogs/v {$ newVersion }.rst " ;
55+ $ upgradePath = "./user_guide_src/source/installation/upgrade_ {$ versionWithoutDots }.rst " ;
56+ $ trackedPathArgs = implode (' ' , array_map (escapeshellarg (...), [
57+ './system/CodeIgniter.php ' ,
58+ './user_guide_src/source/changelogs/index.rst ' ,
59+ './user_guide_src/source/installation/upgrading.rst ' ,
60+ ]));
61+ $ generatedPathArgs = implode (' ' , array_map (escapeshellarg (...), [
62+ $ changelogPath ,
63+ $ upgradePath ,
64+ ]));
65+ $ statusCount = trim ((string ) exec (
66+ "git status --porcelain -- {$ trackedPathArgs } {$ generatedPathArgs } | wc -l " ,
67+ ));
68+
69+ if ($ statusCount !== '0 ' ) {
5470 $ this ->markTestSkipped ('You have uncommitted operations that will be erased by this test. ' );
5571 }
5672
57- $ currentVersion = $ this ->currentVersion ;
58- $ newVersion = $ this ->incrementVersion ($ currentVersion , $ mode );
59-
60- exec (
61- sprintf ('php ./admin/create-new-changelog.php %s %s --dry-run ' , $ currentVersion , $ newVersion ),
62- $ output ,
63- $ exitCode ,
64- );
65-
66- $ this ->assertSame (0 , $ exitCode , "Script exited with code {$ exitCode }. Output: " . implode ("\n" , $ output ));
67-
68- $ this ->assertStringContainsString (
69- "public const CI_VERSION = ' {$ newVersion }-dev'; " ,
70- $ this ->getContents ('./system/CodeIgniter.php ' ),
71- );
72-
73- $ this ->assertFileExists ("./user_guide_src/source/changelogs/v {$ newVersion }.rst " );
74- $ this ->assertStringContainsString (
75- "Version {$ newVersion }" ,
76- $ this ->getContents ("./user_guide_src/source/changelogs/v {$ newVersion }.rst " ),
77- );
78- $ this ->assertStringContainsString (
79- "** {$ newVersion } release of CodeIgniter4** " ,
80- $ this ->getContents ("./user_guide_src/source/changelogs/v {$ newVersion }.rst " ),
81- );
82- $ this ->assertStringContainsString (
83- $ newVersion ,
84- $ this ->getContents ('./user_guide_src/source/changelogs/index.rst ' ),
85- );
86-
87- $ versionWithoutDots = str_replace ('. ' , '' , $ newVersion );
88- $ this ->assertFileExists ("./user_guide_src/source/installation/upgrade_ {$ versionWithoutDots }.rst " );
89- $ this ->assertStringContainsString (
90- "Upgrading from {$ currentVersion } to {$ newVersion }" ,
91- $ this ->getContents ("./user_guide_src/source/installation/upgrade_ {$ versionWithoutDots }.rst " ),
92- );
93- $ this ->assertStringContainsString (
94- "upgrade_ {$ versionWithoutDots }" ,
95- $ this ->getContents ('./user_guide_src/source/installation/upgrading.rst ' ),
96- );
97-
98- // cleanup added and modified files
99- exec ('git restore . ' );
100- exec ('git clean -fd ' );
73+ try {
74+ $ output = [];
75+
76+ exec (
77+ sprintf ('php ./admin/create-new-changelog.php %s %s --dry-run ' , $ currentVersion , $ newVersion ),
78+ $ output ,
79+ $ exitCode ,
80+ );
81+
82+ $ this ->assertSame (0 , $ exitCode , "Script exited with code {$ exitCode }. Output: " . implode ("\n" , $ output ));
83+
84+ $ this ->assertStringContainsString (
85+ "public const CI_VERSION = ' {$ newVersion }-dev'; " ,
86+ $ this ->getContents ('./system/CodeIgniter.php ' ),
87+ );
88+
89+ $ this ->assertFileExists ($ changelogPath );
90+ $ this ->assertStringContainsString (
91+ "Version {$ newVersion }" ,
92+ $ this ->getContents ($ changelogPath ),
93+ );
94+ $ this ->assertStringContainsString (
95+ "** {$ newVersion } release of CodeIgniter4** " ,
96+ $ this ->getContents ($ changelogPath ),
97+ );
98+ $ this ->assertStringContainsString (
99+ $ newVersion ,
100+ $ this ->getContents ('./user_guide_src/source/changelogs/index.rst ' ),
101+ );
102+
103+ $ this ->assertFileExists ($ upgradePath );
104+ $ this ->assertStringContainsString (
105+ "Upgrading from {$ currentVersion } to {$ newVersion }" ,
106+ $ this ->getContents ($ upgradePath ),
107+ );
108+ $ this ->assertStringContainsString (
109+ "upgrade_ {$ versionWithoutDots }" ,
110+ $ this ->getContents ('./user_guide_src/source/installation/upgrading.rst ' ),
111+ );
112+ } finally {
113+ exec ("git restore -- {$ trackedPathArgs }" );
114+ exec ("git clean -f -- {$ generatedPathArgs }" );
115+ }
101116 }
102117
103118 /**
0 commit comments