Completed
Push — master ( 03ba26...623769 )
by Jacob
34s
created

AssetManagerTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 76
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getTestFilePath() 0 4 1
B setUp() 0 33 1
A tearDown() 0 4 1
A getAsset() 0 4 1
A testStoreAsset() 0 5 1
A testRetrieveAsset() 0 8 1
A testRemoveAsset() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the limit0/assets package.
5
 *
6
 * (c) Limit Zero, LLC <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Limit0\Assets\Tests;
13
14
use Limit0\Assets\AssetManager;
15
use Limit0\Assets\AssetFactory;
16
17
/**
18
 * Mocks and tests AssetManager functionality
19
 *
20
 * @author  Josh Worden <[email protected]>
21
 */
22
class AssetManagerTest extends \PHPUnit_Framework_TestCase
23
{
24
    private $manager;
25
26
    private function getTestFilePath()
27
    {
28
        return sprintf('%s/asset-management.test', sys_get_temp_dir());
29
    }
30
31
    public function setUp()
32
    {
33
        file_put_contents($this->getTestFilePath(), 'Lorem ipsum dolor sit amet.');
34
35
        $engineMock = $this
36
            ->getMockBuilder('Limit0\Assets\StorageEngine\AmazonS3StorageEngine')
37
            ->setMethods(['store', 'retrieve', 'remove'])
38
            ->disableOriginalConstructor()
39
            ->getMockForAbstractClass();
40
41
        $engineMock
42
            ->expects($this->any())
43
            ->method('store')
44
            ->with($this->getAsset())
45
            ->willReturn(true);
46
47
        $identifier = 'some/path/new_file_name.txt';
48
49
        $engineMock
50
            ->expects($this->any())
51
            ->method('retrieve')
52
            ->with($identifier)
53
            ->willReturn($this->getAsset());
54
55
        $engineMock
56
            ->expects($this->any())
57
            ->method('remove')
58
            ->with($identifier)
59
            ->willReturn(false);
60
61
        $this->manager = new AssetManager();
62
        $this->manager->setStorageEngine($engineMock);
63
    }
64
65
    public function tearDown()
66
    {
67
        unlink($this->getTestFilePath());
68
    }
69
70
    private function getAsset()
71
    {
72
        return AssetFactory::createFromPath($this->getTestFilePath());
73
    }
74
75
    public function testStoreAsset()
76
    {
77
        $asset = $this->getAsset();
78
        $this->assertInternalType('boolean', $this->manager->store($asset, 'some/path', 'new_file_name.txt'), 'AssetManager::store must return boolean.');
79
    }
80
81
    /**
82
     *
83
     */
84
    public function testRetrieveAsset()
85
    {
86
        $this->assertInstanceOf(
87
            'Limit0\Assets\Asset',
88
            $this->manager->retrieve('some/path/new_file_name.txt'),
89
            'AssetManager::retrieve must return an Asset instance.'
90
        );
91
    }
92
93
    public function testRemoveAsset()
94
    {
95
        $this->assertInternalType('boolean', $this->manager->remove('some/path/new_file_name.txt'), 'AssetManager::remove must return boolean.');
96
    }
97
}
98