Completed
Push — 5.3 ( 958546...1cc96e )
by Jeroen
14:02 queued 07:05
created

unit/Service/Migrations/MigrationsServiceTest.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\TranslatorBundle\Tests\Service\Migrations;
4
5
use Kunstmaan\TranslatorBundle\Service\Migrations\MigrationsService;
6
use Kunstmaan\TranslatorBundle\Tests\unit\WebTestCase;
7
8
class MigrationsServiceTest extends WebTestCase
9
{
10
    private $migrationsService;
11
12 View Code Duplication
    public function setUp()
13
    {
14
        static::bootKernel(['test_case' => 'TranslatorBundleTest', 'root_config' => 'config.yaml']);
15
        $container = static::$kernel->getContainer();
16
        static::loadFixtures($container);
0 ignored issues
show
It seems like $container defined by static::$kernel->getContainer() on line 15 can be null; however, Kunstmaan\TranslatorBund...estCase::loadFixtures() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
17
18
        /* @var MigrationsService migrationsService */
19
        $this->migrationsService = $container->get('kunstmaan_translator.service.migrations.migrations');
20
    }
21
22
    /**
23
     * @group migrations
24
     */
25
    public function testGetDiffSqlArray()
26
    {
27
        $result = $this->migrationsService->getDiffSqlArray();
28
        $this->assertGreaterThanOrEqual(1, count($result));
29
        $this->assertStringStartsWith('INSERT INTO "kuma_translation"', $result[0]);
30
    }
31
}
32