@@ -117,7 +117,7 @@ public function dataCache()
117117 'json ' ,
118118 'json/syllable.en-us.json ' ,
119119 '{ ' .
120- '"version":1.4, ' .
120+ '"version":" 1.4" , ' .
121121 '"patterns":{%a}, ' .
122122 '"max_pattern":9, ' .
123123 '"hyphenation":{%a}, ' .
@@ -131,7 +131,7 @@ public function dataCache()
131131 'serialized ' ,
132132 'serialized/syllable.en-us.serialized ' ,
133133 'a:6:{ ' .
134- 's:7:"version";d: 1.4; ' .
134+ 's:7:"version";s:3:" 1.4" ; ' .
135135 's:8:"patterns";a:4939:{%a} ' .
136136 's:11:"max_pattern";i:9; ' .
137137 's:11:"hyphenation";a:15:{%a} ' .
@@ -169,14 +169,41 @@ public function testCache($cacheClass, $language, $cacheDirectory, $cacheFile, $
169169
170170 $ this ->assertFileExists ($ cacheFile );
171171 $ this ->assertStringMatchesFormat ($ expectedCacheContent , file_get_contents ($ cacheFile ));
172- $ this ->assertSame (1.4 , $ this ->object ->getCache ()->__get ('version ' ));
172+ $ this ->assertSame (' 1.4 ' , $ this ->object ->getCache ()->__get ('version ' ));
173173 $ this ->assertNotEmpty ($ this ->object ->getCache ()->__get ('patterns ' ));
174174 $ this ->assertGreaterThan (0 , $ this ->object ->getCache ()->__get ('max_pattern ' ));
175175 $ this ->assertNotEmpty ($ this ->object ->getCache ()->__get ('hyphenation ' ));
176176 $ this ->assertInternalType ('int ' , $ this ->object ->getCache ()->__get ('left_min_hyphen ' ));
177177 $ this ->assertInternalType ('int ' , $ this ->object ->getCache ()->__get ('right_min_hyphen ' ));
178178 }
179179
180+ public function dataCacheVersionMatchesCacheFileVersionIsRelaxed ()
181+ {
182+ return [
183+ 'Cache file version is float. ' => [1.4 ],
184+ 'Cache file version is string. ' => ['1.4 ' ],
185+ 'Cache file version is float with unexpected precision. ' => [1.3999999999999999 ],
186+ 'Cache file version is string with unexpected precision. ' => ['1.3999999999999999 ' ],
187+ ];
188+ }
189+
190+ /**
191+ * Some PHP versions have the Syllable cache version number 1.4 encoded in 1.39999999999999
192+ * instead of 1.4 in the cache files. To fix this, the internal representation of
193+ * the cache version is changed from float to string. This test shows that the user's existing
194+ * cache files are still valid after this change and do not need to be recreated.
195+ *
196+ * @dataProvider dataCacheVersionMatchesCacheFileVersionIsRelaxed
197+ *
198+ * @return void
199+ */
200+ public function testCacheVersionMatchesCacheFileVersionIsRelaxed ($ cacheFileVersion )
201+ {
202+ $ cacheVersion = '1.4 ' ;
203+
204+ $ this ->assertTrue ($ cacheVersion == $ cacheFileVersion );
205+ }
206+
180207 /**
181208 * @todo Implement testSetSource().
182209 */
0 commit comments