BlobStoreIntegrationTestCase::testExpiry()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 31
rs 8.8571
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
namespace Onoi\BlobStore\Tests\Integration;
4
5
use Onoi\BlobStore\BlobStore;
6
7
/**
8
 * @group onoi-blobstore
9
 *
10
 * @license GNU GPL v2+
11
 * @since 1.0
12
 *
13
 * @author mwjames
14
 */
15
abstract class BlobStoreIntegrationTestCase extends \PHPUnit_Framework_TestCase {
16
17
	protected $cache;
18
19
	public function testStorageAndRetrieval() {
20
21
		$blobStore = new BlobStore( 'Foo', $this->cache );
22
		$container = $blobStore->read( 'bar' );
23
24
		$some = new \stdClass;
25
		$some->foo = 42;
26
27
		$container->set( 'one', $some );
28
29
		$this->assertEquals(
30
			$some,
31
			$container->get( 'one' )
32
		);
33
34
		$blobStore->save( $container );
35
36
		$container = $blobStore->read( 'foobar' );
37
		$container->set( 'two', 'anotherText' );
38
39
		$container->append(
40
			'two',
41
			$blobStore->read( 'bar' )->get( 'one' )
42
		);
43
44
		$container->append(
45
			'two',
46
			$some
47
		);
48
49
		$this->assertEquals(
50
			array( 'anotherText', $some, $some ),
51
			$container->get( 'two' )
52
		);
53
	}
54
55
	public function testDeleteSingleContainer() {
56
57
		$blobStore = new BlobStore( 'Foo', $this->cache );
58
59
		$container = $blobStore->read( 'foobar' );
60
		$container->set( 'one', 42 );
61
		$blobStore->save( $container );
62
63
		$this->assertTrue(
64
			$blobStore->exists( 'foobar' )
65
		);
66
67
		$blobStore->delete( 'foobar' );
68
69
		$this->assertFalse(
70
			$blobStore->exists( 'foobar' )
71
		);
72
	}
73
74
	public function testExpiry() {
75
76
		$blobStore = new BlobStore( 'Foo', $this->cache );
77
		$blobStore->setExpiryInSeconds( 4 );
78
79
		$container = $blobStore->read( 'bar' );
80
		$container->set( 'one', 1001 );
81
		$blobStore->save( $container );
82
83
		$container = $blobStore->read( 'foo' );
84
		$container->set( 'one', 42 );
85
		$blobStore->save( $container );
86
87
		$this->assertTrue(
88
			$blobStore->exists( 'bar' )
89
		);
90
91
		$this->assertTrue(
92
			$blobStore->exists( 'foo' )
93
		);
94
95
		sleep( 5 );
96
97
		$this->assertFalse(
98
			$blobStore->exists( 'bar' )
99
		);
100
101
		$this->assertFalse(
102
			$blobStore->exists( 'foo' )
103
		);
104
	}
105
106
}
107