Subversion Repositories cheapmusic

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
103 - 1
<?php
2
/*
3
 * Copyright 2015 Google Inc.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
 
18
error_reporting(E_ALL | E_STRICT);
19
require dirname(__DIR__) . '/vendor/autoload.php';
20
date_default_timezone_set('UTC');
21
 
22
// autoload base test
23
require_once __DIR__ . '/BaseTest.php';
24
 
25
function buildResponse($code, array $headers = [], $body = null)
26
{
27
    if (class_exists('GuzzleHttp\HandlerStack')) {
28
        return new \GuzzleHttp\Psr7\Response($code, $headers, $body);
29
    }
30
 
31
    return new \GuzzleHttp\Message\Response(
32
        $code,
33
        $headers,
34
        \GuzzleHttp\Stream\Stream::factory((string)$body)
35
    );
36
}
37
 
38
function getHandler(array $mockResponses = [])
39
{
40
    if (class_exists('GuzzleHttp\HandlerStack')) {
41
        $mock = new \GuzzleHttp\Handler\MockHandler($mockResponses);
42
 
43
        $handler = \GuzzleHttp\HandlerStack::create($mock);
44
        $client = new \GuzzleHttp\Client(['handler' => $handler]);
45
 
46
        return new \Google\Auth\HttpHandler\Guzzle6HttpHandler($client);
47
    }
48
 
49
    $client = new \GuzzleHttp\Client();
50
    $client->getEmitter()->attach(
51
        new \GuzzleHttp\Subscriber\Mock($mockResponses)
52
    );
53
 
54
    return new \Google\Auth\HttpHandler\Guzzle5HttpHandler($client);
55
}