Passed
Push — master ( eaba1f...4ca8dc )
by Jean Paul
01:59
created

ApiReaderTest::testGetResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
1
<?php declare( strict_types = 1 );
2
3
namespace Coco\SourceWatcher\Tests\Core\Api;
4
5
use Coco\SourceWatcher\Core\Api\ApiReader;
6
use Coco\SourceWatcher\Core\SourceWatcherException;
7
use Coco\SourceWatcher\Utils\i18n;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * Class ApiReaderTest
12
 * @package Coco\SourceWatcher\Tests\Core\Api
13
 */
14
class ApiReaderTest extends TestCase
15
{
16
    /**
17
     *
18
     */
19
    public function testSetGetResourceURL () : void
20
    {
21
        $apiReader = new ApiReader();
22
23
        $givenResourceURL = "https://api.github.com/emojis";
24
        $expectedResourceURL = "https://api.github.com/emojis";
25
26
        $apiReader->setResourceURL( $givenResourceURL );
27
28
        $this->assertEquals( $expectedResourceURL, $apiReader->getResourceURL() );
29
    }
30
31
    /**
32
     *
33
     */
34
    public function testSetGetTimeout () : void
35
    {
36
        $apiReader = new ApiReader();
37
38
        $givenTimeout = 10;
39
        $expectedTimeout = 10;
40
41
        $apiReader->setTimeout( $givenTimeout );
42
43
        $this->assertEquals( $expectedTimeout, $apiReader->getTimeout() );
44
    }
45
46
    /**
47
     *
48
     */
49
    public function testSetGetHeaders () : void
50
    {
51
        $apiReader = new ApiReader();
52
53
        $givenHeaders = [ "Cache-Control: no-cache", "Content-Type: application/x-www-form-urlencoded; charset=utf-8", "Host: www.example.com" ];
54
        $expectedHeaders = [ "Cache-Control: no-cache", "Content-Type: application/x-www-form-urlencoded; charset=utf-8", "Host: www.example.com" ];
55
56
        $apiReader->setHeaders( $givenHeaders );
57
58
        $this->assertEquals( $expectedHeaders, $apiReader->getHeaders() );
59
    }
60
61
    /**
62
     * @throws SourceWatcherException
63
     */
64
    public function testGetExceptionFromNoResourceURL () : void
65
    {
66
        $apiReader = new ApiReader();
67
68
        $this->expectException( SourceWatcherException::class );
69
        $this->expectExceptionMessage( i18n::getInstance()->getText( "en_US", ApiReader::class, "No_Resource_URL_Found" ) );
70
71
        $apiReader->read();
72
    }
73
74
    /**
75
     * @throws SourceWatcherException
76
     */
77
    public function testGetResult () : void
78
    {
79
        $apiReader = new ApiReader();
80
        $apiReader->setResourceURL( "https://api.github.com/emojis" );
81
        $apiReader->setHeaders( [ "User-Agent: request" ] );
82
        $result = $apiReader->read();
83
84
        $this->assertNotNull( $result );
85
    }
86
}
87