summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection')
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/InflectorTest.php37
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/MemoizingInflectorTest.php46
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/PreComputedInflectorTest.php45
3 files changed, 128 insertions, 0 deletions
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/InflectorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/InflectorTest.php
new file mode 100644
index 0000000..990c0af
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/InflectorTest.php
@@ -0,0 +1,37 @@
+<?php
+
+namespace Guzzle\Tests\Inflection;
+
+use Guzzle\Inflection\Inflector;
+
+/**
+ * @covers Guzzle\Inflection\Inflector
+ */
+class InflectorTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testReturnsDefaultInstance()
+ {
+ $this->assertSame(Inflector::getDefault(), Inflector::getDefault());
+ }
+
+ public function testSnake()
+ {
+ $this->assertEquals('camel_case', Inflector::getDefault()->snake('camelCase'));
+ $this->assertEquals('camel_case', Inflector::getDefault()->snake('CamelCase'));
+ $this->assertEquals('camel_case_words', Inflector::getDefault()->snake('CamelCaseWords'));
+ $this->assertEquals('camel_case_words', Inflector::getDefault()->snake('CamelCase_words'));
+ $this->assertEquals('test', Inflector::getDefault()->snake('test'));
+ $this->assertEquals('test', Inflector::getDefault()->snake('test'));
+ $this->assertEquals('expect100_continue', Inflector::getDefault()->snake('Expect100Continue'));
+ }
+
+ public function testCamel()
+ {
+ $this->assertEquals('CamelCase', Inflector::getDefault()->camel('camel_case'));
+ $this->assertEquals('CamelCaseWords', Inflector::getDefault()->camel('camel_case_words'));
+ $this->assertEquals('Test', Inflector::getDefault()->camel('test'));
+ $this->assertEquals('Expect100Continue', ucfirst(Inflector::getDefault()->camel('expect100_continue')));
+ // Get from cache
+ $this->assertEquals('Test', Inflector::getDefault()->camel('test', false));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/MemoizingInflectorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/MemoizingInflectorTest.php
new file mode 100644
index 0000000..f00b7fa
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/MemoizingInflectorTest.php
@@ -0,0 +1,46 @@
+<?php
+
+namespace Guzzle\Tests\Inflection;
+
+use Guzzle\Inflection\MemoizingInflector;
+use Guzzle\Inflection\Inflector;
+
+/**
+ * @covers Guzzle\Inflection\MemoizingInflector
+ */
+class MemoizingInflectorTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testUsesCache()
+ {
+ $mock = $this->getMock('Guzzle\Inflection\Inflector', 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(10, count($cache['snake']));
+ $this->assertEquals(10, count($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(9, count($cache['snake']));
+ $this->assertEquals(9, count($cache['camel']));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/PreComputedInflectorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/PreComputedInflectorTest.php
new file mode 100644
index 0000000..ff2654c
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Inflection/PreComputedInflectorTest.php
@@ -0,0 +1,45 @@
+<?php
+
+namespace Guzzle\Tests\Inflection;
+
+use Guzzle\Inflection\PreComputedInflector;
+
+/**
+ * @covers Guzzle\Inflection\PreComputedInflector
+ */
+class PreComputedInflectorTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testUsesPreComputedHash()
+ {
+ $mock = $this->getMock('Guzzle\Inflection\Inflector', array('snake', 'camel'));
+ $mock->expects($this->once())->method('snake')->with('Test')->will($this->returnValue('test'));
+ $mock->expects($this->once())->method('camel')->with('Test')->will($this->returnValue('Test'));
+ $inflector = new PreComputedInflector($mock, array('FooBar' => 'foo_bar'), array('foo_bar' => 'FooBar'));
+ $this->assertEquals('FooBar', $inflector->camel('foo_bar'));
+ $this->assertEquals('foo_bar', $inflector->snake('FooBar'));
+ $this->assertEquals('Test', $inflector->camel('Test'));
+ $this->assertEquals('test', $inflector->snake('Test'));
+ }
+
+ public function testMirrorsPrecomputedValues()
+ {
+ $mock = $this->getMock('Guzzle\Inflection\Inflector', array('snake', 'camel'));
+ $mock->expects($this->never())->method('snake');
+ $mock->expects($this->never())->method('camel');
+ $inflector = new PreComputedInflector($mock, array('Zeep' => 'zeep'), array(), true);
+ $this->assertEquals('Zeep', $inflector->camel('zeep'));
+ $this->assertEquals('zeep', $inflector->snake('Zeep'));
+ }
+
+ public function testMirrorsPrecomputedValuesByMerging()
+ {
+ $mock = $this->getMock('Guzzle\Inflection\Inflector', array('snake', 'camel'));
+ $mock->expects($this->never())->method('snake');
+ $mock->expects($this->never())->method('camel');
+ $inflector = new PreComputedInflector($mock, array('Zeep' => 'zeep'), array('foo' => 'Foo'), true);
+ $this->assertEquals('Zeep', $inflector->camel('zeep'));
+ $this->assertEquals('zeep', $inflector->snake('Zeep'));
+ $this->assertEquals('Foo', $inflector->camel('foo'));
+ $this->assertEquals('foo', $inflector->snake('Foo'));
+ }
+}