Completed
Pull Request — master (#10)
by Dominik
02:51
created

ValidatorServiceTest::getInvalidXliff()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Decline\TransformatBundle\Tests\Services;
4
5
use Decline\TransformatBundle\Services\ValidatorService;
6
use Decline\TransformatBundle\Tests\ContainerTestCase;
7
use Decline\TransformatBundle\Tests\Services\Interfaces\ServiceTestInterface;
8
9
/**
10
 * Class ValidatorServiceTest
11
 * @package Decline\TransformatBundle\Tests\Services
12
 */
13
class ValidatorServiceTest extends ContainerTestCase implements ServiceTestInterface
14
{
15
16
    /**
17
     * Tests the validation of the translation files
18
     */
19
    public function testValidate()
20
    {
21
        $validXliff = $this->getValidXliff();
22
        $invalidXliff = $this->getInvalidXliff();
23
24
        $validator = $this->getValidator(ValidatorService::MODE_DISABLED);
25
        $strictValidator = $this->getValidator(ValidatorService::MODE_STRICT);
26
        $transitionalValidator = $this->getValidator(ValidatorService::MODE_TRANSITIONAL);
27
28
        $this->assertCount(0, $validator->validate($validXliff));
0 ignored issues
show
Bug introduced by
It seems like $validXliff defined by $this->getValidXliff() on line 21 can also be of type boolean; however, Decline\TransformatBundl...atorService::validate() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
29
        $this->assertCount(0, $validator->validate($invalidXliff));
0 ignored issues
show
Bug introduced by
It seems like $invalidXliff defined by $this->getInvalidXliff() on line 22 can also be of type boolean; however, Decline\TransformatBundl...atorService::validate() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
30
31
        $this->assertCount(0, $strictValidator->validate($validXliff));
0 ignored issues
show
Bug introduced by
It seems like $validXliff defined by $this->getValidXliff() on line 21 can also be of type boolean; however, Decline\TransformatBundl...atorService::validate() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
32
        $this->assertCount(1, $strictValidator->validate($invalidXliff));
0 ignored issues
show
Bug introduced by
It seems like $invalidXliff defined by $this->getInvalidXliff() on line 22 can also be of type boolean; however, Decline\TransformatBundl...atorService::validate() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
33
34
        $this->assertCount(0, $transitionalValidator->validate($validXliff));
0 ignored issues
show
Bug introduced by
It seems like $validXliff defined by $this->getValidXliff() on line 21 can also be of type boolean; however, Decline\TransformatBundl...atorService::validate() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
35
        $this->assertCount(1, $transitionalValidator->validate($invalidXliff));
0 ignored issues
show
Bug introduced by
It seems like $invalidXliff defined by $this->getInvalidXliff() on line 22 can also be of type boolean; however, Decline\TransformatBundl...atorService::validate() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
36
    }
37
38
    /**
39
     * Gets the validator for the given validation mode
40
     *
41
     * @param string $mode
42
     *
43
     * @return ValidatorService
44
     */
45
    private function getValidator($mode)
46
    {
47
        return new ValidatorService(['xliff' => ['validation' => $mode]]);
48
    }
49
50
    /**
51
     * Returns the content of a valid xliff file
52
     * @return bool|string
53
     */
54
    private function getValidXliff()
55
    {
56
        return file_get_contents(static::RESOURCES_DIR . '/' . static::TRANSLATION_VALID);
57
    }
58
59
    /**
60
     * Returns the content of an invalid xliff file
61
     * @return bool|string
62
     */
63
    private function getInvalidXliff()
64
    {
65
        return file_get_contents(static::RESOURCES_DIR . '/' . static::TRANSLATION_INVALID);
66
    }
67
}