LangManagerTest::testNumberLanguages()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 9
rs 10
1
<?php
2
3
namespace GGGGino\SkuskuCartBundle\Tests\Service;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
use Doctrine\Common\Persistence\ObjectRepository;
7
use Doctrine\ORM\EntityManager;
8
use Doctrine\ORM\EntityRepository;
9
use GGGGino\SkuskuCartBundle\Entity\SkuskuLanguage;
0 ignored issues
show
Bug introduced by
The type GGGGino\SkuskuCartBundle\Entity\SkuskuLanguage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use GGGGino\SkuskuCartBundle\Model\SkuskuLangInterface;
11
use GGGGino\SkuskuCartBundle\Service\LangManager;
12
use GGGGino\SkuskuCartBundle\Tests\Entity\SkuskuLangTest;
13
use GGGGino\SkuskuCartBundle\Tests\TestKernel;
14
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
15
16
class LangManagerTest extends WebTestCase
17
{
18
    private $client;
19
20
    protected static function createKernel(array $options = [])
21
    {
22
        return new TestKernel();
23
    }
24
25
    /**
26
     * @inheritdoc
27
     */
28
    protected function setUp()
29
    {
30
        $this->client = static::createClient();
31
32
        // Mock languages
33
        $repoLangs = $this->createMock(ObjectRepository::class);
34
        $repoLangs->expects($this->any())
35
            ->method('findAll')
36
            ->willReturn($this->fakeLanguages());
37
38
        // Last, mock the EntityManager to return the mock of the repository
39
        $objectManager = $this->createMock(EntityManager::class);
40
        // use getMock() on PHPUnit 5.3 or below
41
        // $objectManager = $this->getMock(ObjectManager::class);
42
        $objectManager->expects($this->any())
43
            ->method('getRepository')
44
            ->with($this->equalTo(SkuskuLangInterface::class))
45
            ->willReturn($repoLangs);
46
47
        static::$kernel->getContainer()->set('doctrine.orm.default_entity_manager', $objectManager);
48
    }
49
50
    private function fakeLanguages()
51
    {
52
        return array(
53
            (new SkuskuLangTest())->setName('Euro')->setIsoCode('EUR'),
54
            (new SkuskuLangTest())->setName('Lira')->setIsoCode('£')
55
        );
56
    }
57
58
    public function testNumberLanguages()
59
    {
60
        //$this->client->request('GET', '/cart');
61
62
        /** @var LangManager $langManager */
63
        $langManager = $this->client->getContainer()->get(LangManager::class);
64
        //$langManager->setEm($objectManager);
65
66
        $this->assertCount(2, $langManager->getActiveLanguages());
67
    }
68
}