Before

…lines 1–34 unchanged (34 lines)
35 * @license BSD License
36 */
37
38namespace TheSeer\DirectoryScanner\Tests {
39
40 use TheSeer\DirectoryScanner\DirectoryScanner;
41
42 /**
43 * Unit tests for DirectoryScanner class
44 *
45 * @author Arne Blankerts <arne@blankerts.de>
46 * @copyright Arne Blankerts <arne@blankerts.de>, All rights reserved.
47 */
48 class DirectoryScannerTest extends \PHPUnit_Framework_TestCase {
49
50 /**
51 * Test if enabling following symbolic links works.
52 *
53 */
54 public function testSetFollowSymlinks() {
55 $tmp = new DirectoryScanner();
56 $this->assertFalse($tmp->isFollowSymlinks());
57 $tmp->setFollowSymlinks(TRUE);
58 $this->assertTrue($tmp->isFollowSymlinks());
59 $tmp->setFollowSymlinks(FALSE);
60 $this->assertFalse($tmp->isFollowSymlinks());
61 }
62
63 /**
64 * Set the include to be matching for *.txt via setIncludes
65 *
66 */
67 public function testSetIncludes() {
68 $test = array('*.txt');
69 $tmp = new DirectoryScanner();
70 $tmp->setIncludes($test);
71 $this->assertEquals($test, $tmp->getIncludes());
72 }
73
74 /**
75 * Set an exclude match on *.txt
76 *
77 */
78 public function testSetExcludes() {
79 $test = array('*.txt');
80 $tmp = new DirectoryScanner();
81 $tmp->setExcludes($test);
82 $this->assertEquals($test, $tmp->getExcludes());
83 }
84
85 /**
86 * Adding multiple matches include matches individually
87 *
88 */
89 public function testAddInclude() {
90 $tmp = new DirectoryScanner();
91 $tmp->addInclude('*.txt');
92 $tmp->addInclude('*.xml');
93
94 $this->assertEquals(2, count($tmp->getIncludes()));
95 $this->assertEquals(array('*.txt','*.xml'), $tmp->getIncludes());
96 }
97
98 /**
99 * Adding multiple exclude maches individually
100 *
101 */
102 public function testAddExclude() {
103 $tmp = new DirectoryScanner();
104 $tmp->addExclude('*.txt');
105 $tmp->addExclude('*.xml');
106
107 $this->assertEquals(array('*.txt','*.xml'), $tmp->getExcludes());
108 }
109
110 /**
111 * Trying to scan a non existend directory should throw an exception
112 *
113 * @expectedException \TheSeer\DirectoryScanner\Exception
114 */
115 public function testScanOfNonExistendPath() {
116 $tmp = new DirectoryScanner();
117 $tmp(__DIR__ . '/_data//not/existing');
118 }
119
120 /**
121 * Recursivly find all files within given test folder without any filter
122 */
123 public function testRecursiveFindAllFilesInFolder() {
124 $tmp = new DirectoryScanner();
125 $x = $tmp->getFiles(__DIR__ . '/_data');
126 $this->assertEquals(9, count($x));
127 }
128
129 /**
130 * Non-Recursivly find all files within given test folder without any filter
131 */
132 public function testNonRecursiveFindAllFilesInFolder() {
133 $tmp = new DirectoryScanner();
134 $x = $tmp->getFiles(__DIR__ . '/_data', false);
135 $this->assertEquals(3, count($x));
136 }
137
138 /**
139 * Recursivly find *.xml files within test folder
140 */
141 public function testRecursiveFindXMLFilesInFolder() {
142 $tmp = new DirectoryScanner();
143 $tmp->addInclude('*.xml');
144 $x = $tmp->getFiles(__DIR__ . '/_data');
145 $this->assertEquals(3, count($x));
146 }
147
148 /**
149 * Non-Recursivly find *.xml files within test folder
150 */
151 public function testNonRecursiveFindXMLFilesInFolder() {
152 $tmp = new DirectoryScanner();
153 $tmp->addInclude('*.xml');
154 $x = $tmp->getFiles(__DIR__ . '/_data', false);
155 $this->assertEquals(2, count($x));
156 }
157
158 /**
159 * Recursivly find all files, not matching *.xml
160 */
161 public function testRecursiveFindByExclude() {
162 $tmp = new DirectoryScanner();
163 $tmp->addExclude('*.xml');
164 $x = $tmp->getFiles(__DIR__ . '/_data');
165 $this->assertEquals(6, count($x));
166 }
167
168 /**
169 * Find all files matching *.txt and not being in 'nested' folder
170 */
171 public function testRecursiveFindByIncludeAndExclude() {
172 $tmp = new DirectoryScanner();
173 $tmp->addInclude('*.txt');
174 $tmp->addExclude('*/nested/*');
175 $x = $tmp->getFiles(__DIR__ . '/_data');
176 $this->assertEquals(1, count($x));
177 }
178
179 }
180
181}

