Passed
Push — test ( d838cf...cef4a5 )
by Tom
03:29
created

NameBuilderTest::testSlugify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\Runner\Containers;
6
7
use Ktomk\Pipelines\TestCase;
8
9
/**
10
 * Class NameBuilderTest
11
 *
12
 * @package Ktomk\Pipelines\Runner\Containers
13
 * @covers \Ktomk\Pipelines\Runner\Containers\NameBuilder
14
 */
15
class NameBuilderTest extends TestCase
16
{
17
    public function provideSlugifyStrings()
18
    {
19
        return array(
20
            array('a', null, 'a'),
21
            array("\xC3\xB6", null, ''), # Unicode Character 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6)
22
            array('#', null, ''),
23
            array('foo#-mixing-food.#3service', null, 'foo-mixing-food-3service'),
24
            array('33.5 horses on the run', null, 'horses-on-the-run'),
25
            array('-33.5 horses on the run', null, 'horses-on-the-run'),
26
            array('it was - (minus!) 33.5 degrees - how that was fun', '_', 'it_was_minus_33.5_degrees_how_that_was_fun'),
27
            array('-#.#.#.#.#-', null, ''),
28
        );
29
    }
30
31
    /**
32
     * @dataProvider provideSlugifyStrings
33
     *
34
     * @param string $string
35
     * @param null|string $replacement
36
     * @param string $expected
37
     */
38
    public function testSlugify($string, $replacement, $expected)
39
    {
40
        $actual = NameBuilder::slugify($string, $replacement);
41
        self::assertSame($expected, $actual);
42
    }
43
44
    /**
45
     * @dataProvider provideSlugifyStrings
46
     *
47
     * @param string $string
48
     * @param null|string $replacement
49
     * @param string $expected
50
     */
51
    public function testSlugifyFallBack($string, $replacement, $expected)
52
    {
53
        if ('' === $expected) {
54
            $expected = 'fall-back';
55
        }
56
        $actual = NameBuilder::slugify($string, $replacement, 'fall-back');
57
        self::assertSame($expected, $actual);
58
    }
59
60
    public function testServiceContainerName()
61
    {
62
        $actual = NameBuilder::serviceContainerName(null, null, null);
63
        self::assertSame('service-unnamed', $actual);
64
    }
65
66
    public function testStepContainerName()
67
    {
68
        $actual = NameBuilder::stepContainerName(null, null, null, 'null', null);
69
        self::assertSame('null-1.no-name.null', $actual);
70
71
        $expected = 'prefix.service-redis.app';
72
        $actual = NameBuilder::serviceContainerName('prefix', 'redis', 'app');
73
        self::assertSame($expected, $actual);
74
    }
75
76
    public function testStepContainerNameByStep()
77
    {
78
        $pipeline = $this->createMock('Ktomk\Pipelines\File\Pipeline');
79
        $step = $this->createMock('Ktomk\Pipelines\File\Pipeline\Step');
80
        $step->method('getPipeline')->willReturn($pipeline);
81
82
        self::assertSame('null-1.no-name.null', NameBuilder::stepContainerNameByStep($step, 'null', null));
83
    }
84
}
85