Completed
Push — master ( 7ac551...9ceff0 )
by Grégoire
02:43 queued 02:38
created

MetadataTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 45
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetters() 0 19 1
A testImageNullGetDefaultImage() 0 5 1
A testIsImageAvailable() 0 7 1
A isImageAvailableProvider() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Object;
15
16
use PHPUnit\Framework\TestCase;
17
18
class MetadataTest extends TestCase
19
{
20
    public function testGetters(): void
21
    {
22
        $metadata = new Metadata('title', 'description', 'image', 'domain', ['key1' => 'value1']);
23
24
        $this->assertSame('title', $metadata->getTitle());
25
        $this->assertSame('description', $metadata->getDescription());
26
        $this->assertSame('image', $metadata->getImage());
27
        $this->assertSame('domain', $metadata->getDomain());
28
29
        $this->assertSame('value1', $metadata->getOption('key1'));
30
        $this->assertSame('valueDefault', $metadata->getOption('none', 'valueDefault'));
31
        $this->assertNull($metadata->getOption('none'));
32
        $this->assertSame(['key1' => 'value1'], $metadata->getOptions());
33
        $this->assertSame('value1', $metadata->getOption('key1'));
34
35
        $metadata2 = new Metadata('title', 'description', 'image');
36
        $this->assertNull($metadata2->getDomain());
37
        $this->assertSame([], $metadata2->getOptions());
38
    }
39
40
    public function testImageNullGetDefaultImage(): void
41
    {
42
        $metadata = new Metadata('title', 'description');
43
        $this->assertSame($metadata::DEFAULT_MOSAIC_BACKGROUND, $metadata->getImage());
44
    }
45
46
    /**
47
     * @dataProvider isImageAvailableProvider
48
     */
49
    public function testIsImageAvailable(bool $expected, ?string $image): void
50
    {
51
        $this->assertSame(
52
            $expected,
53
            (new Metadata('title', 'description', $image))->isImageAvailable()
54
        );
55
    }
56
57
    public function isImageAvailableProvider(): \Generator
58
    {
59
        yield 'image is null' => [false, null];
60
        yield 'image is available' => [true, 'image.png'];
61
    }
62
}
63