Passed
Push — master ( b9b7aa...00462a )
by Mr
07:16
created

MetadataTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 96.3%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 30
c 4
b 0
f 0
dl 0
loc 47
ccs 26
cts 27
cp 0.963
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testToNative() 0 11 1
A testEquals() 0 5 1
A testWith() 0 9 1
A testFromNative() 0 14 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/metadata project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Tests\Metadata;
10
11
use Assert\InvalidArgumentException;
12
use Daikon\Metadata\Metadata;
13
use PHPUnit\Framework\TestCase;
14
15
final class MetadataTest extends TestCase
16
{
17 1
    public function testFromNative(): void
18
    {
19 1
        $metadata = Metadata::fromNative([
20 1
            'some_string' => 'foo',
21
            'some_yay' => true,
22
            'some_number' => 23,
23
            'some_float' => 23.42,
24
            'some_array' => ['captain' => 'arr']
25
        ]);
26 1
        $this->assertEquals($metadata->get('some_string'), 'foo');
27 1
        $this->assertTrue($metadata->get('some_yay'));
28 1
        $this->assertEquals($metadata->get('some_number'), 23);
29 1
        $this->assertEquals($metadata->get('some_float'), 23.42);
30 1
        $this->assertEquals($metadata->get('some_array'), ['captain' => 'arr']);
31 1
    }
32
33 1
    public function testToNative(): void
34
    {
35
        $metadataArray = [
36 1
            'foo' => 'bar',
37
            'yay_or_nay' => true,
38
            'some_number' => 23,
39
            'some_float' => 23.42,
40
            'some_array' => ['captain' => 'arr']
41
        ];
42 1
        $metadata = Metadata::fromNative($metadataArray);
43 1
        $this->assertEquals($metadata->toNative(), $metadataArray);
44 1
    }
45
46 1
    public function testWith(): void
47
    {
48 1
        $emptyMetadata = Metadata::makeEmpty();
49 1
        $metadata = $emptyMetadata->with('foo', 'bar');
50 1
        $this->assertNull($emptyMetadata->get('foo', null));
51 1
        $this->assertEquals($metadata->get('foo'), 'bar');
52 1
        $this->assertFalse($metadata->equals($emptyMetadata));
53 1
        $this->expectException(InvalidArgumentException::class);
54 1
        $this->assertNull($emptyMetadata->get('foo'));
55
    }
56
57 1
    public function testEquals(): void
58
    {
59 1
        $metadata = Metadata::makeEmpty()->with('foo', 'bar');
60 1
        $this->assertTrue($metadata->equals(Metadata::fromNative(['foo' => 'bar'])));
61 1
        $this->assertFalse($metadata->equals(Metadata::fromNative(['foo' => 'baz'])));
62 1
    }
63
}
64