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

HasAuthorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_it_can_create_a_new_author_instance_from_user_array() 0 12 1
A matter() 0 3 1
A test_it_can_create_a_new_author_instance_from_username_string() 0 11 1
1
<?php
2
3
namespace Hyde\Framework\Testing\Unit;
4
5
use Hyde\Framework\Concerns\HasAuthor;
6
use Hyde\Framework\Models\Author;
7
use Hyde\Framework\Models\FrontMatter;
8
use Hyde\Testing\TestCase;
9
10
/**
11
 * Class HasAuthorTest.
12
 *
13
 * @covers \Hyde\Framework\Concerns\HasAuthor
14
 */
15
class HasAuthorTest extends TestCase
16
{
17
    use HasAuthor;
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_author_instance_from_username_string()
27
    {
28
        $this->matter = FrontMatter::fromArray([
29
            'author' => 'John Doe',
30
        ]);
31
32
        $this->constructAuthor();
33
        $this->assertInstanceOf(Author::class, $this->author);
34
        $this->assertEquals('John Doe', $this->author->username);
35
        $this->assertNull($this->author->name);
36
        $this->assertNull($this->author->website);
37
    }
38
39
    public function test_it_can_create_a_new_author_instance_from_user_array()
40
    {
41
        $this->matter = FrontMatter::fromArray(['author' => [
42
            'username' => 'john_doe',
43
            'name' => 'John Doe',
44
            'website' => 'https://example.com',
45
        ]]);
46
        $this->constructAuthor();
47
        $this->assertInstanceOf(Author::class, $this->author);
48
        $this->assertEquals('john_doe', $this->author->username);
49
        $this->assertEquals('John Doe', $this->author->name);
50
        $this->assertEquals('https://example.com', $this->author->website);
51
    }
52
}
53