Fix "Cannot open file" issue with XMLReader::open on Windows
This occurred when using relative paths. Using realpath() solves this issue.
This commit is contained in:
1 parent
45980195cd
commit
01cc8b3da0
5 files changed
+111
-13
No files matched your search
@@ -163,4 +163,39 @@ class XMLReaderTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals($expectedResult, $isZipStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dataProviderForTestConvertURIToUseRealPath()
|
||||
{
|
||||
$tempFolder = realpath(sys_get_temp_dir());
|
||||
|
||||
return [
|
||||
['/../../../' . $tempFolder . '/test.xlsx', $tempFolder . '/test.xlsx'],
|
||||
[$tempFolder . '/test.xlsx', $tempFolder . '/test.xlsx'],
|
||||
['zip://' . $tempFolder . '/test.xlsx#test.xml', 'zip://' . $tempFolder . '/test.xlsx#test.xml'],
|
||||
['zip:///../../../' . $tempFolder . '/test.xlsx#test.xml', 'zip://' . $tempFolder . '/test.xlsx#test.xml'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataProviderForTestConvertURIToUseRealPath
|
||||
*
|
||||
* @param string $URI
|
||||
* @param string $expectedConvertedURI
|
||||
* @return void
|
||||
*/
|
||||
public function testConvertURIToUseRealPath($URI, $expectedConvertedURI)
|
||||
{
|
||||
$tempFolder = sys_get_temp_dir();
|
||||
touch($tempFolder . '/test.xlsx');
|
||||
|
||||
$xmlReader = new XMLReader();
|
||||
$convertedURI = \ReflectionHelper::callMethodOnObject($xmlReader, 'convertURIToUseRealPath', $URI);
|
||||
|
||||
$this->assertEquals($expectedConvertedURI, $convertedURI);
|
||||
|
||||
unlink($tempFolder . '/test.xlsx');
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,13 @@ namespace Box\Spout;
|
||||
trait TestUsingResource {
|
||||
|
||||
/** @var string Path to the test resources folder */
|
||||
private $resourcesPath = 'tests/resources/';
|
||||
private $resourcesPath = 'tests/resources';
|
||||
|
||||
/** @var string Path to the test generated resources folder */
|
||||
private $generatedResourcesPath = 'tests/resources/generated/';
|
||||
private $generatedResourcesPath = 'tests/resources/generated';
|
||||
|
||||
/** @var string Path to the test resources folder, that does not have writing permissions */
|
||||
private $generatedUnwritableResourcesPath = 'tests/resources/generated/unwritable/';
|
||||
private $generatedUnwritableResourcesPath = 'tests/resources/generated/unwritable';
|
||||
|
||||
/**
|
||||
* @param string $resourceName
|
||||
@@ -25,7 +25,7 @@ trait TestUsingResource {
|
||||
protected function getResourcePath($resourceName)
|
||||
{
|
||||
$resourceType = pathinfo($resourceName, PATHINFO_EXTENSION);
|
||||
$resourcePath = $this->resourcesPath . strtolower($resourceType) . '/' . $resourceName;
|
||||
$resourcePath = realpath($this->resourcesPath) . '/' . strtolower($resourceType) . '/' . $resourceName;
|
||||
|
||||
return (file_exists($resourcePath) ? $resourcePath : null);
|
||||
}
|
||||
@@ -37,7 +37,7 @@ trait TestUsingResource {
|
||||
protected function getGeneratedResourcePath($resourceName)
|
||||
{
|
||||
$resourceType = pathinfo($resourceName, PATHINFO_EXTENSION);
|
||||
$generatedResourcePath = $this->generatedResourcesPath . strtolower($resourceType) . '/' . $resourceName;
|
||||
$generatedResourcePath = realpath($this->generatedResourcesPath) . '/' . strtolower($resourceType) . '/' . $resourceName;
|
||||
|
||||
return $generatedResourcePath;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ trait TestUsingResource {
|
||||
protected function createGeneratedFolderIfNeeded($resourceName)
|
||||
{
|
||||
$resourceType = pathinfo($resourceName, PATHINFO_EXTENSION);
|
||||
$generatedResourcePathForType = $this->generatedResourcesPath . strtolower($resourceType);
|
||||
$generatedResourcePathForType = $this->generatedResourcesPath . '/' . strtolower($resourceType);
|
||||
|
||||
if (!file_exists($generatedResourcePathForType)) {
|
||||
mkdir($generatedResourcePathForType, 0777, true);
|
||||
@@ -62,7 +62,7 @@ trait TestUsingResource {
|
||||
*/
|
||||
protected function getGeneratedUnwritableResourcePath($resourceName)
|
||||
{
|
||||
return $this->generatedUnwritableResourcesPath . $resourceName;
|
||||
return realpath($this->generatedUnwritableResourcesPath) . '/' . $resourceName;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user