|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sonata Project package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sonata\AdminBundle\Tests\Filter\Persister; |
|
13
|
|
|
|
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
|
16
|
|
|
use Sonata\AdminBundle\Filter\Persister\SessionFilterPersister; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
|
18
|
|
|
|
|
19
|
|
|
class SessionFilterPersisterTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var SessionInterface|ObjectProphecy |
|
23
|
|
|
*/ |
|
24
|
|
|
private $session; |
|
25
|
|
|
|
|
26
|
|
|
public function setUp() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->session = $this->prophesize(SessionInterface::class); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function tearDown() |
|
32
|
|
|
{ |
|
33
|
|
|
unset($this->session); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testGetDefaultValueFromSessionIfNotDefined() |
|
37
|
|
|
{ |
|
38
|
|
|
$this->session->get('admin.customer.filter.parameters', []) |
|
39
|
|
|
->shouldBeCalledTimes(1) |
|
40
|
|
|
->willReturn([]); |
|
41
|
|
|
|
|
42
|
|
|
self::assertSame([], $this->createPersister()->get('admin.customer')); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testGetValueFromSessionIfDefined() |
|
46
|
|
|
{ |
|
47
|
|
|
$filters = [ |
|
48
|
|
|
'active' => true, |
|
49
|
|
|
'_page' => 1, |
|
50
|
|
|
'_sort_by' => 'firstName', |
|
51
|
|
|
'_sort_order' => 'ASC', |
|
52
|
|
|
'_per_page' => 25, |
|
53
|
|
|
]; |
|
54
|
|
|
$this->session->get('admin.customer.filter.parameters', []) |
|
55
|
|
|
->shouldBeCalledTimes(1) |
|
56
|
|
|
->willReturn($filters); |
|
57
|
|
|
|
|
58
|
|
|
self::assertSame($filters, $this->createPersister()->get('admin.customer')); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function testSetValueToSession() |
|
62
|
|
|
{ |
|
63
|
|
|
$filters = [ |
|
64
|
|
|
'active' => true, |
|
65
|
|
|
'_page' => 1, |
|
66
|
|
|
'_sort_by' => 'firstName', |
|
67
|
|
|
'_sort_order' => 'ASC', |
|
68
|
|
|
'_per_page' => 25, |
|
69
|
|
|
]; |
|
70
|
|
|
$this->session->set('admin.customer.filter.parameters', $filters) |
|
71
|
|
|
->shouldBeCalledTimes(1) |
|
72
|
|
|
->willReturn(null); |
|
73
|
|
|
|
|
74
|
|
|
$this->createPersister()->set('admin.customer', $filters); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testResetValueToSession() |
|
78
|
|
|
{ |
|
79
|
|
|
$this->session->remove('admin.customer.filter.parameters') |
|
80
|
|
|
->shouldBeCalledTimes(1) |
|
81
|
|
|
->willReturn(null); |
|
82
|
|
|
|
|
83
|
|
|
$this->createPersister()->reset('admin.customer'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @return SessionFilterPersister |
|
88
|
|
|
*/ |
|
89
|
|
|
private function createPersister() |
|
90
|
|
|
{ |
|
91
|
|
|
return new SessionFilterPersister($this->session->reveal()); |
|
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.