After

…lines 1–34 unchanged (34 lines)
35 * @license BSD License
36 */
37
38namespace TheSeer\DirectoryScanner\Tests {
39
40 use TheSeer\DirectoryScanner\DirectoryScanner;
41
42 /**
43 * Unit tests for DirectoryScanner class
44 *
45 * @author Arne Blankerts <arne@blankerts.de>
46 * @copyright Arne Blankerts <arne@blankerts.de>, All rights reserved.
47 */
48 class DirectoryScannerTest extends \PHPUnit_Framework_TestCase {
49
50 /**
51 * Test if enabling following symbolic links works.
52 */
53 public function testSetFollowSymlinks() {
54 $tmp = new DirectoryScanner();
55 $this->assertFalse($tmp->isFollowSymlinks());
56 $tmp->setFollowSymlinks(TRUE);
57 $this->assertTrue($tmp->isFollowSymlinks());
58 $tmp->setFollowSymlinks(FALSE);
59 $this->assertFalse($tmp->isFollowSymlinks());
60 }
61
62 /**
63 * @expectedException \TheSeer\DirectoryScanner\Exception
64 * @expectedExceptionCode \TheSeer\DirectoryScanner\Exception::InvalidFlag
65 */
66 public function testSettingInvalidFlagThrowsException() {
67 $tmp = new DirectoryScanner();
68 $tmp->setFlag(-1);
69 }
70
71 /**
72 * @expectedException \TheSeer\DirectoryScanner\Exception
73 * @expectedExceptionCode \TheSeer\DirectoryScanner\Exception::InvalidFlag
74 */
75 public function testUnSettingInvalidFlagThrowsException() {
76 $tmp = new DirectoryScanner();
77 $tmp->unsetFlag(-1);
78 }
79
80 /**
81 * Set the include to be matching for *.txt via setIncludes
82 *
83 */
84 public function testSetIncludes() {
85 $test = array('*.txt');
86 $tmp = new DirectoryScanner();
87 $tmp->setIncludes($test);
88 $this->assertEquals($test, $tmp->getIncludes());
89 }
90
91 /**
92 * Set an exclude match on *.txt
93 *
94 */
95 public function testSetExcludes() {
96 $test = array('*.txt');
97 $tmp = new DirectoryScanner();
98 $tmp->setExcludes($test);
99 $this->assertEquals($test, $tmp->getExcludes());
100 }
101
102 /**
103 * Adding multiple matches include matches individually
104 *
105 */
106 public function testAddInclude() {
107 $tmp = new DirectoryScanner();
108 $tmp->addInclude('*.txt');
109 $tmp->addInclude('*.xml');
110
111 $this->assertEquals(2, count($tmp->getIncludes()));
112 $this->assertEquals(array('*.txt', '*.xml'), $tmp->getIncludes());
113 }
114
115 /**
116 * Adding multiple exclude maches individually
117 *
118 */
119 public function testAddExclude() {
120 $tmp = new DirectoryScanner();
121 $tmp->addExclude('*.txt');
122 $tmp->addExclude('*.xml');
123
124 $this->assertEquals(array('*.txt', '*.xml'), $tmp->getExcludes());
125 }
126
127 /**
128 * Trying to scan a non existend directory should throw an exception
129 *
130 * @expectedException \TheSeer\DirectoryScanner\Exception
131 */
132 public function testScanOfNonExistendPath() {
133 $tmp = new DirectoryScanner();
134 $tmp(__DIR__ . '/_data//not/existing');
135 }
136
137 /**
138 * Recursivly find all files within given test folder without any filter
139 */
140 public function testRecursiveFindAllFilesInFolder() {
141 $tmp = new DirectoryScanner();
142 $x = $tmp->getFiles(__DIR__ . '/_data');
143 $this->assertEquals(9, count($x));
144 }
145
146 /**
147 * Non-Recursivly find all files within given test folder without any filter
148 */
149 public function testNonRecursiveFindAllFilesInFolder() {
150 $tmp = new DirectoryScanner();
151 $x = $tmp->getFiles(__DIR__ . '/_data', FALSE);
152 $this->assertEquals(3, count($x));
153 }
154
155 /**
156 * Recursivly find *.xml files within test folder
157 */
158 public function testRecursiveFindXMLFilesInFolder() {
159 $tmp = new DirectoryScanner();
160 $tmp->addInclude('*.xml');
161 $x = $tmp->getFiles(__DIR__ . '/_data');
162 $this->assertEquals(3, count($x));
163 }
164
165 /**
166 * Non-Recursivly find *.xml files within test folder
167 */
168 public function testNonRecursiveFindXMLFilesInFolder() {
169 $tmp = new DirectoryScanner();
170 $tmp->addInclude('*.xml');
171 $x = $tmp->getFiles(__DIR__ . '/_data', FALSE);
172 $this->assertEquals(2, count($x));
173 }
174
175 /**
176 * Recursivly find all files, not matching *.xml
177 */
178 public function testRecursiveFindByExclude() {
179 $tmp = new DirectoryScanner();
180 $tmp->addExclude('*.xml');
181 $x = $tmp->getFiles(__DIR__ . '/_data');
182 $this->assertEquals(6, count($x));
183 }
184
185 /**
186 * Find all files matching *.txt and not being in 'nested' folder
187 */
188 public function testRecursiveFindByIncludeAndExclude() {
189 $tmp = new DirectoryScanner();
190 $tmp->addInclude('*.txt');
191 $tmp->addExclude('*/nested/*');
192 $x = $tmp->getFiles(__DIR__ . '/_data');
193 $this->assertEquals(1, count($x));
194 }
195
196 }
197
198}
199

