Completed
Branch master (597d40)
by Douglas
02:41 queued 01:20
created

PlaceTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreatingAPlace() 0 7 1
A testCoordinates() 0 4 1
A provideBadCoordinates() 0 8 1
A canMapPlaceCoords() 0 9 1
1
<?php
2
/**
3
 * (c) 2018 Douglas Reith.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Reith\ToyRobot\Domain\Robot;
11
12
use PHPUnit\Framework\TestCase;
13
14
class PlaceTest extends TestCase
15
{
16
    public static function testCreatingAPlace()
17
    {
18
        // Create a placement at 3,2
19
        $place = Place::create([3, 2]);
20
21
        self::assertInstanceOf(Place::class, $place);
22
    }
23
24
    /**
25
     * @dataProvider provideBadCoordinates
26
     * @expectedException \Assert\AssertionFailedException
27
     *
28
     * @param array $badCoords
29
     */
30
    public static function testCoordinates(array $badCoords)
31
    {
32
        Place::create($badCoords);
33
    }
34
35
    public static function provideBadCoordinates(): array
36
    {
37
        return [
38
            [[]], // empty
39
            [['a']], // chars
40
            [[3, 3, 3, 4.5]], // float
41
        ];
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public static function canMapPlaceCoords()
48
    {
49
        $place = Place::create([1, 2, 3]);
50
        $result = $place->map(function ($coord) {
51
            return $coord * 2;
52
        });
53
54
        self::assertEquals([2, 4, 6], $result);
55
    }
56
}
57