|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BlueBear\AdminBundle\Tests\AdminBundle\DataProvider; |
|
4
|
|
|
|
|
5
|
|
|
use LAG\AdminBundle\DataProvider\DataProvider; |
|
6
|
|
|
use LAG\AdminBundle\Tests\Base; |
|
7
|
|
|
use stdClass; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Test the built-in data provider |
|
11
|
|
|
*/ |
|
12
|
|
|
class DataProviderTest extends Base |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Method save SHOULD be called on the entiy repository |
|
16
|
|
|
*/ |
|
17
|
|
View Code Duplication |
public function testSave() |
|
18
|
|
|
{ |
|
19
|
|
|
// repository save method SHOULD be called |
|
20
|
|
|
$repositoryMock = $this->mockEntityRepository(); |
|
21
|
|
|
$repositoryMock |
|
22
|
|
|
->expects($this->once()) |
|
23
|
|
|
->method('save'); |
|
24
|
|
|
|
|
25
|
|
|
$dataProvider = new DataProvider($repositoryMock); |
|
|
|
|
|
|
26
|
|
|
$dataProvider->save(new stdClass()); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Method delete SHOULD be called on the entity repository |
|
31
|
|
|
*/ |
|
32
|
|
View Code Duplication |
public function testDelete() |
|
33
|
|
|
{ |
|
34
|
|
|
// entity manager delete method SHOULD be called |
|
35
|
|
|
$repositoryMock = $this->mockEntityRepository(); |
|
36
|
|
|
$repositoryMock |
|
37
|
|
|
->expects($this->once()) |
|
38
|
|
|
->method('delete'); |
|
39
|
|
|
|
|
40
|
|
|
$dataProvider = new DataProvider($repositoryMock); |
|
|
|
|
|
|
41
|
|
|
$dataProvider->remove(new stdClass()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Method find SHOULD be called on the entity repository |
|
46
|
|
|
*/ |
|
47
|
|
View Code Duplication |
public function testFind() |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
// repository find method SHOULD be called |
|
50
|
|
|
$repositoryMock = $this->mockEntityRepository(); |
|
51
|
|
|
$repositoryMock |
|
52
|
|
|
->expects($this->once()) |
|
53
|
|
|
->method('find'); |
|
54
|
|
|
|
|
55
|
|
|
$dataProvider = new DataProvider($repositoryMock); |
|
|
|
|
|
|
56
|
|
|
$dataProvider->find('unique_id'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Method findBy SHOULD be called on the entity repository |
|
61
|
|
|
*/ |
|
62
|
|
View Code Duplication |
public function testfindBy() |
|
63
|
|
|
{ |
|
64
|
|
|
// repository findBy method SHOULD be called |
|
65
|
|
|
$repositoryMock = $this->mockEntityRepository(); |
|
66
|
|
|
$repositoryMock |
|
67
|
|
|
->expects($this->once()) |
|
68
|
|
|
->method('findBy'); |
|
69
|
|
|
|
|
70
|
|
|
$dataProvider = new DataProvider($repositoryMock); |
|
|
|
|
|
|
71
|
|
|
$dataProvider->findBy([]); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.