Skip to content

Commit 732c85f

Browse files
wip: test option 1 - update existing tests with data provider
1 parent bedda64 commit 732c85f

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

tests/Cache/CacheApcStoreTest.php

+28-21
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,22 @@ public function testGetReturnsNullWhenNotFound()
2828
$this->assertNull($store->get('bar'));
2929
}
3030

31-
public function testAPCValueIsReturned()
31+
#[DataProvider('resolveKeyNameDataProvider')]
32+
public function testAPCValueIsReturned(mixed $key, string $expected)
3233
{
3334
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['get'])->getMock();
34-
$apc->expects($this->once())->method('get')->willReturn('bar');
35+
$apc->expects($this->once())->method('get')->with($this->equalTo($expected))->willReturn('bar');
3536
$store = new ApcStore($apc);
36-
$this->assertSame('bar', $store->get('foo'));
37+
$this->assertSame('bar', $store->get($key));
3738
}
3839

39-
public function testAPCFalseValueIsReturned()
40+
#[DataProvider('resolveKeyNameDataProvider')]
41+
public function testAPCFalseValueIsReturned(mixed $key, string $expected)
4042
{
4143
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['get'])->getMock();
42-
$apc->expects($this->once())->method('get')->willReturn(false);
44+
$apc->expects($this->once())->method('get')->with($this->equalTo($expected))->willReturn(false);
4345
$store = new ApcStore($apc);
44-
$this->assertFalse($store->get('foo'));
46+
$this->assertFalse($store->get($key));
4547
}
4648

4749
public function testGetMultipleReturnsNullWhenNotFoundAndValueWhenFound()
@@ -60,14 +62,15 @@ public function testGetMultipleReturnsNullWhenNotFoundAndValueWhenFound()
6062
], $store->many(['foo', 'bar', 'baz']));
6163
}
6264

63-
public function testSetMethodProperlyCallsAPC()
65+
#[DataProvider('resolveKeyNameDataProvider')]
66+
public function testSetMethodProperlyCallsAPC(mixed $key, string $expected)
6467
{
6568
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['put'])->getMock();
6669
$apc->expects($this->once())
67-
->method('put')->with($this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo(60))
70+
->method('put')->with($this->equalTo($expected), $this->equalTo('bar'), $this->equalTo(60))
6871
->willReturn(true);
6972
$store = new ApcStore($apc);
70-
$result = $store->put('foo', 'bar', 60);
73+
$result = $store->put($key, 'bar', 60);
7174
$this->assertTrue($result);
7275
}
7376

@@ -99,39 +102,43 @@ public function testSetMultipleMethodProperlyCallsAPC()
99102
$this->assertTrue($result);
100103
}
101104

102-
public function testIncrementMethodProperlyCallsAPC()
105+
#[DataProvider('resolveKeyNameDataProvider')]
106+
public function testIncrementMethodProperlyCallsAPC(mixed $key, string $expected)
103107
{
104108
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['increment'])->getMock();
105-
$apc->expects($this->once())->method('increment')->with($this->equalTo('foo'), $this->equalTo(5));
109+
$apc->expects($this->once())->method('increment')->with($this->equalTo($expected), $this->equalTo(5));
106110
$store = new ApcStore($apc);
107-
$store->increment('foo', 5);
111+
$store->increment($key, 5);
108112
}
109113

110-
public function testDecrementMethodProperlyCallsAPC()
114+
#[DataProvider('resolveKeyNameDataProvider')]
115+
public function testDecrementMethodProperlyCallsAPC(mixed $key, string $expected)
111116
{
112117
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['decrement'])->getMock();
113-
$apc->expects($this->once())->method('decrement')->with($this->equalTo('foo'), $this->equalTo(5));
118+
$apc->expects($this->once())->method('decrement')->with($this->equalTo($expected), $this->equalTo(5));
114119
$store = new ApcStore($apc);
115-
$store->decrement('foo', 5);
120+
$store->decrement($key, 5);
116121
}
117122

118-
public function testStoreItemForeverProperlyCallsAPC()
123+
#[DataProvider('resolveKeyNameDataProvider')]
124+
public function testStoreItemForeverProperlyCallsAPC(mixed $key, string $expected)
119125
{
120126
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['put'])->getMock();
121127
$apc->expects($this->once())
122-
->method('put')->with($this->equalTo('foo'), $this->equalTo('bar'), $this->equalTo(0))
128+
->method('put')->with($this->equalTo($expected), $this->equalTo('bar'), $this->equalTo(0))
123129
->willReturn(true);
124130
$store = new ApcStore($apc);
125-
$result = $store->forever('foo', 'bar');
131+
$result = $store->forever($key, 'bar');
126132
$this->assertTrue($result);
127133
}
128134

129-
public function testForgetMethodProperlyCallsAPC()
135+
#[DataProvider('resolveKeyNameDataProvider')]
136+
public function testForgetMethodProperlyCallsAPC(mixed $key, string $expected)
130137
{
131138
$apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['delete'])->getMock();
132-
$apc->expects($this->once())->method('delete')->with($this->equalTo('foo'))->willReturn(true);
139+
$apc->expects($this->once())->method('delete')->with($this->equalTo($expected))->willReturn(true);
133140
$store = new ApcStore($apc);
134-
$result = $store->forget('foo');
141+
$result = $store->forget($key);
135142
$this->assertTrue($result);
136143
}
137144

0 commit comments

Comments
 (0)