/
githubmirror
/
framework
Обзор
Документация
Войти
/
githubmirror
/
framework
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
13.x
tests/Cache/CacheApcStoreTest.php
145 строк
5 KB
Jason McCreary
[13.x] Mockery cleanup (#61117)
10 авг 2026, 20:23
Не верифицирован
10 авг 2026, 20:23
2ee40ee
Код
Авторство
О чём код?
<?php namespace Illuminate\Tests\Cache; use Illuminate\Cache\ApcStore; use Illuminate\Cache\ApcWrapper; use Mockery; use PHPUnit\Framework\TestCase; class CacheApcStoreTest extends TestCase { public function testGetReturnsNullWhenNotFound() { $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['get'])->getMock(); $apc->expects($this->once())->method('get')->with('foobar')->willReturn(null); $store = new ApcStore($apc, 'foo'); $this->assertNull($store->get('bar')); } public function testAPCValueIsReturned() { $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['get'])->getMock(); $apc->expects($this->once())->method('get')->willReturn('bar'); $store = new ApcStore($apc); $this->assertSame('bar', $store->get('foo')); } public function testAPCFalseValueIsReturned() { $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['get'])->getMock(); $apc->expects($this->once())->method('get')->willReturn(false); $store = new ApcStore($apc); $this->assertFalse($store->get('foo')); } public function testGetMultipleReturnsNullWhenNotFoundAndValueWhenFound() { $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['get'])->getMock(); $apc->expects($this->exactly(3))->method('get')->willReturnMap([ ['foo', 'qux'], ['bar', null], ['baz', 'norf'], ]); $store = new ApcStore($apc); $this->assertEquals([ 'foo' => 'qux', 'bar' => null, 'baz' => 'norf', ], $store->many(['foo', 'bar', 'baz'])); } public function testSetMethodProperlyCallsAPC() { $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['put'])->getMock(); $apc->expects($this->once()) ->method('put')->with('foo', 'bar', 60) ->willReturn(true); $store = new ApcStore($apc); $result = $store->put('foo', 'bar', 60); $this->assertTrue($result); } public function testSetMultipleMethodProperlyCallsAPC() { $apc = Mockery::mock(ApcWrapper::class); $apc->expects('put') ->with('foo', 'bar', 60) ->andReturn(true); $apc->expects('put') ->with('baz', 'qux', 60) ->andReturn(true); $apc->expects('put') ->with('bar', 'norf', 60) ->andReturn(true); $store = new ApcStore($apc); $result = $store->putMany([ 'foo' => 'bar', 'baz' => 'qux', 'bar' => 'norf', ], 60); $this->assertTrue($result); } public function testIncrementMethodProperlyCallsAPC() { $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['increment'])->getMock(); $apc->expects($this->once())->method('increment')->with('foo', 5); $store = new ApcStore($apc); $store->increment('foo', 5); } public function testDecrementMethodProperlyCallsAPC() { $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['decrement'])->getMock(); $apc->expects($this->once())->method('decrement')->with('foo', 5); $store = new ApcStore($apc); $store->decrement('foo', 5); } public function testStoreItemForeverProperlyCallsAPC() { $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['put'])->getMock(); $apc->expects($this->once()) ->method('put')->with('foo', 'bar', 0) ->willReturn(true); $store = new ApcStore($apc); $result = $store->forever('foo', 'bar'); $this->assertTrue($result); } public function testForgetMethodProperlyCallsAPC() { $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['delete'])->getMock(); $apc->expects($this->once())->method('delete')->with('foo')->willReturn(true); $store = new ApcStore($apc); $result = $store->forget('foo'); $this->assertTrue($result); } public function testTouchMethodProperlyCallsAPC(): void { $key = 'key'; $ttl = 60; $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['get', 'put'])->getMock(); $apc->expects($this->once())->method('get')->with($key)->willReturn('bar'); $apc->expects($this->once())->method('put')->with($key, 'bar', $ttl)->willReturn(true); $this->assertTrue((new ApcStore($apc))->touch($key, $ttl)); } public function testFlushesCached() { $apc = $this->getMockBuilder(ApcWrapper::class)->onlyMethods(['flush'])->getMock(); $apc->expects($this->once())->method('flush')->willReturn(true); $store = new ApcStore($apc); $result = $store->flush(); $this->assertTrue($result); } }