|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @see https://github.com/zendframework/zend-diactoros for the canonical source repository |
| 4 | + * @copyright Copyright (c) 2015-2018 Zend Technologies USA Inc. (http://www.zend.com) |
| 5 | + * @license https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License |
| 6 | + */ |
| 7 | + |
| 8 | +declare(strict_types=1); |
| 9 | + |
| 10 | +namespace ZendTest\Diactoros\Response; |
| 11 | + |
| 12 | +use org\bovigo\vfs\vfsStream; |
| 13 | +use PHPUnit\Framework\TestCase; |
| 14 | +use Zend\Diactoros\Response; |
| 15 | +use Zend\Diactoros\Response\DownloadResponse; |
| 16 | + |
| 17 | +class DownloadResponseTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @var \org\bovigo\vfs\vfsStreamDirectory |
| 21 | + */ |
| 22 | + private $root; |
| 23 | + |
| 24 | + public function setUp() |
| 25 | + { |
| 26 | + $validCSVString = <<<EOF |
| 27 | +name,address,email,street,city,state,country |
| 28 | +Victoria Freeman,1770 Urfe Pass,[email protected],Ipziw Grove,Uzfujnic,SD,KN |
| 29 | +Kathryn Reynolds,861 Nircu Mill,[email protected],Kaid Court,Botpupe,CA,WS |
| 30 | +Dora Schmidt,703 Laufo Heights,[email protected],Sowdu Key,Pojzudiz,FL,TN |
| 31 | +Delia Harrison,1409 Abeeli Loop,[email protected],Dulgi Heights,Eswooke,MN,DZ |
| 32 | +Jordan Lane,1409 Zihoce Plaza,[email protected],Acfuh View,Dulwawa,NY,NF |
| 33 | +Danny Holmes,502 Fubjib Parkway,[email protected],Apsa Loop,Etaweza,CO,MQ |
| 34 | +Clarence Brewer,1085 Jacpa View,[email protected],Baroh Highway,Tikawi,WA,LS |
| 35 | +Elmer Cohen,1556 Netjol Heights,[email protected],Dacbap Trail,Kihiguk,UT,WS |
| 36 | +EOF; |
| 37 | + |
| 38 | + $directoryStructure = [ |
| 39 | + 'files' => [ |
| 40 | + 'empty.csv' => "", |
| 41 | + 'valid.csv' => $validCSVString, |
| 42 | + 'non-readable-file.csv' => vfsStream::newFile('non-readable-file.csv', 0000) |
| 43 | + ] |
| 44 | + ]; |
| 45 | + $this->root = vfsStream::setup('root', null, $directoryStructure); |
| 46 | + } |
| 47 | + |
| 48 | + public function testCanCreateResponseFromString() |
| 49 | + { |
| 50 | + $csvString = file_get_contents($this->root->url() . '/files/valid.csv'); |
| 51 | + $response = new DownloadResponse($csvString); |
| 52 | + $this->assertInstanceOf(Response::class, $response); |
| 53 | + $this->assertEquals($csvString, (string) $response->getBody()->getContents()); |
| 54 | + $this->assertArrayHasKey('cache-control', $response->getHeaders()); |
| 55 | + } |
| 56 | +} |
0 commit comments