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' ) ); |
|
|
|
|
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' ) ); |
|
|
|
|
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' ) ); |
|
|
|
|
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
|
|
|
|
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.