ResponseTest::testDateFormat()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 13
rs 9.9332
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')));
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'getBody'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        $guzzleResponse->/** @scrutinizer ignore-call */ 
65
                         shouldReceive('getBody')->andReturn($this->toStream(TestFixtures::getFixture('accounts.getAccountInfo')));

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.

Loading history...
65
        $response = new Response($guzzleResponse);
0 ignored issues
show
Bug introduced by
$guzzleResponse of type Mockery\MockInterface is incompatible with the type Psr\Http\Message\ResponseInterface expected by parameter $response of Graze\Gigya\Response\Response::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        $response = new Response(/** @scrutinizer ignore-type */ $guzzleResponse);
Loading history...
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')));
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'getBody'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $guzzleResponse->/** @scrutinizer ignore-call */ 
74
                         shouldReceive('getBody')->andReturn($this->toStream(TestFixtures::getFixture('failure_403')));

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.

Loading history...
74
        $response = new Response($guzzleResponse);
0 ignored issues
show
Bug introduced by
$guzzleResponse of type Mockery\MockInterface is incompatible with the type Psr\Http\Message\ResponseInterface expected by parameter $response of Graze\Gigya\Response\Response::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

74
        $response = new Response(/** @scrutinizer ignore-type */ $guzzleResponse);
Loading history...
75
76
        static::assertRegExp('/Response: \d+: \w+ - \d+: .+\n.+\n.+\n.+/s', $response->__toString());
77
    }
78
}
79