Passed
Push — master ( e779bf...8d157f )
by Gabriel
03:58
created

FileDiskTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Nip\Filesystem\Tests;
4
5
use League\Flysystem\Adapter\Local;
6
use Nip\Filesystem\FileDisk;
7
use Symfony\Component\HttpFoundation\StreamedResponse;
8
9
/**
10
 * Class FileDiskTest
11
 * @package Nip\Filesystem\Tests
12
 */
13
class FileDiskTest extends AbstractTest
14
{
15
    private $fileDisk;
16
17
    public function testResponse()
18
    {
19
        $this->fileDisk->write('file.txt', 'Hello World');
20
        $response = $this->fileDisk->response('file.txt');
21
22
        ob_start();
23
        $response->sendContent();
24
        $content = ob_get_clean();
25
26
        static::assertInstanceOf(StreamedResponse::class, $response);
27
        static::assertEquals('Hello World', $content);
28
        static::assertEquals('inline; filename=file.txt', $response->headers->get('content-disposition'));
29
    }
30
31
    public function testDownload()
32
    {
33
        $this->fileDisk->write('file.txt', 'Hello World');
34
        $response = $this->fileDisk->download('file.txt', 'hello.txt');
35
        static::assertInstanceOf(StreamedResponse::class, $response);
36
        static::assertEquals('attachment; filename=hello.txt', $response->headers->get('content-disposition'));
37
    }
38
39
    protected function tearDown(): void
40
    {
41
        parent::tearDown();
42
        $filesystem = new FileDisk(new Local(TEST_FIXTURE_PATH . '/storage'));
43
        $filesystem->deleteDir('tmp');
44
    }
45
46
    protected function setUp(): void
47
    {
48
        parent::setUp();
49
50
        $this->fileDisk = new FileDisk(new Local(TEST_FIXTURE_PATH . '/storage/tmp'));
51
    }
52
}