1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace TheCodingMachine\TDBM\Dao; |
4
|
|
|
|
5
|
|
|
use TheCodingMachine\TDBM\Test\Dao\Bean\CountryBean; |
|
|
|
|
6
|
|
|
use TheCodingMachine\TDBM\Test\Dao\Bean\UserBean; |
|
|
|
|
7
|
|
|
use TheCodingMachine\TDBM\Test\Dao\Generated\UserBaseDao; |
|
|
|
|
8
|
|
|
use TheCodingMachine\TDBM\UncheckedOrderBy; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* The UserDao class will maintain the persistence of UserBean class into the users table. |
12
|
|
|
*/ |
13
|
|
|
class TestUserDao extends UserBaseDao |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Returns the list of users by alphabetical order. |
17
|
|
|
* |
18
|
|
|
* @return UserBean[] |
19
|
|
|
*/ |
20
|
|
|
public function getUsersByAlphabeticalOrder() |
21
|
|
|
{ |
22
|
|
|
// The third parameter will be used in the "ORDER BY" clause of the SQL query. |
23
|
|
|
return $this->find(null, [], 'login ASC'); |
24
|
|
|
} |
25
|
|
|
/** |
26
|
|
|
* Returns the list of users by alphabetical order. |
27
|
|
|
* |
28
|
|
|
* @return UserBean[] |
29
|
|
|
*/ |
30
|
|
|
public function getUsersFromSqlByAlphabeticalOrder() |
31
|
|
|
{ |
32
|
|
|
// The third parameter will be used in the "ORDER BY" clause of the SQL query. |
33
|
|
|
return $this->findFromSql('users', null, [], 'users.login ASC'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Returns the list of users by alphabetical order. |
38
|
|
|
* |
39
|
|
|
* @return UserBean[] |
40
|
|
|
*/ |
41
|
|
|
public function getUsersByCountryOrder() |
42
|
|
|
{ |
43
|
|
|
// The third parameter will be used in the "ORDER BY" clause of the SQL query. |
44
|
|
|
return $this->find(null, [], 'country.label ASC', ['country']); |
45
|
|
|
} |
46
|
|
|
/** |
47
|
|
|
* Returns the list of users by alphabetical order. |
48
|
|
|
* |
49
|
|
|
* @return UserBean[] |
50
|
|
|
*/ |
51
|
|
|
public function getUsersFromSqlByCountryOrder() |
52
|
|
|
{ |
53
|
|
|
// The third parameter will be used in the "ORDER BY" clause of the SQL query. |
54
|
|
|
return $this->findFromSql('users JOIN country ON country.id = users.country_id', null, [], 'country.label ASC'); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Returns the list of users whose login starts with $login. |
59
|
|
|
* |
60
|
|
|
* @param string $login |
61
|
|
|
* @param string $mode |
62
|
|
|
* |
63
|
|
|
* @return \TheCodingMachine\TDBM\ResultIterator|UserBean[] |
64
|
|
|
*/ |
65
|
|
|
public function getUsersByLoginStartingWith($login = null, $mode = null) |
66
|
|
|
{ |
67
|
|
|
return $this->find('login LIKE :login', ['login' => $login.'%'], null, [], $mode); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns the user whose login is $login. |
72
|
|
|
* |
73
|
|
|
* @param string $login |
74
|
|
|
* |
75
|
|
|
* @return UserBean |
76
|
|
|
*/ |
77
|
|
|
public function getUserByLogin($login) |
78
|
|
|
{ |
79
|
|
|
return $this->findOne('login = :login', ['login' => $login]); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function getUsersByManagerId($managerId) |
83
|
|
|
{ |
84
|
|
|
return $this->find('contact.manager_id = :id!', ['id' => $managerId]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Triggers an error because table "contacts" does not exist. |
89
|
|
|
* |
90
|
|
|
* @return \TheCodingMachine\TDBM\ResultIterator|UserBean[] |
91
|
|
|
*/ |
92
|
|
|
public function getUsersWrongTableName() |
93
|
|
|
{ |
94
|
|
|
return $this->find('contacts.manager_id = 1'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Returns a list of users, sorted by a table on an external column. |
99
|
|
|
* |
100
|
|
|
* @return \TheCodingMachine\TDBM\ResultIterator|UserBean[] |
101
|
|
|
*/ |
102
|
|
|
public function getUsersByCountryName() |
103
|
|
|
{ |
104
|
|
|
return $this->find(null, [], 'country.label DESC'); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* A test to sort by function. |
109
|
|
|
* |
110
|
|
|
* @return \TheCodingMachine\TDBM\ResultIterator|UserBean[] |
111
|
|
|
*/ |
112
|
|
|
public function getUsersByReversedCountryName() |
113
|
|
|
{ |
114
|
|
|
return $this->find(null, [], new UncheckedOrderBy('REVERSE(country.label) ASC')); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* A test to check exceptions when providing expressions in ORDER BY clause. |
119
|
|
|
* |
120
|
|
|
* @return \TheCodingMachine\TDBM\ResultIterator|UserBean[] |
121
|
|
|
*/ |
122
|
|
|
public function getUsersByInvalidOrderBy() |
123
|
|
|
{ |
124
|
|
|
return $this->find(null, [], 'REVERSE(country.label) ASC'); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param CountryBean $country |
129
|
|
|
* @param string[] $names |
130
|
|
|
* @return \TheCodingMachine\TDBM\ResultIterator|UserBean[] |
131
|
|
|
*/ |
132
|
|
|
public function getUsersByComplexFilterBag(CountryBean $country, array $names) |
133
|
|
|
{ |
134
|
|
|
$filterBag = [ |
135
|
|
|
'person.name' => $names |
136
|
|
|
]; |
137
|
|
|
$filterBag[] = $country; |
138
|
|
|
return $this->find($filterBag); |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths