Open Monograph Press  3.3.0
MemoizingInflectorTest.php
1 <?php
2 
4 
7 
12 {
13  public function testUsesCache()
14  {
15  $mock = $this->getMock('Guzzle\Inflection\Inflector', array('snake', 'camel'));
16  $mock->expects($this->once())->method('snake')->will($this->returnValue('foo_bar'));
17  $mock->expects($this->once())->method('camel')->will($this->returnValue('FooBar'));
18 
19  $inflector = new MemoizingInflector($mock);
20  $this->assertEquals('foo_bar', $inflector->snake('FooBar'));
21  $this->assertEquals('foo_bar', $inflector->snake('FooBar'));
22  $this->assertEquals('FooBar', $inflector->camel('foo_bar'));
23  $this->assertEquals('FooBar', $inflector->camel('foo_bar'));
24  }
25 
27  {
28  $inflector = new MemoizingInflector(new Inflector(), 10);
29  for ($i = 1; $i < 11; $i++) {
30  $inflector->camel('foo_' . $i);
31  $inflector->snake('Foo' . $i);
32  }
33 
34  $cache = $this->readAttribute($inflector, 'cache');
35  $this->assertEquals(10, count($cache['snake']));
36  $this->assertEquals(10, count($cache['camel']));
37 
38  $inflector->camel('baz!');
39  $inflector->snake('baz!');
40 
41  // Now ensure that 20% of the cache was removed (2), then the item was added
42  $cache = $this->readAttribute($inflector, 'cache');
43  $this->assertEquals(9, count($cache['snake']));
44  $this->assertEquals(9, count($cache['camel']));
45  }
46 }
Guzzle\Tests\GuzzleTestCase
Definition: GuzzleTestCase.php:22
Guzzle\Tests\Inflection\MemoizingInflectorTest
Definition: MemoizingInflectorTest.php:11
Guzzle\Inflection\MemoizingInflector
Definition: MemoizingInflector.php:8
Guzzle\Tests\Inflection\MemoizingInflectorTest\testProtectsAgainstCacheOverflow
testProtectsAgainstCacheOverflow()
Definition: MemoizingInflectorTest.php:26
Guzzle\Inflection\Inflector
Definition: Inflector.php:8
Guzzle\Tests\Inflection\MemoizingInflectorTest\testUsesCache
testUsesCache()
Definition: MemoizingInflectorTest.php:13
Guzzle\Tests\Inflection
Definition: InflectorTest.php:3