Fix tests on Windows (#288)
This commit is contained in:
parent
7f65993c87
commit
b2dc0c3fa9
@ -138,11 +138,12 @@ class XMLReaderTest extends \PHPUnit_Framework_TestCase
|
||||
public function dataProviderForTestGetRealPathURIForFileInZip()
|
||||
{
|
||||
$tempFolder = realpath(sys_get_temp_dir());
|
||||
$tempFolderName = basename($tempFolder);
|
||||
$expectedRealPathURI = 'zip://' . $tempFolder . '/test.xlsx#test.xml';
|
||||
|
||||
return [
|
||||
[$tempFolder, "$tempFolder/test.xlsx", 'test.xml', $expectedRealPathURI],
|
||||
[$tempFolder, "/../../../$tempFolder/test.xlsx", 'test.xml', $expectedRealPathURI],
|
||||
[$tempFolder, "$tempFolder/../$tempFolderName/test.xlsx", 'test.xml', $expectedRealPathURI],
|
||||
];
|
||||
}
|
||||
|
||||
@ -162,7 +163,11 @@ class XMLReaderTest extends \PHPUnit_Framework_TestCase
|
||||
$xmlReader = new XMLReader();
|
||||
$realPathURI = \ReflectionHelper::callMethodOnObject($xmlReader, 'getRealPathURIForFileInZip', $zipFilePath, $fileInsideZipPath);
|
||||
|
||||
$this->assertEquals($expectedRealPathURI, $realPathURI);
|
||||
// Normalizing path separators for Windows support
|
||||
$normalizedRealPathURI = str_replace('\\', '/', $realPathURI);
|
||||
$normalizedExpectedRealPathURI = str_replace('\\', '/', $expectedRealPathURI);
|
||||
|
||||
$this->assertEquals($normalizedExpectedRealPathURI, $normalizedRealPathURI);
|
||||
|
||||
unlink($tempFolder . '/test.xlsx');
|
||||
}
|
||||
|
@ -7,8 +7,8 @@ namespace Box\Spout;
|
||||
*
|
||||
* @package Box\Spout
|
||||
*/
|
||||
trait TestUsingResource {
|
||||
|
||||
trait TestUsingResource
|
||||
{
|
||||
/** @var string Path to the test resources folder */
|
||||
private $resourcesPath = 'tests/resources';
|
||||
|
||||
@ -70,6 +70,11 @@ trait TestUsingResource {
|
||||
*/
|
||||
protected function createUnwritableFolderIfNeeded()
|
||||
{
|
||||
// On Windows, chmod() or the mkdir's mode is ignored
|
||||
if ($this->isWindows()) {
|
||||
$this->markTestSkipped('Skipping because Windows cannot create read-only folders through PHP');
|
||||
}
|
||||
|
||||
if (!file_exists($this->generatedUnwritableResourcesPath)) {
|
||||
// Make sure generated folder exists first
|
||||
if (!file_exists($this->generatedResourcesPath)) {
|
||||
@ -80,4 +85,12 @@ trait TestUsingResource {
|
||||
mkdir($this->generatedUnwritableResourcesPath, 0444, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool Whether the OS on which PHP is installed is Windows
|
||||
*/
|
||||
protected function isWindows()
|
||||
{
|
||||
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ class WriterTest extends \PHPUnit_Framework_TestCase
|
||||
public function testWriteShouldThrowExceptionIfCannotOpenFileForWriting()
|
||||
{
|
||||
$fileName = 'file_that_wont_be_written.csv';
|
||||
$this->createUnwritableFolderIfNeeded($fileName);
|
||||
$this->createUnwritableFolderIfNeeded();
|
||||
$filePath = $this->getGeneratedUnwritableResourcePath($fileName);
|
||||
|
||||
$writer = WriterFactory::create(Type::CSV);
|
||||
|
Loading…
x
Reference in New Issue
Block a user