1
+ <?php
2
+
3
+ namespace FQ \Tests \Query ;
4
+
5
+ use FQ \Query \FilesQuery ;
6
+ use FQ \Query \FilesQueryBuilder ;
7
+ use FQ \Query \FilesQueryRequirements ;
8
+ use FQ \Query \Selection \ChildSelection ;
9
+ use FQ \Query \Selection \DirSelection ;
10
+ use FQ \Query \Selection \RootSelection ;
11
+
12
+ class FilesQueryBuilderTest extends AbstractFilesQueryTests {
13
+
14
+ /**
15
+ * @var FilesQueryBuilder
16
+ */
17
+ private $ _builder ;
18
+
19
+ function setUp () {
20
+ parent ::setUp ();
21
+
22
+ $ this ->_builder = new FilesQueryBuilder ($ this ->files ());
23
+ $ this ->nonPublicMethodObject ($ this ->builder ());
24
+ }
25
+ protected function builder () {
26
+ return $ this ->_builder ;
27
+ }
28
+
29
+ public function testConstructor ()
30
+ {
31
+ $ builder = new FilesQueryBuilder ($ this ->files ());
32
+ $ this ->assertNotNull ($ builder );
33
+ $ this ->assertTrue ($ builder instanceof FilesQueryBuilder);
34
+ }
35
+
36
+ public function testIncludeRootDirsById () {
37
+ $ builder = $ this ->builder ();
38
+ $ builder ->includeRootDirs ($ this ->rootDir ()->id ());
39
+ $ this ->assertEquals (array (
40
+ $ this ->rootDir ()->id ()
41
+ ), $ builder ->rootSelection ()->getIncludedDirsById ());
42
+ }
43
+ public function testIncludeRootDirsByArrayOfRootDirs () {
44
+ $ builder = $ this ->builder ();
45
+ $ builder ->includeRootDirs (array ($ this ->rootDir ()));
46
+ $ this ->assertEquals (array (
47
+ $ this ->rootDir ()
48
+ ), $ builder ->rootSelection ()->getIncludedDirsByDir ());
49
+ }
50
+
51
+ public function testExcludeRootDirsById () {
52
+ $ builder = $ this ->builder ();
53
+ $ builder ->excludeRootDirs ($ this ->rootDir ()->id ());
54
+ $ this ->assertEquals (array (
55
+ $ this ->rootDir ()->id ()
56
+ ), $ builder ->rootSelection ()->getExcludedDirsById ());
57
+ }
58
+ public function testExcludeRootDirsByArrayOfRootDirs () {
59
+ $ builder = $ this ->builder ();
60
+ $ builder ->excludeRootDirs (array ($ this ->rootDir ()));
61
+ $ this ->assertEquals (array (
62
+ $ this ->rootDir ()
63
+ ), $ builder ->rootSelection ()->getExcludedDirsByDir ());
64
+ }
65
+
66
+ public function testIncludeChildDirsById () {
67
+ $ builder = $ this ->builder ();
68
+ $ builder ->includeChildDirs ($ this ->childDir ()->id ());
69
+ $ this ->assertEquals (array (
70
+ $ this ->childDir ()->id ()
71
+ ), $ builder ->childSelection ()->getIncludedDirsById ());
72
+ }
73
+ public function testIncludeChildDirsByArrayOfRootDirs () {
74
+ $ builder = $ this ->builder ();
75
+ $ builder ->includeChildDirs (array ($ this ->childDir ()));
76
+ $ this ->assertEquals (array (
77
+ $ this ->childDir ()
78
+ ), $ builder ->childSelection ()->getIncludedDirsByDir ());
79
+ }
80
+
81
+ public function testExcludeChildDirsById () {
82
+ $ builder = $ this ->builder ();
83
+ $ builder ->excludeChildDirs ($ this ->childDir ()->id ());
84
+ $ this ->assertEquals (array (
85
+ $ this ->childDir ()->id ()
86
+ ), $ builder ->childSelection ()->getExcludedDirsById ());
87
+ }
88
+ public function testExcludeChildDirsByArrayOfRootDirs () {
89
+ $ builder = $ this ->builder ();
90
+ $ builder ->excludeChildDirs (array ($ this ->childDir ()));
91
+ $ this ->assertEquals (array (
92
+ $ this ->childDir ()
93
+ ), $ builder ->childSelection ()->getExcludedDirsByDir ());
94
+ }
95
+
96
+ public function testAddDirSelectionByUnknownType () {
97
+ $ this ->setExpectedException ('FQ\Exceptions\FileQueryBuilderException ' , 'Add type of "non-existing-type" not found. ' );
98
+ $ this ->callNonPublicMethod ('_addToDirSelection ' , array ('non-existing-type ' , new DirSelection (), $ this ->rootDir ()));
99
+ }
100
+
101
+ public function testAddRequirement () {
102
+ $ builder = $ this ->builder ();
103
+ $ builder ->addRequirement (FilesQueryRequirements::LEVELS_ONE );
104
+ $ this ->assertEquals (array (
105
+ FilesQueryRequirements::LEVELS_ONE
106
+ ), $ this ->callNonPublicMethod ('_getRequirements ' ));
107
+ }
108
+
109
+ public function testReverse () {
110
+ $ builder = $ this ->builder ();
111
+ $ this ->assertFalse ($ this ->callNonPublicMethod ('_isReversed ' ));
112
+
113
+ $ builder ->reverse (true );
114
+ $ this ->assertTrue ($ this ->callNonPublicMethod ('_isReversed ' ));
115
+
116
+ $ builder ->reverse (false );
117
+ $ this ->assertFalse ($ this ->callNonPublicMethod ('_isReversed ' ));
118
+ }
119
+
120
+ public function testFilter () {
121
+ $ builder = $ this ->builder ();
122
+ $ this ->assertNull ($ this ->callNonPublicMethod ('_getFilters ' ));
123
+
124
+ $ builder ->filters (array ());
125
+ $ this ->assertEquals (array (), $ this ->callNonPublicMethod ('_getFilters ' ));
126
+
127
+ $ builder ->filters (FilesQuery::FILTER_EXISTING );
128
+ $ this ->assertEquals (FilesQuery::FILTER_EXISTING , $ this ->callNonPublicMethod ('_getFilters ' ));
129
+
130
+ $ builder ->filters (array (FilesQuery::FILTER_EXISTING ));
131
+ $ this ->assertEquals (array (
132
+ FilesQuery::FILTER_EXISTING
133
+ ), $ this ->callNonPublicMethod ('_getFilters ' ));
134
+ }
135
+
136
+ public function testRunBasicBuilderWithoutAFileName () {
137
+ $ this ->setExpectedException ('FQ\Exceptions\FileQueryBuilderException ' , 'No filename has been set. Use filename() to use a filename for the query or supply it this this run() method ' );
138
+ $ builder = $ this ->builder ();
139
+ $ builder ->run ();
140
+ }
141
+ public function testRunBasicBuilder () {
142
+ $ builder = $ this ->builder ();
143
+ $ query = $ builder ->run ('File2 ' );
144
+ $ this ->assertEquals (array (
145
+ self ::ROOT_DIR_DEFAULT_ID => self ::ROOT_DIR_DEFAULT_ABSOLUTE_PATH . '/child1/File2.php '
146
+ ), $ query ->listPaths ());
147
+ }
148
+ public function testRunBasicBuilderWithFilter () {
149
+ $ files = $ this ->files ();
150
+ $ files ->addRootDir ($ this ->_newActualRootDirSecond ());
151
+ $ builder = $ this ->builder ();
152
+ $ builder ->filters (FilesQuery::FILTER_EXISTING );
153
+ $ query = $ builder ->run ('File1 ' );
154
+ $ this ->assertEquals (array (
155
+ self ::ROOT_DIR_DEFAULT_ID => self ::ROOT_DIR_DEFAULT_ABSOLUTE_PATH . '/child1/File1.php ' ,
156
+ self ::ROOT_DIR_SECOND_ID => self ::ROOT_DIR_SECOND_ABSOLUTE_PATH . '/child1/File1.php '
157
+ ), $ query ->listPaths ());
158
+ }
159
+ public function testRunBasicBuilderWithFileNameProvidedByMethod () {
160
+ $ builder = $ this ->builder ();
161
+ $ builder ->fileName ('File1 ' );
162
+ $ query = $ builder ->run ();
163
+ $ this ->assertEquals (array (
164
+ self ::ROOT_DIR_DEFAULT_ID => self ::ROOT_DIR_DEFAULT_ABSOLUTE_PATH . '/child1/File1.php '
165
+ ), $ query ->listPaths ());
166
+ }
167
+ }
0 commit comments