testAmazonConfigAclInvalid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
c 0
b 0
f 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Partnermarketing\FileSystemBundle\Tests\Functional\Factory;
4
5
use Partnermarketing\FileSystemBundle\Factory\FileSystemFactory;
6
use Partnermarketing\TestBundle\Tests\Base\BaseFunctionalTest;
7
8
class FileSystemFactoryTest extends \PHPUnit_Framework_TestCase
9
{
10 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
11
    {
12
        $this->config = [
0 ignored issues
show
Bug introduced by
The property config does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
13
            'local_storage' => ['path' => '', 'url' => ''],
14
            'amazon_s3' => ['key' => '', 'secret' => '', 'region' => '', 'bucket' => ''],
15
        ];
16
        $this->factory = new FileSystemFactory('local_storage', $this->config, '/tmp');
0 ignored issues
show
Bug introduced by
The property factory does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17
    }
18
19
    /**
20
     * @expectedException \Exception
21
     * @expectedExceptionMessage the given adapter name did not match any existing file system
22
     */
23
    public function testThrowsAnErrorForInvalidAdapter()
24
    {
25
        $this->factory->build('xyz');
26
    }
27
28
    public function testBuildDefault()
29
    {
30
        $this->assertInstanceOf(
31
            'Partnermarketing\FileSystemBundle\Adapter\AdapterInterface',
32
            $this->factory->build()
33
        );
34
    }
35
36
    public function testBuildLocalStorage()
37
    {
38
        $this->assertInstanceOf(
39
            'Partnermarketing\FileSystemBundle\Adapter\LocalStorage',
40
            $this->factory->build('local_storage')
41
        );
42
    }
43
44
    public function testBuildAmazonS3()
45
    {
46
        $this->assertInstanceOf(
47
            'Partnermarketing\FileSystemBundle\Adapter\AmazonS3',
48
            $this->factory->build('amazon_s3')
49
        );
50
    }
51
52
    /**
53
     * @expectedException \Exception
54
     * @expectedExceptionMessage Invalid S3 acl value.
55
     */
56 View Code Duplication
    public function testAmazonConfigAclInvalid()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
    {
58
        $this->config = [
59
            'local_storage' => ['path' => '', 'url' => ''],
60
            'amazon_s3' => ['key' => '', 'secret' => '', 'region' => '', 'bucket' => '', 'acl' => 'read'],
61
        ];
62
        $this->factory = new FileSystemFactory('amazon_s3', $this->config, '/tmp');
63
        $this->factory->build('amazon_s3');
64
    }
65
66
    /**
67
     * Should
68
     */
69 View Code Duplication
    public function testAmazonConfigAclValid()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $this->config = [
72
            'local_storage' => ['path' => '', 'url' => ''],
73
            'amazon_s3' => ['key' => '', 'secret' => '', 'region' => '', 'bucket' => '', 'acl' => 'public-read'],
74
        ];
75
        $this->factory = new FileSystemFactory('amazon_s3', $this->config, '/tmp');
76
77
        $s3Adaptor = $this->factory->build('amazon_s3');
78
        $this->assertInstanceOf('Partnermarketing\FileSystemBundle\Adapter\AmazonS3', $s3Adaptor);
79
    }
80
    
81
    public function testDefaultsTempDirCorrectly()
82
    {
83
        if (defined('HHVM_VERSION')) {
84
            $this->markTestSkipped('HHVM does not support the moving of the configured temp directory as PHP does.');
85
        }
86
        
87
        //Force PHP to use this directory as the system temp directory.
88
        putenv('TMPDIR='.__DIR__.'/');
89
        
90
        $this->config = [
91
            'local_storage' => ['path' => '', 'url' => 'http://localhost/tmp'],
92
            'amazon_s3' => ['key' => '', 'secret' => '', 'region' => '', 'bucket' => ''],
93
        ];
94
        $this->factory = new FileSystemFactory('amazon_s3', $this->config);
95
        $adapter = $this->factory->build('local_storage');
96
        
97
        $initFile = __DIR__.'/lorem.txt';
98
        $adapter->writeContent($initFile, 'Lorem Ipsum');
99
        $tmpFile = $adapter->copyToLocalTemporaryFile($initFile);
100
        
101
        $this->assertCount(4, $adapter->getFiles(__DIR__));
102
        $this->assertTrue($adapter->exists($tmpFile));
103
        
104
        $adapter->delete($initFile);
105
        $adapter->delete($tmpFile);
106
        $adapter->delete(substr($tmpFile, 0, (strrpos($tmpFile, "."))));
107
    }
108
}
109