-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
FieldApiControllerTest.php
76 lines (60 loc) · 2.05 KB
/
FieldApiControllerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/*
* @copyright 2016 Mautic Contributors. All rights reserved
* @author Mautic, Inc.
*
* @link https://mautic.org
*
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
*/
namespace Mautic\LeadBundle\Tests\Controller\Api;
use Mautic\CampaignBundle\Tests\CampaignTestAbstract;
use Mautic\LeadBundle\Controller\Api\FieldApiController;
use Symfony\Component\HttpFoundation\Request;
class FieldApiControllerTest extends CampaignTestAbstract
{
private $defaultWhere = [
[
'col' => 'object',
'expr' => 'eq',
'val' => null,
],
];
public function testgetWhereFromRequestWithNoWhere()
{
$request = $this->getMockBuilder(Request::class)
->disableOriginalConstructor()
->getMock();
$result = $this->getResultFromProtectedMethod('getWhereFromRequest', [], $request);
$this->assertEquals($this->defaultWhere, $result);
}
public function testgetWhereFromRequestWithSomeWhere()
{
$where = [
[
'col' => 'id',
'expr' => 'eq',
'val' => 5,
],
];
$request = $this->getMockBuilder(Request::class)
->onlyMethods(['get'])
->disableOriginalConstructor()
->getMock();
$request->method('get')
->willReturn($where);
$result = $this->getResultFromProtectedMethod('getWhereFromRequest', [], $request);
$this->assertEquals(array_merge($where, $this->defaultWhere), $result);
}
protected function getResultFromProtectedMethod($method, array $args, Request $request = null)
{
$controller = new FieldApiController();
if ($request) {
$controller->setRequest($request);
}
$controllerReflection = new \ReflectionClass(FieldApiController::class);
$method = $controllerReflection->getMethod($method);
$method->setAccessible(true);
return $method->invokeArgs($controller, $args);
}
}