['bar', 'baz'], 'Abc' => ['123'], 'Def' => ['a, b'], ]; self::assertSame($expected, Utils::headersFromLines($lines)); self::assertSame($expected, GuzzleHttp\headers_from_lines($lines)); } public function testParsesHeadersFromLinesWithMultipleLines() { $lines = ['Foo: bar', 'Foo: baz', 'Foo: 123']; $expected = ['Foo' => ['bar', 'baz', '123']]; self::assertSame($expected, Utils::headersFromLines($lines)); self::assertSame($expected, GuzzleHttp\headers_from_lines($lines)); } public function testChooseHandler() { self::assertIsCallable(Utils::chooseHandler()); self::assertIsCallable(GuzzleHttp\choose_handler()); } public function testDefaultUserAgent() { self::assertIsString(Utils::defaultUserAgent()); self::assertIsString(GuzzleHttp\default_user_agent()); } public function testReturnsDebugResource() { self::assertIsResource(Utils::debugResource()); self::assertIsResource(GuzzleHttp\debug_resource()); } public function testProvidesDefaultCaBundler() { self::assertFileExists(Utils::defaultCaBundle()); self::assertFileExists(GuzzleHttp\default_ca_bundle()); } public function testNormalizeHeaderKeys() { $input = ['HelLo' => 'foo', 'WORld' => 'bar']; $expected = ['hello' => 'HelLo', 'world' => 'WORld']; self::assertSame($expected, Utils::normalizeHeaderKeys($input)); self::assertSame($expected, GuzzleHttp\normalize_header_keys($input)); } public function noProxyProvider() { return [ ['mit.edu', ['.mit.edu'], false], ['foo.mit.edu', ['.mit.edu'], true], ['foo.mit.edu:123', ['.mit.edu'], true], ['mit.edu', ['mit.edu'], true], ['mit.edu', ['baz', 'mit.edu'], true], ['mit.edu', ['', '', 'mit.edu'], true], ['mit.edu', ['baz', '*'], true], ]; } /** * @dataProvider noproxyProvider */ public function testChecksNoProxyList($host, $list, $result) { self::assertSame($result, Utils::isHostInNoProxy($host, $list)); self::assertSame($result, \GuzzleHttp\is_host_in_noproxy($host, $list)); } public function testEnsuresNoProxyCheckHostIsSet() { $this->expectException(\InvalidArgumentException::class); Utils::isHostInNoProxy('', []); } public function testEnsuresNoProxyCheckHostIsSetLegacy() { $this->expectException(\InvalidArgumentException::class); \GuzzleHttp\is_host_in_noproxy('', []); } public function testEncodesJson() { self::assertSame('true', Utils::jsonEncode(true)); self::assertSame('true', \GuzzleHttp\json_encode(true)); } public function testEncodesJsonAndThrowsOnError() { $this->expectException(\InvalidArgumentException::class); Utils::jsonEncode("\x99"); } public function testEncodesJsonAndThrowsOnErrorLegacy() { $this->expectException(\InvalidArgumentException::class); \GuzzleHttp\json_encode("\x99"); } public function testDecodesJson() { self::assertTrue(Utils::jsonDecode('true')); self::assertTrue(\GuzzleHttp\json_decode('true')); } public function testDecodesJsonAndThrowsOnError() { $this->expectException(\InvalidArgumentException::class); Utils::jsonDecode('{{]]'); } public function testDecodesJsonAndThrowsOnErrorLegacy() { $this->expectException(\InvalidArgumentException::class); \GuzzleHttp\json_decode('{{]]'); } } final class StrClass { public function __toString() { return 'foo'; } }