FilterTypeGuesserTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testThrowsOnMissingField() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\DoctrineMongoDBAdminBundle\Tests\Guesser;
15
16
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
17
use PHPUnit\Framework\TestCase;
18
use Sonata\DoctrineMongoDBAdminBundle\Guesser\FilterTypeGuesser;
19
use Sonata\DoctrineMongoDBAdminBundle\Model\ModelManager;
20
21
class FilterTypeGuesserTest extends TestCase
22
{
23
    private $guesser;
24
    private $modelManager;
25
    private $metadata;
26
27
    protected function setUp(): void
28
    {
29
        $this->guesser = new FilterTypeGuesser();
30
        $this->modelManager = $this->prophesize(ModelManager::class);
31
        $this->metadata = $this->prophesize(ClassMetadata::class);
32
    }
33
34
    public function testThrowsOnMissingField(): void
35
    {
36
        $this->expectException(\Sonata\DoctrineMongoDBAdminBundle\Model\MissingPropertyMetadataException::class);
37
38
        $class = 'My\Model';
39
        $property = 'whatever';
40
41
        $this->metadata->hasAssociation($property)->willReturn(false);
42
43
        $this->modelManager->getParentMetadataForProperty($class, $property)->willReturn([
44
            $this->metadata->reveal(),
45
            $property,
46
            'parent mappings, no idea what it looks like',
47
        ]);
48
        $this->guesser->guessType($class, $property, $this->modelManager->reveal());
49
    }
50
}
51