Test Setup Failed
Pull Request — master (#93)
by
unknown
10:09
created

OpenGraphTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 13
Bugs 6 Features 0
Metric Value
eloc 56
c 13
b 6
f 0
dl 0
loc 93
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testFetchMustacheMetasData() 0 12 1
A testGetHeadersReturns403() 0 11 1
A testFetchReturnsEmptyArrayForWebsiteWithNoMetadata() 0 9 1
A testFetchNonAsciiImageUrlData() 0 12 1
A testFetchReturnsEmptyArrayForWebsiteWithNoMetadataAndReturnedNotFound() 0 9 1
A testFetchAllMetadata() 0 14 1
A testFetch() 0 12 1
1
<?php
2
3
namespace shweshi\OpenGraph\Test;
4
5
use PHPUnit\Framework\Attributes\Test;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\Attributes\Test was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use PHPUnit\Framework\TestCase;
7
use shweshi\OpenGraph\OpenGraph;
0 ignored issues
show
Bug introduced by
The type shweshi\OpenGraph\OpenGraph was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class OpenGraphTest extends TestCase
10
{
11
    #[Test]
12
    public function testFetch()
13
    {
14
        $opengraph = new OpenGraph();
15
        $data = $opengraph->fetch(
16
            'https://www.ogp.me/'
17
        );
18
        $this->assertArrayHasKey('title', $data);
19
        $this->assertArrayHasKey('description', $data);
20
        $this->assertArrayHasKey('type', $data);
21
        $this->assertArrayHasKey('url', $data);
22
        $this->assertArrayHasKey('image', $data);
23
    }
24
25
    #[Test]
26
    public function testFetchAllMetadata()
27
    {
28
        $opengraph = new OpenGraph();
29
        $data = $opengraph->fetch(
30
            'https://www.ogp.me/',
31
            true
32
        );
33
        $this->assertArrayHasKey('title', $data);
34
        $this->assertArrayHasKey('description', $data);
35
        $this->assertArrayHasKey('type', $data);
36
        $this->assertArrayHasKey('url', $data);
37
        $this->assertArrayHasKey('image', $data);
38
        $this->assertArrayHasKey('fb:app_id', $data);
39
    }
40
41
    #[Test]
42
    public function testFetchReturnsEmptyArrayForWebsiteWithNoMetadata()
43
    {
44
        $opengraph = new OpenGraph();
45
        $data = $opengraph->fetch(
46
            'https://www.example.com/'
47
        );
48
49
        $this->assertEmpty($data);
50
    }
51
52
    #[Test]
53
    public function testFetchReturnsEmptyArrayForWebsiteWithNoMetadataAndReturnedNotFound()
54
    {
55
        $opengraph = new OpenGraph();
56
        $data = $opengraph->fetch(
57
            'https://www.example.com/not-found'
58
        );
59
60
        $this->assertEmpty($data);
61
    }
62
63
    #[Test]
64
    public function testFetchMustacheMetasData()
65
    {
66
        $opengraph = new OpenGraph();
67
        $data = $opengraph->fetch(
68
            'https://raw.githubusercontent.com/jurgenbosch/OpenGraph/master/tests/__mocks__/angular-headers.html',
69
            true
70
        );
71
        $this->assertArrayHasKey('title', $data);
72
        $this->assertArrayHasKey('description', $data);
73
        $this->assertArrayHasKey('image', $data);
74
        $this->assertEmpty($data['image']);
75
    }
76
77
    #[Test]
78
    public function testFetchNonAsciiImageUrlData()
79
    {
80
        $opengraph = new OpenGraph();
81
        $data = $opengraph->fetch(
82
            'https://unitedwithisrael.org/iranians-fall-in-love-with-israel-as-netanyahu-reaches-out-in-persian/',
83
            true
84
        );
85
        $this->assertArrayHasKey('title', $data);
86
        $this->assertArrayHasKey('description', $data);
87
        $this->assertArrayHasKey('image', $data);
88
        $this->assertNotEmpty($data['image']);
89
    }
90
91
    #[Test]
92
    public function testGetHeadersReturns403()
93
    {
94
        $urlToFetch = 'https://www.icreatemagazine.nl/nieuws/airtag-hond-of-kat/';
95
        $graph = new OpenGraph();
96
        $meta = $graph->fetch($urlToFetch, true);
97
98
        self::assertEquals('', $meta['image']);
99
100
        $meta = $graph->userAgent('Mozilla/5.0')->fetch($urlToFetch, true);
101
        self::assertnotEmpty($meta['image']);
102
    }
103
}
104