Completed
Pull Request — master (#33)
by Kevin
09:56
created

FunctionalTest::addTestData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Zenstruck\RedirectBundle\Tests\Functional;
4
5
use Doctrine\ORM\EntityManager;
6
use Symfony\Bundle\FrameworkBundle\Client;
7
use Symfony\Bundle\FrameworkBundle\Console\Application;
8
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
9
use Symfony\Component\Console\Input\StringInput;
10
use Symfony\Component\Console\Output\NullOutput;
11
use Zenstruck\RedirectBundle\Model\NotFound;
12
use Zenstruck\RedirectBundle\Model\Redirect;
13
use Zenstruck\RedirectBundle\Tests\Fixture\Bundle\Entity\DummyRedirect;
14
use Zenstruck\RedirectBundle\Tests\Fixture\TestKernel;
15
16
/**
17
 * @author Kevin Bond <[email protected]>
18
 */
19
abstract class FunctionalTest extends WebTestCase
20
{
21
    /** @var Client */
22
    protected $client;
23
24
    /** @var EntityManager */
25
    protected $em;
26
27
    public function setUp(): void
28
    {
29
        $client = self::createClient();
30
31
        $application = new Application($client->getKernel());
32
        $application->setAutoExit(false);
33
34
        $application->run(new StringInput('doctrine:database:drop --force'), new NullOutput());
35
        $application->run(new StringInput('doctrine:database:create'), new NullOutput());
36
        $application->run(new StringInput('doctrine:schema:create'), new NullOutput());
37
38
        $this->em = $client->getContainer()->get('doctrine.orm.default_entity_manager');
39
        $this->client = $client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $client of type object<Symfony\Bundle\Fr...rkBundle\KernelBrowser> is incompatible with the declared type object<Symfony\Bundle\FrameworkBundle\Client> of property $client.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
41
        $this->addTestData();
42
    }
43
44
    protected static function getKernelClass()
45
    {
46
        return TestKernel::class;
47
    }
48
49
    /**
50
     * @param string $source
51
     *
52
     * @return Redirect|null
53
     */
54
    protected function getRedirect($source)
55
    {
56
        if (null === $redirect = $this->em->getRepository('TestBundle:DummyRedirect')->findOneBy(['source' => $source])) {
57
            return null;
58
        }
59
60
        $this->em->refresh($redirect);
61
62
        return $redirect;
63
    }
64
65
    /**
66
     * @return NotFound[]
67
     */
68
    protected function getNotFounds()
69
    {
70
        return $this->em->getRepository('TestBundle:DummyNotFound')->findAll();
71
    }
72
73
    protected function addTestData()
74
    {
75
        $this->em->createQuery('DELETE TestBundle:DummyRedirect')
76
            ->execute()
77
        ;
78
79
        $this->em->createQuery('DELETE TestBundle:DummyNotFound')
80
            ->execute()
81
        ;
82
83
        $this->em->persist(new DummyRedirect('/301-redirect', 'http://symfony.com'));
84
        $this->em->persist(new DummyRedirect('/302-redirect', 'http://example.com', false));
85
86
        $this->em->flush();
87
    }
88
}
89