Skip to content

Commit 2085ac4

Browse files
harm-lessharm-less
authored andcommitted
FilesQueryChild tests are all done
1 parent a0bb906 commit 2085ac4

File tree

5 files changed

+123
-11
lines changed

5 files changed

+123
-11
lines changed

src/FQ/query/FilesQuery.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class FilesQuery {
6969
/**
7070
* Constants determining preliminary filters types
7171
*/
72-
const FILTER_NONE = 'filter_none';
7372
const FILTER_EXISTING = 'filter_existing';
7473

7574
/**

src/FQ/query/FilesQueryChild.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,6 @@ private function _cachedFilterPaths() {
259259
foreach ($rootDirs as $rootDir) {
260260
$rootDirId = $rootDir->id();
261261
switch ($filter) {
262-
case FilesQuery::FILTER_NONE :
263-
$filteredPaths[$filter][$rootDirId] = true;
264-
break;
265262
case FilesQuery::FILTER_EXISTING :
266263
$filteredPaths[$filter][$rootDirId] = $pathsExist[$rootDirId];
267264
break;

tests/FQ/Tests/AbstractFQTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,17 @@ abstract class AbstractFQTest extends PHPUnit_Framework_TestCase
2929

3030
const ROOT_DIR_DEFAULT_ID = ACTUAL_ROOT_DIR_FIRST_ID;
3131
const ROOT_DIR_DEFAULT_ABSOLUTE_PATH = ACTUAL_ROOT_DIR_FIRST_ABSOLUTE_PATH;
32+
const ROOT_DIR_DEFAULT_BASE_PATH = 'http://www.basepath.com';
3233
const ROOT_DIR_SECOND_ID = ACTUAL_ROOT_DIR_SECOND_ID;
3334
const ROOT_DIR_SECOND_ABSOLUTE_PATH = ACTUAL_ROOT_DIR_SECOND_ABSOLUTE_PATH;
35+
const ROOT_DIR_SECOND_BASE_PATH = 'http://www.basepath2.com';
36+
37+
const ROOT_DIR_FICTITIOUS_ID = 'does-not-exist-id';
38+
const ROOT_DIR_FICTITIOUS_ABSOLUTE_PATH = 'abs-path-does-not-exist';
39+
const ROOT_DIR_FICTITIOUS_BASE_PATH = 'base-path-does-not-exist';
40+
41+
const CHILD_DIR_FICTITIOUS_ID = 'does-not-exist-id';
42+
const CHILD_DIR_FICTITIOUS_DIR = 'does-not-exist-dir';
3443

3544
const ROOT_DIR_ID_CUSTOM = 'rootDir';
3645
const CHILD_DIR_DEFAULT = ACTUAL_CHILD_DIR;
@@ -85,14 +94,14 @@ protected function _newFictitiousDir($required = true) {
8594
protected function __newRootDir($id = self::ROOT_DIR_ID_CUSTOM, $absoluteDir = self::ROOT_DIR_DEFAULT_ABSOLUTE_PATH, $basePath = null, $required = false) {
8695
return new RootDir($id, $absoluteDir, $basePath, $required);
8796
}
88-
protected function _newActualRootDir($basePath = null, $required = false) {
97+
protected function _newActualRootDir($basePath = self::ROOT_DIR_DEFAULT_BASE_PATH, $required = false) {
8998
return $this->__newRootDir(self::ROOT_DIR_DEFAULT_ID, self::ROOT_DIR_DEFAULT_ABSOLUTE_PATH, $basePath, $required);
9099
}
91-
protected function _newActualRootDirSecond($basePath = null, $required = false) {
100+
protected function _newActualRootDirSecond($basePath = self::ROOT_DIR_SECOND_BASE_PATH, $required = false) {
92101
return $this->__newRootDir(self::ROOT_DIR_SECOND_ID, self::ROOT_DIR_SECOND_ABSOLUTE_PATH, $basePath, $required);
93102
}
94103
protected function _newFictitiousRootDir($required = true) {
95-
return $this->__newRootDir('does_not_exist', 'does_not_exist', $required);
104+
return $this->__newRootDir(self::ROOT_DIR_FICTITIOUS_ID, self::ROOT_DIR_FICTITIOUS_ABSOLUTE_PATH, self::ROOT_DIR_FICTITIOUS_BASE_PATH, $required);
96105
}
97106

98107
protected function __newChildDir($id = self::CHILD_DIR_DEFAULT, $relativePathFromRootDirs = self::CHILD_DIR_DEFAULT, $required = false) {
@@ -102,6 +111,6 @@ protected function _newActualChildDir($required = true) {
102111
return $this->__newChildDir(self::CHILD_DIR_DEFAULT, self::CHILD_DIR_DEFAULT, $required);
103112
}
104113
protected function _newFictitiousChildDir($required = false) {
105-
return $this->__newChildDir('does_not_exist', 'does_not_exist', $required);
114+
return $this->__newChildDir(self::CHILD_DIR_FICTITIOUS_ID, self::CHILD_DIR_FICTITIOUS_DIR, $required);
106115
}
107116
}

tests/FQ/Tests/Dirs/RootDirTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ public function testCreateNewRootDir()
1616

1717
public function testBasePathConstructor() {
1818
$rootDir = $this->_newActualRootDir();
19-
$this->assertEquals(self::ROOT_DIR_DEFAULT_ABSOLUTE_PATH, $rootDir->basePath());
19+
$this->assertEquals(self::ROOT_DIR_DEFAULT_BASE_PATH, $rootDir->basePath());
2020
}
2121

2222
public function testBasePathDefault() {
2323
$rootDir = $this->_newActualRootDir();
24-
$this->assertEquals(self::ROOT_DIR_DEFAULT_ABSOLUTE_PATH, $rootDir->basePath());
24+
$this->assertEquals(self::ROOT_DIR_DEFAULT_BASE_PATH, $rootDir->basePath());
2525
}
2626

2727
public function testBasePathCustom() {

tests/FQ/Tests/Query/FilesQueryChildTest.php

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace FQ\Tests\Query;
44

5+
use FQ\Query\FilesQuery;
56
use FQ\Query\FilesQueryChild;
67
use FQ\Query\FilesQueryRequirements;
78

@@ -42,16 +43,122 @@ public function testGetRootDirsEmpty() {
4243

4344
public function testQuery() {
4445
$queryChild = $this->queryChild();
46+
$this->assertNotNull($queryChild->query());
4547
$this->assertTrue(is_a($queryChild->query(), 'FQ\Query\FilesQuery'));
4648
}
4749

4850
public function testFiles() {
4951
$queryChild = $this->queryChild();
50-
$this->assertTrue(is_a($queryChild->Files(), 'FQ\Files'));
52+
$this->assertNotNull($queryChild->files());
53+
$this->assertTrue(is_a($queryChild->files(), 'FQ\Files'));
5154
}
5255

5356
public function testChildDir() {
5457
$queryChild = $this->queryChild();
58+
$this->assertNotNull($queryChild->childDir());
5559
$this->assertTrue(is_a($queryChild->childDir(), 'FQ\Dirs\ChildDir'));
5660
}
61+
62+
public function testRelativePath() {
63+
$queryChild = $this->queryChild();
64+
$this->runQuery();
65+
$this->assertEquals('/child1/File2.php', $queryChild->relativePath());
66+
}
67+
public function testRelativePathWithCustomExtension() {
68+
$queryChild = $this->queryChild();
69+
$this->runQuery('File2.ext');
70+
$this->assertEquals('/child1/File2.ext', $queryChild->relativePath());
71+
}
72+
public function testRawAbsolutePath() {
73+
$queryChild = $this->queryChild();
74+
$this->runQuery();
75+
$this->assertEquals(array(
76+
self::ROOT_DIR_DEFAULT_ID => self::ROOT_DIR_DEFAULT_ABSOLUTE_PATH . '/child1/File2.php'
77+
), $queryChild->rawAbsolutePaths());
78+
}
79+
public function testBaseAbsolutePath() {
80+
$queryChild = $this->queryChild();
81+
$this->runQuery();
82+
$this->assertEquals(array(
83+
self::ROOT_DIR_DEFAULT_ID => self::ROOT_DIR_DEFAULT_BASE_PATH . '/child1/File2.php'
84+
), $queryChild->rawBasePaths());
85+
}
86+
87+
public function testGeneratePaths() {
88+
$this->setExpectedException('\FQ\Exceptions\FileQueryException', 'Cannot generate paths because method (non-existing-dir-method) is not defined in FQ\Dirs\RootDir');
89+
$this->runQuery();
90+
$this->callNonPublicMethod('_generatePaths', array('non-existing-dir-method'));
91+
}
92+
93+
public function testFilteredAbsolutePathsWithoutFilters() {
94+
$this->query()->filters(array(), false);
95+
$queryChild = $this->queryChild();
96+
$firstRootDir = $this->_newActualRootDir();
97+
$secondRootDir = $this->_newActualRootDirSecond();
98+
$queryChild->setRootDirs(array($firstRootDir, $secondRootDir));
99+
$this->runQuery();
100+
$this->assertEquals(array(
101+
self::ROOT_DIR_DEFAULT_ID => self::ROOT_DIR_DEFAULT_ABSOLUTE_PATH . '/child1/File2.php',
102+
self::ROOT_DIR_SECOND_ID => self::ROOT_DIR_SECOND_ABSOLUTE_PATH . '/child1/File2.php'
103+
), $queryChild->filteredAbsolutePaths());
104+
}
105+
public function testFilteredAbsolutePathsWithOneNonExistingFile() {
106+
$query = $this->query();
107+
$queryChild = $this->queryChild();
108+
$query->filters(FilesQuery::FILTER_EXISTING);
109+
$firstRootDir = $this->_newActualRootDir();
110+
$secondRootDir = $this->_newActualRootDirSecond();
111+
$thirdFictitiousDir = $this->_newFictitiousRootDir();
112+
$queryChild->setRootDirs(array($firstRootDir, $secondRootDir, $thirdFictitiousDir));
113+
$this->runQuery('File1');
114+
$this->assertEquals(array(
115+
self::ROOT_DIR_DEFAULT_ID => self::ROOT_DIR_DEFAULT_ABSOLUTE_PATH . '/child1/File1.php',
116+
self::ROOT_DIR_SECOND_ID => self::ROOT_DIR_SECOND_ABSOLUTE_PATH . '/child1/File1.php',
117+
self::ROOT_DIR_FICTITIOUS_ID => self::ROOT_DIR_FICTITIOUS_ABSOLUTE_PATH . '/child1/File1.php'
118+
), $queryChild->rawAbsolutePaths());
119+
$this->assertEquals(array(
120+
self::ROOT_DIR_DEFAULT_ID => self::ROOT_DIR_DEFAULT_ABSOLUTE_PATH . '/child1/File1.php',
121+
self::ROOT_DIR_SECOND_ID => self::ROOT_DIR_SECOND_ABSOLUTE_PATH . '/child1/File1.php'
122+
), $queryChild->filteredAbsolutePaths());
123+
}
124+
125+
public function testFilteredBasePathsWithoutFilters() {
126+
$this->query()->filters(array(), false);
127+
$queryChild = $this->queryChild();
128+
$firstRootDir = $this->_newActualRootDir();
129+
$secondRootDir = $this->_newActualRootDirSecond();
130+
$queryChild->setRootDirs(array($firstRootDir, $secondRootDir));
131+
$this->runQuery();
132+
$this->assertEquals(array(
133+
self::ROOT_DIR_DEFAULT_ID => self::ROOT_DIR_DEFAULT_BASE_PATH . '/child1/File2.php',
134+
self::ROOT_DIR_SECOND_ID => self::ROOT_DIR_SECOND_BASE_PATH . '/child1/File2.php'
135+
), $queryChild->filteredBasePaths());
136+
}
137+
public function testFilteredBasePathsWithOneNonExistingFile() {
138+
$query = $this->query();
139+
$queryChild = $this->queryChild();
140+
$query->filters(FilesQuery::FILTER_EXISTING);
141+
$firstRootDir = $this->_newActualRootDir();
142+
$secondRootDir = $this->_newActualRootDirSecond();
143+
$thirdFictitiousDir = $this->_newFictitiousRootDir();
144+
$queryChild->setRootDirs(array($firstRootDir, $secondRootDir, $thirdFictitiousDir));
145+
$this->runQuery('File1');
146+
$this->assertEquals(array(
147+
self::ROOT_DIR_DEFAULT_ID => self::ROOT_DIR_DEFAULT_BASE_PATH . '/child1/File1.php',
148+
self::ROOT_DIR_SECOND_ID => self::ROOT_DIR_SECOND_BASE_PATH . '/child1/File1.php',
149+
self::ROOT_DIR_FICTITIOUS_ID => self::ROOT_DIR_FICTITIOUS_BASE_PATH . '/child1/File1.php'
150+
), $queryChild->rawBasePaths());
151+
$this->assertEquals(array(
152+
self::ROOT_DIR_DEFAULT_ID => self::ROOT_DIR_DEFAULT_BASE_PATH . '/child1/File1.php',
153+
self::ROOT_DIR_SECOND_ID => self::ROOT_DIR_SECOND_BASE_PATH . '/child1/File1.php'
154+
), $queryChild->filteredBasePaths());
155+
}
156+
157+
/*public function testResetAfterQuery() {
158+
$queryChild = $this->queryChild();
159+
$this->runQuery();
160+
$this->assertEquals(array(
161+
self::ROOT_DIR_DEFAULT_ID => self::ROOT_DIR_DEFAULT_BASE_PATH . '/child1/File2.php'
162+
), $queryChild->rawBasePaths());
163+
}*/
57164
}

0 commit comments

Comments
 (0)