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

CliCommandPathValidatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createValidator() 0 4 1
A testValidCommand() 0 6 1
A testInvalidValues() 0 10 1
A getInvalidValues() 0 10 1
1
<?php
2
namespace Tests\FOA\CronBundle\Validator\Constraints;
3
4
use FOA\CronBundle\Manager\Cron;
5
use FOA\CronBundle\Validator\Constraints\CliCommandPath;
6
use FOA\CronBundle\Validator\Constraints\CliCommandPathValidator;
7
use InvalidArgumentException;
8
use PHPUnit\Framework\TestCase;
9
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
10
11
class CliCommandPathValidatorTest extends AbstractConstraintValidatorTest
12
{
13
    protected function createValidator()
14
    {
15
        return new CliCommandPathValidator('/home/akeneo/pim/app');
16
    }
17
18
    public function testValidCommand()
19
    {
20
        $constraint = new CliCommandPath();
21
        $this->validator->validate('php /home/akeneo/pim/app/console debug:container', $constraint);
22
        $this->assertNoViolation();
23
    }
24
25
    /**
26
     * @dataProvider getInvalidValues
27
     */
28
    public function testInvalidValues($value)
29
    {
30
        $constraint = new CliCommandPath();
31
32
        $this->validator->validate($value, $constraint);
33
34
        $this->buildViolation($constraint->message)
35
            ->setParameter('%string%', $value)
36
            ->assertRaised();
37
    }
38
39
    public function getInvalidValues()
40
    {
41
        return [
42
            ['php /home/akeneo/pim/app/hack.php'],
43
            ['php /usr/bin/console'],
44
            ['/home/akeneo/pim/app/console'],
45
            ['php /home/akeneo/pim/app/console_hacked'],
46
            ['app/console'],
47
        ];
48
    }
49
}
50