MediaWikiCacheTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 66
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 2
A testSetValue() 0 19 1
A testGetValueWithReturnFoobarAsValue() 0 18 1
A testGetValueWithReturnFalseAsValue() 0 17 1
1
<?php
2
3
namespace SimpleCache\Tests\Phpunit\Cache;
4
5
use SimpleCache\Cache\MediaWikiCache;
6
7
/**
8
 * @covers SimpleCache\Cache\MediaWikiCache
9
 *
10
 * @licence GNU GPL v2+
11
 * @author Jeroen De Dauw < [email protected] >
12
 */
13
class MediaWikiCacheTest extends \PHPUnit_Framework_TestCase {
14
15
	public function setUp() {
16
		if ( !class_exists( 'BagOStuff' ) ) {
17
			$this->markTestSkipped( 'MediaWiki not available' );
18
		}
19
	}
20
21
	public function testSetValue() {
22
		$value = 'foobar';
23
		$key = 'foo';
24
		$expiryTime = 42;
25
26
		$bagOfStuff = $this->createMock( 'BagOStuff', array( 'set' ) );
0 ignored issues
show
Unused Code introduced by
The call to MediaWikiCacheTest::createMock() has too many arguments starting with array('set').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
27
28
		$bagOfStuff->expects( $this->once() )
29
			->method( 'set' )
30
			->with(
31
				$this->equalTo( $key ),
32
				$this->equalTo( $value ),
33
				$this->equalTo( $expiryTime )
34
			);
35
36
		$cache = new MediaWikiCache( $bagOfStuff, $expiryTime );
37
38
		$cache->set( $key, $value );
39
	}
40
41
	public function testGetValueWithReturnFoobarAsValue() {
42
		$key = 'foo';
43
		$value = 'foobar';
44
45
		$bagOfStuff = $this->createMock( 'BagOStuff', array( 'get' ) );
0 ignored issues
show
Unused Code introduced by
The call to MediaWikiCacheTest::createMock() has too many arguments starting with array('get').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
46
47
		$bagOfStuff->expects( $this->exactly( 2 ) )
48
			->method( 'get' )
49
			->with(
50
				$this->equalTo( $key )
51
			)
52
			->will( $this->returnValue( $value ) );
53
54
		$cache = new MediaWikiCache( $bagOfStuff );
55
56
		$this->assertEquals( $value, $cache->get( $key ) );
57
		$this->assertTrue( $cache->has( $key ) );
58
	}
59
60
	public function testGetValueWithReturnFalseAsValue() {
61
		$key = 'foo';
62
63
		$bagOfStuff = $this->createMock( 'BagOStuff', array( 'get' ) );
0 ignored issues
show
Unused Code introduced by
The call to MediaWikiCacheTest::createMock() has too many arguments starting with array('get').

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
64
65
		$bagOfStuff->expects( $this->exactly( 2 ) )
66
			->method( 'get' )
67
			->with(
68
				$this->equalTo( $key )
69
			)
70
			->will( $this->returnValue( false ) );
71
72
		$cache = new MediaWikiCache( $bagOfStuff );
73
74
		$this->assertNull( $cache->get( $key ) );
75
		$this->assertFalse( $cache->has( $key ) );
76
	}
77
78
}
79