Before

program
php_tag "<?php"
comment "/**\n * Copyright (c) 2009-2011 Arne Blankerts <arne@blankert"...
namespace_definition
namespace "namespace"
namespace_name
name "TheSeer"
\ "\\"
name "DirectoryScanner"
\ "\\"
name "Tests"
compound_statement
{ "{"
namespace_use_declaration
use "use"
namespace_use_clause
qualified_name
namespace_name
name "TheSeer"
\ "\\"
name "DirectoryScanner"
\ "\\"
name "DirectoryScanner"
; ";"
comment "/**\n * Unit tests for DirectoryScanner class\n *\n * "...
class_declaration
class "class"
name "DirectoryScannerTest"
base_clause
extends "extends"
qualified_name
\ "\\"
name "PHPUnit_Framework_TestCase"
declaration_list
{ "{"
comment "/**\n * Test if enabling following symbolic links works"...
method_declaration (+113 nodes collapsed)
comment "/**\n * Set the include to be matching for *.txt via se"...
method_declaration (+81 nodes collapsed)
comment "/**\n * Set an exclude match on *.txt\n *\n *"...
method_declaration (+81 nodes collapsed)
comment "/**\n * Adding multiple matches include matches individ"...
method_declaration (+124 nodes collapsed)
comment "/**\n * Adding multiple exclude maches individually\n "...
method_declaration (+94 nodes collapsed)
comment "/**\n * Trying to scan a non existend directory should "...
method_declaration (+41 nodes collapsed)
comment "/**\n * Recursivly find all files within given test fol"...
method_declaration (+72 nodes collapsed)
comment "/**\n * Non-Recursivly find all files within given test"...
method_declaration
visibility_modifier
public "public"
function "function"
name "testNonRecursiveFindAllFilesInFolder"
formal_parameters
( "("
) ")"
compound_statement
{ "{"
expression_statement
assignment_expression
variable_name
$ "$"
name "tmp"
= "="
object_creation_expression
new "new"
name "DirectoryScanner"
arguments
( "("
) ")"
; ";"
expression_statement
assignment_expression
variable_name
$ "$"
name "x"
= "="
member_call_expression
variable_name
$ "$"
name "tmp"
-> "->"
name "getFiles"
arguments
( "("
argument
binary_expression
name "__DIR__"
. "."
string
' "'"
string_content "/_data"
' "'"
, ","
argument
boolean "false"
) ")"
; ";"
expression_statement (+24 nodes collapsed)
} "}"
comment "/**\n * Recursivly find *.xml files within test folder\n"...
method_declaration (+88 nodes collapsed)
comment "/**\n * Non-Recursivly find *.xml files within test fol"...
method_declaration
visibility_modifier
public "public"
function "function"
name "testNonRecursiveFindXMLFilesInFolder"
formal_parameters
( "("
) ")"
compound_statement
{ "{"
expression_statement
assignment_expression
variable_name
$ "$"
name "tmp"
= "="
object_creation_expression
new "new"
name "DirectoryScanner"
arguments
( "("
) ")"
; ";"
expression_statement
member_call_expression
variable_name
$ "$"
name "tmp"
-> "->"
name "addInclude"
arguments
( "("
argument
string
' "'"
string_content "*.xml"
' "'"
) ")"
; ";"
expression_statement
assignment_expression
variable_name
$ "$"
name "x"
= "="
member_call_expression
variable_name
$ "$"
name "tmp"
-> "->"
name "getFiles"
arguments
( "("
argument
binary_expression
name "__DIR__"
. "."
string
' "'"
string_content "/_data"
' "'"
, ","
argument
boolean "false"
) ")"
; ";"
expression_statement (+24 nodes collapsed)
} "}"
comment "/**\n * Recursivly find all files, not matching *.xml\n "...
method_declaration (+88 nodes collapsed)
comment "/**\n * Find all files matching *.txt and not being in "...
method_declaration (+104 nodes collapsed)
} "}"
} "}"

