Skip to content

Commit

Permalink
[zend-loader] fix failing Zend_Loader_PluginLoaderTest on windows (#154)
Browse files Browse the repository at this point in the history
on php versions lower than 7.4, `file_get_contents` on `flock`-ed file returned empty string on Windows
starting php 7.4, it throws an error "file_get_contents(): read of 8192 bytes failed with errno=13 Permission denied"
see https://bugs.php.net/bug.php?id=79398

On windows, file lock needs to be released before reading file contents, even if it's within the same process.
  • Loading branch information
marcing authored Dec 2, 2022
1 parent 87d22a5 commit e0b1c65
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tests/Zend/Loader/PluginLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,20 @@ public function testPluginLoaderShouldAppendIncludeCacheWhenClassIsFound()
$this->fail(sprintf("Failed loading helper; paths: %s", var_export($paths, 1)));
}
$this->assertTrue(file_exists($cacheFile));
$cache = file_get_contents($cacheFile);
if (substr(PHP_OS, 0, 3) !== 'WIN') {
// windows reads an empty string, without any error, if a file is flock-ed...
$this->assertContains('CacheTest.php', $cache);

// on php versions lower than 7.4, file_get_contents returned empty string on Windows
// starting php 7.4, it throws an error "file_get_contents(): read of 8192 bytes failed with errno=13 Permission denied"
// releasing the lock helps in this case and contents are returned properly
// @see https://bugs.php.net/bug.php?id=79398
// releasing the lock is conducted by passing "null" value to setIncludeFileCache method

if (substr(PHP_OS, 0, 3) === 'WIN') {
Zend_Loader_PluginLoader::setIncludeFileCache(null);
}

$cache = file_get_contents($cacheFile);

$this->assertContains('CacheTest.php', $cache);
}

/**
Expand Down

0 comments on commit e0b1c65

Please sign in to comment.