Completed
Push — master ( ba8ed9...770316 )
by Jeroen
06:11
created

TranslatorBundle/Tests/unit/WebTestCase.php (1 issue)

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\unit;
4
5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase as BaseWebTestCase;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
use Symfony\Component\Filesystem\Filesystem;
8
use Nelmio\Alice\Loader\NativeLoader;
9
10
class WebTestCase extends BaseWebTestCase
11
{
12
    public static function assertRedirect($response, $location)
13
    {
14
        self::assertTrue($response->isRedirect(), 'Response is not a redirect, got status code: '.$response->getStatusCode());
15
        self::assertEquals('http://localhost'.$location, $response->headers->get('Location'));
16
    }
17
18
    public static function setUpBeforeClass()
19
    {
20
        static::deleteTmpDir();
21
    }
22
23
    public static function tearDownAfterClass()
24
    {
25
        static::deleteTmpDir();
26
    }
27
28
    protected static function deleteTmpDir()
29
    {
30
        if (!file_exists($dir = sys_get_temp_dir().'/'.static::getVarDir())) {
31
            return;
32
        }
33
34
        $fs = new Filesystem();
35
        $fs->remove($dir);
36
    }
37
38
    protected static function getKernelClass()
39
    {
40
        require_once __DIR__.'/app/AppKernel.php';
41
42
        return 'Kunstmaan\TranslatorBundle\Tests\app\AppKernel';
43
    }
44
45
    protected static function createKernel(array $options = [])
46
    {
47
        $class = self::getKernelClass();
48
49
        if (!isset($options['test_case'])) {
50
            throw new \InvalidArgumentException('The option "test_case" must be set.');
51
        }
52
53
        return new $class(
54
            static::getVarDir(),
55
            $options['test_case'],
56
            isset($options['root_config']) ? $options['root_config'] : 'config.yml',
57
            isset($options['environment']) ? $options['environment'] : strtolower(static::getVarDir().$options['test_case']),
58
            isset($options['debug']) ? $options['debug'] : true
59
        );
60
    }
61
62
    protected static function getVarDir()
63
    {
64
        return 'FB'.substr(strrchr(\get_called_class(), '\\'), 1);
65
    }
66
67
    protected static function loadFixtures(ContainerInterface $container)
68
    {
69
        $em = $container->get('doctrine.orm.default_entity_manager');
70
        $meta = $em->getMetadataFactory()->getAllMetadata();
71
        $tool = new \Doctrine\ORM\Tools\SchemaTool($em);
0 ignored issues
show
$em is of type object|null, but the function expects a object<Doctrine\ORM\EntityManagerInterface>.

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...
72
        $tool->dropSchema($meta);
73
        $tool->createSchema($meta);
74
75
        // insert fixtures
76
        $fixtures = __DIR__.'/files/fixtures.yml';
77
        $loader = new NativeLoader();
78
        $objects = $loader->loadFile($fixtures)->getObjects();
79
        foreach ($objects as $object) {
80
            $em->persist($object);
81
        }
82
        $em->flush();
83
    }
84
}
85