Skip to content

Commit

Permalink
fixes #5: temporary files should be deleted during unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OriHoch committed Jul 13, 2017
1 parent 4c5c4c0 commit 5bdc84d
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public function testConstructFromInvalidResource()

public function testDifferentValidDescriptorSources()
{
$simpleFile = tempnam(sys_get_temp_dir(), 'tableschema-php-tests');
$fullFile = tempnam(sys_get_temp_dir(), 'tableschema-php-tests');
$simpleFile = $this->getTempFile();
$fullFile = $this->getTempFile();
file_put_contents($simpleFile, json_encode($this->simpleDescriptor));
file_put_contents($fullFile, json_encode($this->fullDescriptor));
$descriptors = [
Expand Down Expand Up @@ -504,7 +504,7 @@ public function testSchemaToEditableSchema()
public function testSave()
{
$schema = new Schema($this->minDescriptorJson);
$filename = tempnam(sys_get_temp_dir(), 'tableschema-php-tests');
$filename = $this->getTempFile();
$schema->save($filename);
$this->assertEquals($schema->fullDescriptor(), json_decode(file_get_contents($filename)));
}
Expand Down Expand Up @@ -532,6 +532,17 @@ public function testSpecsUriFormat()
]], $validator->getErrors());
}

public function tearDown()
{
foreach ($this->tempFiles as $tempFile) {
if (file_exists($tempFile)) {
unlink($tempFile);
}
}
}

protected $tempFiles = [];

protected function assertValidationErrors($expectedValidationErrors, $descriptor)
{
$this->assertEquals(
Expand Down Expand Up @@ -570,4 +581,12 @@ protected function assertCastRowException($expectedError, $descriptor, $inputRow
$this->assertEquals($expectedError, $e->getMessage());
}
}

protected function getTempFile()
{
$file = tempnam(sys_get_temp_dir(), 'tableschema-php-tests');
$this->tempFiles[] = $file;

return $file;
}
}

0 comments on commit 5bdc84d

Please sign in to comment.