Completed
Pull Request — develop (#14)
by jean-marie
02:10
created

CliCommandPathValidatorTest::createValidator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
c 1
b 1
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Tests\FOA\CronBundle\Validator\Constraints;
4
5
use FOA\CronBundle\Validator\Constraints\CliCommandPath;
6
use FOA\CronBundle\Validator\Constraints\CliCommandPathValidator;
7
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
8
9
/**
10
 * @author JM Leroux <[email protected]>
11
 */
12
class CliCommandPathValidatorTest extends AbstractConstraintValidatorTest
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    protected function createValidator()
18
    {
19
        return new CliCommandPathValidator('/home/akeneo/pim/app');
20
    }
21
22
    public function testValidCommand()
23
    {
24
        $constraint = new CliCommandPath();
25
        $this->validator->validate('php /home/akeneo/pim/app/console debug:container', $constraint);
26
        $this->assertNoViolation();
27
    }
28
29
    /**
30
     * @dataProvider getInvalidValues
31
     *
32
     * @param string $value
33
     */
34
    public function testInvalidValues($value)
35
    {
36
        $constraint = new CliCommandPath();
37
38
        $this->validator->validate($value, $constraint);
39
40
        $this->buildViolation($constraint->message)
41
            ->setParameter('%string%', $value)
42
            ->assertRaised();
43
    }
44
45
    /**
46
     * @return array
47
     */
48
    public function getInvalidValues()
49
    {
50
        return [
51
            ['php /home/akeneo/pim/app/hack.php'],
52
            ['php /usr/bin/console'],
53
            ['/home/akeneo/pim/app/console'],
54
            ['php /home/akeneo/pim/app/console_hacked'],
55
            ['app/console'],
56
        ];
57
    }
58
}
59