Passed
Branch master (ef5451)
by Caen
03:29
created

HasFeaturedImageTest::matter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Hyde\Framework\Testing\Unit;
4
5
use Hyde\Framework\Concerns\HasFeaturedImage;
6
use Hyde\Framework\Models\FrontMatter;
7
use Hyde\Framework\Models\Image;
8
use Hyde\Testing\TestCase;
9
10
/**
11
 * Class HasFeaturedImageTest.
12
 *
13
 * @covers \Hyde\Framework\Concerns\HasFeaturedImage
14
 */
15
class HasFeaturedImageTest extends TestCase
16
{
17
    use HasFeaturedImage;
18
19
    protected FrontMatter $matter;
20
21
    protected function matter(...$args)
22
    {
23
        return $this->matter->get(...$args);
0 ignored issues
show
Bug introduced by
$args is expanded, but the parameter $key of Hyde\Framework\Models\FrontMatter::get() does not expect variable arguments. ( Ignorable by Annotation )

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

23
        return $this->matter->get(/** @scrutinizer ignore-type */ ...$args);
Loading history...
24
    }
25
26
    public function test_it_can_create_a_new_image_instance_from_a_string()
27
    {
28
        $this->matter = FrontMatter::fromArray([
29
            'image' => 'https://example.com/image.jpg',
30
        ]);
31
32
        $this->constructFeaturedImage();
33
        $this->assertInstanceOf(Image::class, $this->image);
34
        $this->assertEquals('https://example.com/image.jpg', $this->image->uri);
35
    }
36
37
    public function test_it_can_create_a_new_image_instance_from_an_array()
38
    {
39
        $this->matter = FrontMatter::fromArray([
40
            'image' => [
41
                'uri' => 'https://example.com/image.jpg',
42
            ],
43
        ]);
44
45
        $this->constructFeaturedImage();
46
        $this->assertInstanceOf(Image::class, $this->image);
47
        $this->assertEquals('https://example.com/image.jpg', $this->image->uri);
48
    }
49
50
    public function test_construct_base_image_sets_the_source_to_the_image_uri_when_supplied_path_is_an_uri()
51
    {
52
        $image = $this->constructBaseImage('https://example.com/image.jpg');
53
        $this->assertEquals('https://example.com/image.jpg', $image->getSource());
54
    }
55
56
    public function test_construct_base_image_sets_the_source_to_the_image_path_when_supplied_path_is_a_local_path()
57
    {
58
        $image = $this->constructBaseImage('/path/to/image.jpg');
59
        $this->assertEquals('/path/to/image.jpg', $image->getSource());
60
    }
61
62
    public function test_construct_base_image_returns_an_image_instance_created_from_a_string()
63
    {
64
        $this->assertInstanceOf(Image::class, $this->constructBaseImage(''));
65
    }
66
67
    public function test_construct_full_image_returns_an_image_instance_created_from_an_array()
68
    {
69
        $this->assertInstanceOf(Image::class, $this->constructFullImage([]));
70
    }
71
}
72