After

program
php_tag "<?php"
comment "/**\n * Copyright (c) 2009-2011 Arne Blankerts <arne@blankert"...
namespace_definition
namespace "namespace"
namespace_name
name "TheSeer"
\ "\\"
name "DirectoryScanner"
\ "\\"
name "Tests"
compound_statement
{ "{"
namespace_use_declaration
use "use"
namespace_use_clause
qualified_name
namespace_name
name "TheSeer"
\ "\\"
name "DirectoryScanner"
\ "\\"
name "DirectoryScanner"
; ";"
comment "/**\n * Unit tests for DirectoryScanner class\n *\n "...
class_declaration
class "class"
name "DirectoryScannerTest"
base_clause
extends "extends"
qualified_name
\ "\\"
name "PHPUnit_Framework_TestCase"
declaration_list
{ "{"
comment "/**\n * Test if enabling following symbolic links wor"...
method_declaration (+113 nodes collapsed)
comment "/**\n * @expectedException \\TheSeer\\DirectoryScanner\\"...
method_declaration
visibility_modifier
public "public"
function "function"
name "testSettingInvalidFlagThrowsException"
formal_parameters
( "("
) ")"
compound_statement
{ "{"
expression_statement
assignment_expression
variable_name
$ "$"
name "tmp"
= "="
object_creation_expression
new "new"
name "DirectoryScanner"
arguments
( "("
) ")"
; ";"
expression_statement
member_call_expression
variable_name
$ "$"
name "tmp"
-> "->"
name "setFlag"
arguments
( "("
argument
unary_op_expression
- "-"
integer "1"
) ")"
; ";"
} "}"
comment "/**\n * @expectedException \\TheSeer\\DirectoryScanner\\"...
method_declaration
visibility_modifier
public "public"
function "function"
name "testUnSettingInvalidFlagThrowsException"
formal_parameters
( "("
) ")"
compound_statement
{ "{"
expression_statement
assignment_expression
variable_name
$ "$"
name "tmp"
= "="
object_creation_expression
new "new"
name "DirectoryScanner"
arguments
( "("
) ")"
; ";"
expression_statement
member_call_expression
variable_name
$ "$"
name "tmp"
-> "->"
name "unsetFlag"
arguments
( "("
argument
unary_op_expression
- "-"
integer "1"
) ")"
; ";"
} "}"
comment "/**\n * Set the include to be matching for *.txt via "...
method_declaration (+81 nodes collapsed)
comment "/**\n * Set an exclude match on *.txt\n *\n "...
method_declaration (+81 nodes collapsed)
comment "/**\n * Adding multiple matches include matches indiv"...
method_declaration (+124 nodes collapsed)
comment "/**\n * Adding multiple exclude maches individually\n "...
method_declaration (+94 nodes collapsed)
comment "/**\n * Trying to scan a non existend directory shoul"...
method_declaration (+41 nodes collapsed)
comment "/**\n * Recursivly find all files within given test f"...
method_declaration (+72 nodes collapsed)
comment "/**\n * Non-Recursivly find all files within given te"...
method_declaration
visibility_modifier
public "public"
function "function"
name "testNonRecursiveFindAllFilesInFolder"
formal_parameters
( "("
) ")"
compound_statement
{ "{"
expression_statement
assignment_expression
variable_name
$ "$"
name "tmp"
= "="
object_creation_expression
new "new"
name "DirectoryScanner"
arguments
( "("
) ")"
; ";"
expression_statement
assignment_expression
variable_name
$ "$"
name "x"
= "="
member_call_expression
variable_name
$ "$"
name "tmp"
-> "->"
name "getFiles"
arguments
( "("
argument
binary_expression
name "__DIR__"
. "."
string
' "'"
string_content "/_data"
' "'"
, ","
argument
boolean "FALSE"
) ")"
; ";"
expression_statement (+24 nodes collapsed)
} "}"
comment "/**\n * Recursivly find *.xml files within test folde"...
method_declaration (+88 nodes collapsed)
comment "/**\n * Non-Recursivly find *.xml files within test f"...
method_declaration
visibility_modifier
public "public"
function "function"
name "testNonRecursiveFindXMLFilesInFolder"
formal_parameters
( "("
) ")"
compound_statement
{ "{"
expression_statement
assignment_expression
variable_name
$ "$"
name "tmp"
= "="
object_creation_expression
new "new"
name "DirectoryScanner"
arguments
( "("
) ")"
; ";"
expression_statement
member_call_expression
variable_name
$ "$"
name "tmp"
-> "->"
name "addInclude"
arguments
( "("
argument
string
' "'"
string_content "*.xml"
' "'"
) ")"
; ";"
expression_statement
assignment_expression
variable_name
$ "$"
name "x"
= "="
member_call_expression
variable_name
$ "$"
name "tmp"
-> "->"
name "getFiles"
arguments
( "("
argument
binary_expression
name "__DIR__"
. "."
string
' "'"
string_content "/_data"
' "'"
, ","
argument
boolean "FALSE"
) ")"
; ";"
expression_statement (+24 nodes collapsed)
} "}"
comment "/**\n * Recursivly find all files, not matching *.xml"...
method_declaration (+88 nodes collapsed)
comment "/**\n * Find all files matching *.txt and not being i"...
method_declaration (+104 nodes collapsed)
} "}"
} "}"