1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-24 01:53:58 +01:00
guzzle/tests/functionsTest.php

82 lines
2.0 KiB
PHP
Raw Normal View History

2015-03-20 00:21:42 -07:00
<?php
namespace GuzzleHttp\Test;
2015-03-21 16:14:23 -07:00
use GuzzleHttp;
2015-03-20 00:21:42 -07:00
class FunctionsTest extends \PHPUnit_Framework_TestCase
{
2015-03-21 16:14:23 -07:00
public function testExpandsTemplate()
{
$this->assertEquals(
'foo/123',
GuzzleHttp\uri_template('foo/{bar}', ['bar' => '123'])
);
}
public function noBodyProvider()
2015-03-21 15:53:38 -07:00
{
2015-03-21 16:14:23 -07:00
return [['get'], ['head'], ['delete']];
}
2015-03-20 00:21:42 -07:00
2015-03-21 16:14:23 -07:00
public function testProvidesDefaultUserAgent()
{
$ua = GuzzleHttp\default_user_agent();
$this->assertEquals(1, preg_match('#^GuzzleHttp/.+ curl/.+ PHP/.+$#', $ua));
2015-03-21 15:53:38 -07:00
}
2015-03-21 16:14:23 -07:00
public function typeProvider()
{
return [
['foo', 'string(3) "foo"'],
[true, 'bool(true)'],
[false, 'bool(false)'],
[10, 'int(10)'],
[1.0, 'float(1)'],
[new StrClass(), 'object(GuzzleHttp\Test\StrClass)'],
[['foo'], 'array(1)']
];
}
/**
* @dataProvider typeProvider
*/
public function testDescribesType($input, $output)
2015-03-21 15:53:38 -07:00
{
2015-03-21 16:14:23 -07:00
$this->assertEquals($output, GuzzleHttp\describe_type($input));
}
2015-03-21 15:53:38 -07:00
2015-03-21 16:14:23 -07:00
public function testParsesHeadersFromLines()
{
$lines = ['Foo: bar', 'Foo: baz', 'Abc: 123', 'Def: a, b'];
$this->assertEquals([
'Foo' => ['bar', 'baz'],
'Abc' => ['123'],
'Def' => ['a, b'],
], GuzzleHttp\headers_from_lines($lines));
}
public function testParsesHeadersFromLinesWithMultipleLines()
{
$lines = ['Foo: bar', 'Foo: baz', 'Foo: 123'];
$this->assertEquals([
'Foo' => ['bar', 'baz', '123'],
], GuzzleHttp\headers_from_lines($lines));
}
public function testReturnsDebugResource()
{
$this->assertTrue(is_resource(GuzzleHttp\get_debug_resource()));
}
public function testProvidesDefaultCaBundler()
{
$this->assertFileExists(GuzzleHttp\default_ca_bundle());
}
}
final class StrClass
{
public function __toString()
{
return 'foo';
2015-03-21 15:53:38 -07:00
}
2015-03-20 00:21:42 -07:00
}