Вход Регистрация
Файл: vkolhoze.com/vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/MemoizingInflectorTest.php
Строк: 64
<?php

namespace GuzzleTestsInflection;

use 
GuzzleInflectionMemoizingInflector;
use 
GuzzleInflectionInflector;

/**
 * @covers GuzzleInflectionMemoizingInflector
 */
class MemoizingInflectorTest extends GuzzleTestsGuzzleTestCase
{
    public function 
testUsesCache()
    {
        
$mock $this->getMock('GuzzleInflectionInflector', array('snake''camel'));
        
$mock->expects($this->once())->method('snake')->will($this->returnValue('foo_bar'));
        
$mock->expects($this->once())->method('camel')->will($this->returnValue('FooBar'));

        
$inflector = new MemoizingInflector($mock);
        
$this->assertEquals('foo_bar'$inflector->snake('FooBar'));
        
$this->assertEquals('foo_bar'$inflector->snake('FooBar'));
        
$this->assertEquals('FooBar'$inflector->camel('foo_bar'));
        
$this->assertEquals('FooBar'$inflector->camel('foo_bar'));
    }

    public function 
testProtectsAgainstCacheOverflow()
    {
        
$inflector = new MemoizingInflector(new Inflector(), 10);
        for (
$i 1$i 11$i++) {
            
$inflector->camel('foo_' $i);
            
$inflector->snake('Foo' $i);
        }

        
$cache $this->readAttribute($inflector'cache');
        
$this->assertEquals(10count($cache['snake']));
        
$this->assertEquals(10count($cache['camel']));

        
$inflector->camel('baz!');
        
$inflector->snake('baz!');

        
// Now ensure that 20% of the cache was removed (2), then the item was added
        
$cache $this->readAttribute($inflector'cache');
        
$this->assertEquals(9count($cache['snake']));
        
$this->assertEquals(9count($cache['camel']));
    }
}
Онлайн: 1
Реклама