|
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
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Query\Tests; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query; |
|
12
|
|
|
use eZ\Publish\Core\Query\QueryFactory; |
|
13
|
|
|
use eZ\Publish\Core\QueryType\QueryType; |
|
14
|
|
|
use eZ\Publish\Core\QueryType\QueryTypeRegistry; |
|
15
|
|
|
use eZ\Publish\Core\Search\Tests\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
final class QueryFactoryTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
private const EXAMPLE_QUERY_TYPE = 'Example'; |
|
20
|
|
|
private const EXAMPLE_QUERY_PARAMS = [ |
|
21
|
|
|
'foo' => 'foo', |
|
22
|
|
|
'bar' => 'bar', |
|
23
|
|
|
'baz' => 'baz', |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
/** @var \eZ\Publish\Core\QueryType\QueryTypeRegistry|\PHPUnit\Framework\MockObject\MockObject */ |
|
27
|
|
|
private $queryTypeRegistry; |
|
28
|
|
|
|
|
29
|
|
|
/** @var \eZ\Publish\Core\Query\QueryFactory */ |
|
30
|
|
|
private $queryFactory; |
|
31
|
|
|
|
|
32
|
|
|
protected function setUp(): void |
|
33
|
|
|
{ |
|
34
|
|
|
$this->queryTypeRegistry = $this->createMock(QueryTypeRegistry::class); |
|
35
|
|
|
$this->queryFactory = new QueryFactory($this->queryTypeRegistry); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testCreate(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$expectedQuery = new Query(); |
|
41
|
|
|
|
|
42
|
|
|
$queryType = $this->createMock(QueryType::class); |
|
43
|
|
|
$queryType |
|
44
|
|
|
->expects($this->once()) |
|
45
|
|
|
->method('getQuery') |
|
46
|
|
|
->with(self::EXAMPLE_QUERY_PARAMS) |
|
47
|
|
|
->willReturn($expectedQuery); |
|
48
|
|
|
|
|
49
|
|
|
$this->queryTypeRegistry |
|
50
|
|
|
->expects($this->once()) |
|
51
|
|
|
->method('getQueryType') |
|
52
|
|
|
->with(self::EXAMPLE_QUERY_TYPE) |
|
53
|
|
|
->willReturn($queryType); |
|
54
|
|
|
|
|
55
|
|
|
$actualQuery = $this->queryFactory->create( |
|
56
|
|
|
self::EXAMPLE_QUERY_TYPE, |
|
57
|
|
|
self::EXAMPLE_QUERY_PARAMS |
|
58
|
|
|
); |
|
59
|
|
|
|
|
60
|
|
|
$this->assertEquals($expectedQuery, $actualQuery); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|