This is a small change to the way the tests run. It doesn't change the meaning of the test.
Before
------
* Writes example file to `/tmp/versionCheckTestFile.json`.
* File left behind at end of test.
* If two users runs the same test at different times, they could interfere with each other.
* If two processes run the same test at the same time, they could interfere with each other.
After
-----
* Writes example file to `/tmp/VersionCheck-NNNNNNN/versionCheckTestFile.json`
* Temp folder cleaned up at end
* If two users or two processes run the test, they use separate folders
*/
class CRM_Utils_versionCheckTest extends CiviUnitTestCase {
+ /**
+ * @var string
+ */
+ protected $tempDir;
+
public function setUp(): void {
$this->useTransaction();
parent::setUp();
+ $this->tempDir = sys_get_temp_dir() . '/VersionCheck-' . rand() . rand();
+ mkdir($this->tempDir);
}
/**
if (file_exists($vc->cacheFile)) {
unlink($vc->cacheFile);
}
+ if (file_exists($this->tempDir)) {
+ CRM_Utils_File::cleanDir($this->tempDir, TRUE, FALSE);
+ }
}
public function testCronFallback() {
// Fake "remote" source data
- $tmpSrc = '/tmp/versionCheckTestFile.json';
+ $tmpSrc = $this->tempDir . '/versionCheckTestFile.json';
file_put_contents($tmpSrc, json_encode($this->sampleVersionInfo));
$vc = new CRM_Utils_VersionCheck();