Passed
Push — master ( 270ec8...6c3449 )
by Aimeos
02:04
created

RedisTest::testGetSubManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://www.gnu.org/licenses/lgpl.html
5
 * @copyright Metaways Infosystems GmbH, 2014
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 */
8
9
10
namespace Aimeos\MAdmin\Cache\Manager;
11
12
13
class RedisTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
{
15
	private $object;
16
17
18
	protected function setUp()
19
	{
20
		$this->context = \TestHelper::getContext();
0 ignored issues
show
Bug Best Practice introduced by
The property context does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
		$this->object = new \Aimeos\MAdmin\Cache\Manager\Redis( $this->context );
22
	}
23
24
25
	protected function tearDown()
26
	{
27
		$this->object = null;
28
	}
29
30
31
	public function testClear()
32
	{
33
		$this->object->clear( array( -1 ) );
34
	}
35
36
37
	public function testCreateItem()
38
	{
39
		$this->assertInstanceOf( '\\Aimeos\\MAdmin\\Cache\\Item\\Iface', $this->object->createItem() );
40
	}
41
42
43
	public function testGetSearchAttributes()
44
	{
45
		foreach( $this->object->getSearchAttributes() as $attr ) {
46
			$this->assertInstanceOf('\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attr );
47
		}
48
	}
49
50
51
	public function testGetSubManager()
52
	{
53
		$this->setExpectedException('\\Aimeos\\MAdmin\\Exception');
54
		$this->object->getSubManager( 'unknown' );
55
	}
56
57
58
	public function testSearchItems()
59
	{
60
		$search = $this->object->createSearch();
61
		$search->setConditions( $search->compare( '==', 'cache.id', 'unittest' ) );
62
63
		$this->assertEquals( [], $this->object->searchItems( $search ) );
64
	}
65
66
67
	public function testGetItem()
68
	{
69
		$context = \TestHelper::getContext();
70
71
		$mockRedis = $this->getMockBuilder( '\\Aimeos\\MW\\Cache\\Redis' )
72
			->disableOriginalConstructor()->setMethods( array( 'get' ) )->getMock();
73
74
		$mockRedis->expects( $this->once() )->method( 'get' )->will( $this->returnValue( 'test value' ) );
75
76
		$mock = $this->getMockBuilder( '\\Aimeos\\MAdmin\\Cache\\Manager\\Redis' )
77
			->setConstructorArgs( array( $context ) )->setMethods( array( 'getCache' ) )->getMock();
78
79
		$mock->expects( $this->once() )->method( 'getCache' )->will( $this->returnValue( $mockRedis ) );
80
81
		$this->assertInstanceOf( '\\Aimeos\\MAdmin\\Cache\\Item\\Iface', $mock->getItem( 'test' ) );
82
	}
83
84
85
	public function testGetItemException()
86
	{
87
		$context = \TestHelper::getContext();
88
89
		$mockRedis = $this->getMockBuilder( '\\Aimeos\\MW\\Cache\\Redis' )
90
			->disableOriginalConstructor()->setMethods( array( 'get' ) )->getMock();
91
92
		$mock = $this->getMockBuilder( '\\Aimeos\\MAdmin\\Cache\\Manager\\Redis' )
93
			->setConstructorArgs( array( $context ) )->setMethods( array( 'getCache' ) )->getMock();
94
95
		$mock->expects( $this->once() )->method( 'getCache' )->will( $this->returnValue( $mockRedis ) );
96
97
		$this->setExpectedException( '\\Aimeos\\MAdmin\\Cache\\Exception' );
98
		$mock->getItem( 'test' );
99
	}
100
101
102
	public function testSaveItem()
103
	{
104
		$context = \TestHelper::getContext();
105
106
		$mockRedis = $this->getMockBuilder( '\\Aimeos\\MW\\Cache\\Redis' )
107
			->disableOriginalConstructor()->setMethods( array( 'delete', 'set' ) )->getMock();
108
109
		$mockRedis->expects( $this->once() )->method( 'delete' );
110
		$mockRedis->expects( $this->once() )->method( 'set' );
111
112
		$mock = $this->getMockBuilder( '\\Aimeos\\MAdmin\\Cache\\Manager\\Redis' )
113
			->setConstructorArgs( array( $context ) )->setMethods( array( 'getCache' ) )->getMock();
114
115
		$mock->expects( $this->once() )->method( 'getCache' )->will( $this->returnValue( $mockRedis ) );
116
117
		$item = $mock->createItem();
118
		$item->setId( 'test' );
119
120
		$mock->saveItem( $item );
121
	}
122
123
124
	public function testSaveItemNotModified()
125
	{
126
		$context = \TestHelper::getContext();
127
128
		$mock = $this->getMockBuilder( '\\Aimeos\\MAdmin\\Cache\\Manager\\Redis' )
129
			->setConstructorArgs( array( $context ) )->setMethods( array( 'getCache' ) )->getMock();
130
131
		$mock->saveItem( $mock->createItem() );
132
	}
133
134
135
	public function testDeleteItems()
136
	{
137
		$mockRedis = $this->getMockBuilder( '\\Aimeos\\MW\\Cache\\Redis' )
138
			->disableOriginalConstructor()->setMethods( array( 'deleteMultiple' ) )->getMock();
139
140
		$mock = $this->getMockBuilder( '\\Aimeos\\MAdmin\\Cache\\Manager\\Redis' )
141
			->disableOriginalConstructor()->setMethods( array( 'getCache' ) )->getMock();
142
143
		$mock->expects( $this->once() )->method( 'getCache' )->will( $this->returnValue( $mockRedis ) );
144
145
		$mock->deleteItems( [] );
146
	}
147
148
149
	public function testGetCache()
150
	{
151
		try {
152
			$this->assertInstanceOf( '\\Aimeos\\MW\\Cache\\Iface', $this->object->getCache() );
153
		} catch( \Aimeos\MAdmin\Cache\Exception $e ) {
154
			$this->markTestSkipped( 'Please install Predis client first' );
155
		}
156
	}
157
}
158