@@ -127,4 +127,47 @@ public function testFooterResetsErrorReportingToOriginalSetting()
127
127
}//end testFooterResetsErrorReportingToOriginalSetting()
128
128
129
129
130
+ /**
131
+ * Safeguard that users won't see a PHP warning about the timezone not being set when calling date().
132
+ *
133
+ * The warning we don't want to see is:
134
+ * "date(): It is not safe to rely on the system's timezone settings. You are *required* to use
135
+ * the date.timezone setting or the date_default_timezone_set() function. In case you used any of
136
+ * those methods and you are still getting this warning, you most likely misspelled the timezone
137
+ * identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select
138
+ * your timezone."
139
+ *
140
+ * JRF: Based on my tests, the warning only occurs on PHP < 7.0, but never a bad thing to safeguard this
141
+ * on a wider range of PHP versions.
142
+ *
143
+ * Note: as of PHP 8.2, PHP no longer accepts an empty string as timezone and will use `UTC` instead,
144
+ * so the warning on calling date() in the code itself would not display anyway.
145
+ *
146
+ * @requires PHP < 8.2
147
+ *
148
+ * @doesNotPerformAssertions
149
+ *
150
+ * @return void
151
+ */
152
+ public function testFooterDoesntThrowWarningOnMissingTimezone ()
153
+ {
154
+ $ originalIni = @ini_set ('date.timezone ' , '' );
155
+
156
+ // Set up the ruleset.
157
+ $ standard = __DIR__ .'/OneDocTest.xml ' ;
158
+ $ config = new ConfigDouble (["--standard= $ standard " ]);
159
+ $ ruleset = new Ruleset ($ config );
160
+
161
+ // We know there will be output, but we're not interested in the output for this test.
162
+ ob_start ();
163
+ $ generator = new MarkdownDouble ($ ruleset );
164
+ $ generator ->printRealFooter ();
165
+ ob_end_clean ();
166
+
167
+ // Reset the timezone to its original state.
168
+ ini_set ('date.timezone ' , $ originalIni );
169
+
170
+ }//end testFooterDoesntThrowWarningOnMissingTimezone()
171
+
172
+
130
173
}//end class
0 commit comments