Completed
Push — master ( cfe8d7...fcc746 )
by André
19:36 queued 06:48
created

CriteriaConverterTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testConvertCriteriaSuccess() 0 41 1
A testConvertCriteriaFailure() 0 8 1
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Persistence\Legacy\Tests\URL\Query;
8
9
use eZ\Publish\API\Repository\Values\URL\Query\Criterion;
10
use eZ\Publish\Core\Persistence\Database\Expression;
11
use eZ\Publish\Core\Persistence\Database\SelectQuery;
12
use eZ\Publish\Core\Persistence\Legacy\URL\Query\CriteriaConverter;
13
use eZ\Publish\Core\Persistence\Legacy\URL\Query\CriterionHandler;
14
use PHPUnit\Framework\TestCase;
15
16
class CriteriaConverterTest extends TestCase
17
{
18
    public function testConvertCriteriaSuccess()
19
    {
20
        $fooCriterionHandler = $this->createMock(CriterionHandler::class);
21
        $barCriterionHandler = $this->createMock(CriterionHandler::class);
22
23
        $criteriaConverter = new CriteriaConverter([
24
            $fooCriterionHandler,
25
            $barCriterionHandler,
26
        ]);
27
28
        $barCriterion = $this->createMock(Criterion::class);
29
30
        $selectQuery = $this->createMock(SelectQuery::class);
31
        $expression = $this->createMock(Expression::class);
32
33
        $fooCriterionHandler
34
            ->expects($this->once())
35
            ->method('accept')
36
            ->with($barCriterion)
37
            ->willReturn(false);
38
39
        $fooCriterionHandler
40
            ->expects($this->never())
41
            ->method('handle');
42
43
        $barCriterionHandler
44
            ->expects($this->once())
45
            ->method('accept')
46
            ->with($barCriterion)
47
            ->willReturn(true);
48
49
        $barCriterionHandler
50
            ->expects($this->once())
51
            ->method('handle')
52
            ->with($criteriaConverter, $selectQuery, $barCriterion)
53
            ->willReturn($expression);
54
55
        $this->assertEquals($expression, $criteriaConverter->convertCriteria(
56
            $selectQuery, $barCriterion
57
        ));
58
    }
59
60
    /**
61
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotImplementedException
62
     */
63
    public function testConvertCriteriaFailure()
64
    {
65
        $criteriaConverter = new CriteriaConverter();
66
        $criteriaConverter->convertCriteria(
67
            $this->createMock(SelectQuery::class),
68
            $this->createMock(Criterion::class)
69
        );
70
    }
71
}
72