Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 8cf3b7c

Browse files
mlocatiweierophinney
authored andcommitted
Test deleting downloaded file
1 parent 45fdf45 commit 8cf3b7c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/Client/StaticTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,36 @@ public function testOpenTempStreamWithValidFileDoesntThrowsException()
501501
// @todo verify link is still active
502502
}
503503

504+
/**
505+
* Test if a downloaded file can be deleted
506+
*
507+
* @group ZF-9685
508+
*/
509+
public function testDownloadedFileCanBeDeleted()
510+
{
511+
if (! getenv('TESTS_ZEND_HTTP_CLIENT_ONLINE')) {
512+
$this->markTestSkipped('Zend\Http\Client online tests are not enabled');
513+
}
514+
$url = 'http://www.example.com/';
515+
$outputFile = @tempnam(@sys_get_temp_dir(), 'zht');
516+
if (!is_file($outputFile)) {
517+
$this->markTestSkipped('Failed to create a temporary file');
518+
}
519+
$config = [
520+
'outputstream' => $outputFile,
521+
];
522+
$client = new HTTPClient($url, $config);
523+
524+
$result = $client->send();
525+
526+
$this->assertInstanceOf('Zend\Http\Response\Stream', $result);
527+
if (DIRECTORY_SEPARATOR === '\\') {
528+
$this->assertFalse(@unlink($outputFile), 'Deleting an open file should fail on Windows');
529+
}
530+
fclose($result->getStream());
531+
$this->assertTrue(@unlink($outputFile), 'Failed to delete downloaded file');
532+
}
533+
504534
/**
505535
* Testing if the connection can be closed
506536
*

0 commit comments

Comments
 (0)