Completed
Push — master ( 7ace69...caa23d )
by Mathieu
01:54 queued 10s
created

XliffConverterTest::testContentToCatalogue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\SymfonyStorage\Tests\Unit;
13
14
use PHPUnit\Framework\TestCase;
15
use Symfony\Component\Translation\MessageCatalogue;
16
use Translation\SymfonyStorage\XliffConverter;
17
18
/**
19
 * @author Tobias Nyholm <[email protected]>
20
 */
21
class XliffConverterTest extends TestCase
22
{
23
    public function testContentToCatalogue()
24
    {
25
        $content = file_get_contents(__DIR__.'/../Fixtures/single-file/messages.en.xlf');
26
        $catalogue = XliffConverter::contentToCatalogue($content, 'en', 'messages');
27
28
        $this->assertEquals('en', $catalogue->getLocale());
29
        $this->assertEquals(['messages'], $catalogue->getDomains());
30
        $this->assertCount(2, $catalogue->all('messages'));
0 ignored issues
show
Documentation introduced by
$catalogue->all('messages') is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
    }
32
33
    public function testCatalogueToContent()
34
    {
35
        $catalogue = new MessageCatalogue('en');
36
        $catalogue->add(['foobar' => 'bar']);
37
        $content = XliffConverter::catalogueToContent($catalogue, 'messages');
38
39
        $this->assertRegExp('|foobar|', $content);
40
    }
41
}
42