Completed
Pull Request — master (#1)
by Rafał
04:48
created

TenantRepositorySpec::it_finds_available_tenants()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 8
nc 1
nop 3
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace spec\SWP\MultiTenancyBundle\Repository;
15
16
use PhpSpec\ObjectBehavior;
17
use Prophecy\Argument;
18
use Doctrine\ORM\Mapping\ClassMetadata;
19
use Doctrine\ORM\EntityManager;
20
use Doctrine\ORM\QueryBuilder;
21
use Doctrine\ORM\Query\Expr;
22
use Doctrine\ORM\AbstractQuery;
23
24
class TenantRepositorySpec extends ObjectBehavior
25
{
26
    public function let(EntityManager $entityManager, ClassMetadata $classMetadata)
27
    {
28
        $this->beConstructedWith($entityManager, $classMetadata);
29
    }
30
31
    public function it_is_initializable()
32
    {
33
        $this->shouldHaveType('SWP\MultiTenancyBundle\Repository\TenantRepository');
34
    }
35
36
    public function it_is_a_repository()
37
    {
38
        $this->shouldHaveType('Doctrine\ORM\EntityRepository');
39
        $this->shouldImplement('SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface');
40
    }
41
42
    public function it_finds_by_subdomain($entityManager, QueryBuilder $builder, AbstractQuery $query)
43
    {
44
        $entityManager->createQueryBuilder()->shouldBeCalled()->willReturn($builder);
45
        $builder->select('t')->shouldBeCalled()->willReturn($builder);
46
        $builder->from(Argument::any(), 't', Argument::cetera())->shouldBeCalled()->willReturn($builder);
47
        $builder->where('t.subdomain = :subdomain')->shouldBeCalled()->willReturn($builder);
48
        $builder->andWhere('t.enabled = true')->shouldBeCalled()->willReturn($builder);
49
        $builder->setParameter('subdomain', 'example1')->shouldBeCalled()->willReturn($builder);
50
        $builder->getQuery()->shouldBeCalled()->willReturn($query);
51
        $query->getOneOrNullResult()->shouldBeCalled();
52
53
        $this->findBySubdomain('example1');
54
    }
55
56
    public function it_finds_available_tenants($entityManager, QueryBuilder $builder, AbstractQuery $query)
57
    {
58
        $entityManager->createQueryBuilder()->willReturn($builder);
59
        $builder->select('t')->willReturn($builder);
60
        $builder->from(Argument::any(), 't', Argument::cetera())->willReturn($builder);
61
        $builder->where('t.enabled = true')->willReturn($builder);
62
        $builder->getQuery()->willReturn($query);
63
        $query->getArrayResult()->shouldBeCalled();
64
65
        $this->findAvailableTenants();
66
    }
67
}
68