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

AbstractStorageEngineTest::getTestAsset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
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\StorageEngine;
13
14
use Limit0\Assets\AssetFactory;
15
16
/**
17
 * Provides common tests for all storage engines
18
 *
19
 * @author  Josh Worden <[email protected]>
20
 */
21
abstract class AbstractStorageEngineTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @var     \Limit0\Assets\StorageEngineInterface
25
     */
26
    protected static $engine;
27
28
    public function testEngineSetUp()
29
    {
30
        $this->assertInstanceOf('Limit0\Assets\StorageEngineInterface', self::$engine, 'Storage engine was not set up before test.');
31
    }
32
33
    public function testEngineStorage()
34
    {
35
        $result = self::$engine->store(
36
            $this->getTestAsset(),
37
            $this->getTestPath(),
38
            $this->getTestFilename()
39
        );
40
41
        $this->assertTrue($result, 'StorageEngine did not return a good value.');
42
    }
43
44
    public function testEngineRetrieval()
45
    {
46
        $asset = self::$engine->retrieve($this->getTestIdentifier());
47
        $this->assertInstanceOf('Limit0\Assets\Asset', $asset);
48
    }
49
50
    public function testEngineRemoval()
51
    {
52
        $result = self::$engine->remove($this->getTestIdentifier());
53
        $this->assertTrue($result, 'StorageEngine did not return a good value.');
54
    }
55
56
    protected function getTestAsset()
57
    {
58
        $path = sprintf('%s/asset-management.test', sys_get_temp_dir());
59
        file_put_contents($path, 'Lorem ipsum dolor sit amet.');
60
        return AssetFactory::createFromPath($path);
61
    }
62
63
    protected function getTestPath()
64
    {
65
        return 'test/directory/structure';
66
    }
67
68
    protected function getTestFilename()
69
    {
70
        return 'asset-management.test';
71
    }
72
73
    protected function getTestIdentifier()
74
    {
75
        return sprintf('%s/%s', $this->getTestPath(), $this->getTestFilename());
76
    }
77
}
78