15
15
16
16
class DirectoryResourceTest extends \PHPUnit_Framework_TestCase
17
17
{
18
- protected $ resource ;
19
18
protected $ directory ;
20
19
21
20
protected function setUp ()
@@ -25,7 +24,6 @@ protected function setUp()
25
24
mkdir ($ this ->directory );
26
25
}
27
26
touch ($ this ->directory .'/tmp.xml ' );
28
- $ this ->resource = new DirectoryResource ($ this ->directory );
29
27
}
30
28
31
29
protected function tearDown ()
@@ -56,16 +54,18 @@ protected function removeDirectory($directory) {
56
54
*/
57
55
public function testGetResource ()
58
56
{
59
- $ this ->assertEquals ($ this ->directory , $ this ->resource ->getResource (), '->getResource() returns the path to the resource ' );
57
+ $ resource = new DirectoryResource ($ this ->directory );
58
+ $ this ->assertEquals ($ this ->directory , $ resource ->getResource (), '->getResource() returns the path to the resource ' );
60
59
}
61
60
62
61
/**
63
62
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
64
63
*/
65
64
public function testIsFresh ()
66
65
{
67
- $ this ->assertTrue ($ this ->resource ->isFresh (time () + 10 ), '->isFresh() returns true if the resource has not changed ' );
68
- $ this ->assertFalse ($ this ->resource ->isFresh (time () - 86400 ), '->isFresh() returns false if the resource has been updated ' );
66
+ $ resource = new DirectoryResource ($ this ->directory );
67
+ $ this ->assertTrue ($ resource ->isFresh (time () + 10 ), '->isFresh() returns true if the resource has not changed ' );
68
+ $ this ->assertFalse ($ resource ->isFresh (time () - 86400 ), '->isFresh() returns false if the resource has been updated ' );
69
69
70
70
$ resource = new DirectoryResource ('/____foo/foobar ' .rand (1 , 999999 ));
71
71
$ this ->assertFalse ($ resource ->isFresh (time ()), '->isFresh() returns false if the resource does not exist ' );
@@ -76,35 +76,39 @@ public function testIsFresh()
76
76
*/
77
77
public function testIsFreshUpdateFile ()
78
78
{
79
+ $ resource = new DirectoryResource ($ this ->directory );
79
80
touch ($ this ->directory .'/tmp.xml ' , time () + 20 );
80
- $ this ->assertFalse ($ this -> resource ->isFresh (time () + 10 ), '->isFresh() returns false if an existing file is modified ' );
81
+ $ this ->assertFalse ($ resource ->isFresh (time () + 10 ), '->isFresh() returns false if an existing file is modified ' );
81
82
}
82
83
83
84
/**
84
85
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
85
86
*/
86
87
public function testIsFreshNewFile ()
87
88
{
89
+ $ resource = new DirectoryResource ($ this ->directory );
88
90
touch ($ this ->directory .'/new.xml ' , time () + 20 );
89
- $ this ->assertFalse ($ this -> resource ->isFresh (time () + 10 ), '->isFresh() returns false if a new file is added ' );
91
+ $ this ->assertFalse ($ resource ->isFresh (time () + 10 ), '->isFresh() returns false if a new file is added ' );
90
92
}
91
93
92
94
/**
93
95
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
94
96
*/
95
97
public function testIsFreshDeleteFile ()
96
98
{
99
+ $ resource = new DirectoryResource ($ this ->directory );
97
100
unlink ($ this ->directory .'/tmp.xml ' );
98
- $ this ->assertFalse ($ this -> resource ->isFresh (time ()), '->isFresh() returns false if an existing file is removed ' );
101
+ $ this ->assertFalse ($ resource ->isFresh (time ()), '->isFresh() returns false if an existing file is removed ' );
99
102
}
100
103
101
104
/**
102
105
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
103
106
*/
104
107
public function testIsFreshDeleteDirectory ()
105
108
{
109
+ $ resource = new DirectoryResource ($ this ->directory );
106
110
$ this ->removeDirectory ($ this ->directory );
107
- $ this ->assertFalse ($ this -> resource ->isFresh (time ()), '->isFresh() returns false if the whole resource is removed ' );
111
+ $ this ->assertFalse ($ resource ->isFresh (time ()), '->isFresh() returns false if the whole resource is removed ' );
108
112
}
109
113
110
114
/**
@@ -115,58 +119,46 @@ public function testIsFreshCreateFileInSubdirectory()
115
119
$ subdirectory = $ this ->directory .'/subdirectory ' ;
116
120
mkdir ($ subdirectory );
117
121
118
- $ this ->assertTrue ($ this ->resource ->isFresh (time () + 10 ), '->isFresh() returns true if an unmodified subdirectory exists ' );
122
+ $ resource = new DirectoryResource ($ this ->directory );
123
+ $ this ->assertTrue ($ resource ->isFresh (time () + 10 ), '->isFresh() returns true if an unmodified subdirectory exists ' );
119
124
120
125
touch ($ subdirectory .'/newfile.xml ' , time () + 20 );
121
- $ this ->assertFalse ($ this -> resource ->isFresh (time () + 10 ), '->isFresh() returns false if a new file in a subdirectory is added ' );
126
+ $ this ->assertFalse ($ resource ->isFresh (time () + 10 ), '->isFresh() returns false if a new file in a subdirectory is added ' );
122
127
}
123
128
124
129
/**
125
130
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
126
131
*/
127
132
public function testIsFreshModifySubdirectory ()
128
133
{
134
+ $ resource = new DirectoryResource ($ this ->directory );
135
+
129
136
$ subdirectory = $ this ->directory .'/subdirectory ' ;
130
137
mkdir ($ subdirectory );
131
-
132
138
touch ($ subdirectory , time () + 20 );
133
- $ this ->assertFalse ($ this ->resource ->isFresh (time () + 10 ), '->isFresh() returns false if a subdirectory is modified (e.g. a file gets deleted) ' );
134
- }
135
139
136
- /**
137
- * @covers Symfony\Component\Config\Resource\DirectoryResource::setFilterRegexList
138
- * @covers Symfony\Component\Config\Resource\DirectoryResource::getFilterRegexList
139
- */
140
- public function testSetFilterRegexList ()
141
- {
142
- $ regexes = array ('#\.foo$# ' , '#\.xml$# ' );
143
- $ this ->resource ->setFilterRegexList ($ regexes );
144
-
145
- $ this ->assertEquals ($ regexes , $ this ->resource ->getFilterRegexList (), '->getFilterRegexList() returns the previously defined list of filter regexes ' );
140
+ $ this ->assertFalse ($ resource ->isFresh (time () + 10 ), '->isFresh() returns false if a subdirectory is modified (e.g. a file gets deleted) ' );
146
141
}
147
142
148
143
/**
149
144
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
150
145
*/
151
146
public function testFilterRegexListNoMatch ()
152
147
{
153
- $ regexes = array ('#\.foo$# ' , '#\.xml$# ' );
154
- $ this ->resource ->setFilterRegexList ($ regexes );
148
+ $ resource = new DirectoryResource ($ this ->directory , '/\.(foo|xml)$/ ' );
155
149
156
150
touch ($ this ->directory .'/new.bar ' , time () + 20 );
157
- $ this ->assertTrue ($ this -> resource ->isFresh (time () + 10 ), '->isFresh() returns true if a new file not matching the filter regex is created ' );
151
+ $ this ->assertTrue ($ resource ->isFresh (time () + 10 ), '->isFresh() returns true if a new file not matching the filter regex is created ' );
158
152
}
159
153
160
154
/**
161
155
* @covers Symfony\Component\Config\Resource\DirectoryResource::isFresh
162
156
*/
163
157
public function testFilterRegexListMatch ()
164
158
{
165
- $ regexes = array ('#\.foo$# ' , '#\.xml$# ' );
166
- $ this ->resource ->setFilterRegexList ($ regexes );
159
+ $ resource = new DirectoryResource ($ this ->directory , '/\.(foo|xml)$/ ' );
167
160
168
161
touch ($ this ->directory .'/new.xml ' , time () + 20 );
169
- $ this ->assertFalse ($ this -> resource ->isFresh (time () + 10 ), '->isFresh() returns false if an new file matching the filter regex is created ' );
162
+ $ this ->assertFalse ($ resource ->isFresh (time () + 10 ), '->isFresh() returns false if an new file matching the filter regex is created ' );
170
163
}
171
-
172
164
}
0 commit comments