1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/gigya-client |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/gigya-client/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/gigya-client |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\Gigya\Test\Unit\Response; |
15
|
|
|
|
16
|
|
|
use DateTime; |
17
|
|
|
use Graze\Gigya\Gigya; |
18
|
|
|
use Graze\Gigya\Response\Response; |
19
|
|
|
use Graze\Gigya\Test\TestCase; |
20
|
|
|
use Graze\Gigya\Test\TestFixtures; |
21
|
|
|
use Mockery as m; |
22
|
|
|
use Psr\Http\Message\ResponseInterface as GuzzleResponseInterface; |
23
|
|
|
|
24
|
|
|
class ResponseTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
public static function setUpBeforeClass() |
27
|
|
|
{ |
28
|
|
|
date_default_timezone_set('UTC'); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testDateFormat() |
32
|
|
|
{ |
33
|
|
|
$time = DateTime::createFromFormat(Gigya::DATE_TIME_FORMAT, '2015-03-22T11:42:25.943Z'); |
34
|
|
|
|
35
|
|
|
static::assertInstanceOf('DateTimeInterface', $time); |
36
|
|
|
static::assertEquals('2015', $time->format('Y')); |
37
|
|
|
static::assertEquals('03', $time->format('m')); |
38
|
|
|
static::assertEquals('22', $time->format('d')); |
39
|
|
|
static::assertEquals('11', $time->format('H')); |
40
|
|
|
static::assertEquals('42', $time->format('i')); |
41
|
|
|
static::assertEquals('25', $time->format('s')); |
42
|
|
|
static::assertEquals('943000', $time->format('u')); |
43
|
|
|
static::assertEquals('Z', $time->getTimezone()->getName()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testOtherTimeZoneFormat() |
47
|
|
|
{ |
48
|
|
|
$time = DateTime::createFromFormat(Gigya::DATE_TIME_FORMAT, '2015-03-22T11:42:25.943+02:00'); |
49
|
|
|
|
50
|
|
|
static::assertInstanceOf('DateTimeInterface', $time); |
51
|
|
|
static::assertEquals('2015', $time->format('Y')); |
52
|
|
|
static::assertEquals('03', $time->format('m')); |
53
|
|
|
static::assertEquals('22', $time->format('d')); |
54
|
|
|
static::assertEquals('11', $time->format('H')); |
55
|
|
|
static::assertEquals('42', $time->format('i')); |
56
|
|
|
static::assertEquals('25', $time->format('s')); |
57
|
|
|
static::assertEquals('943000', $time->format('u')); |
58
|
|
|
static::assertEquals('+02:00', $time->getTimezone()->getName()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testToString() |
62
|
|
|
{ |
63
|
|
|
$guzzleResponse = m::mock(GuzzleResponseInterface::class); |
64
|
|
|
$guzzleResponse->shouldReceive('getBody')->andReturn($this->toStream(TestFixtures::getFixture('accounts.getAccountInfo'))); |
|
|
|
|
65
|
|
|
$response = new Response($guzzleResponse); |
|
|
|
|
66
|
|
|
|
67
|
|
|
static::assertRegExp('/Response: \d+: \w+ - \d+: .+\n.+/s', $response->__toString()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testToStringForFailure() |
71
|
|
|
{ |
72
|
|
|
$guzzleResponse = m::mock(GuzzleResponseInterface::class); |
73
|
|
|
$guzzleResponse->shouldReceive('getBody')->andReturn($this->toStream(TestFixtures::getFixture('failure_403'))); |
|
|
|
|
74
|
|
|
$response = new Response($guzzleResponse); |
|
|
|
|
75
|
|
|
|
76
|
|
|
static::assertRegExp('/Response: \d+: \w+ - \d+: .+\n.+\n.+\n.+/s', $response->__toString()); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.