@@ -10,21 +10,31 @@ class FileSelectorTest extends Orchestra\Testbench\TestCase {
10
10
11
11
protected $ disk ;
12
12
13
+ protected $ root ;
14
+
15
+ protected $ testFilesPath ;
16
+
13
17
protected $ fileSelector ;
14
18
15
19
public function setUp ()
16
20
{
17
21
parent ::setUp ();
18
- $ this ->path = realpath ('tests/_data/backups ' );
22
+
23
+ $ this ->root = realpath ('tests/_data/disk/root ' );
24
+
25
+ $ this ->path = 'backups ' ;
26
+
27
+ $ this ->testFilesPath = realpath ($ this ->root . '/ ' . $ this ->path );
19
28
20
29
//make sure all files in our testdirectory are 5 days old
21
- foreach (scandir ($ this ->path ) as $ file )
30
+ foreach (scandir ($ this ->testFilesPath ) as $ file )
22
31
{
23
- touch ($ this ->path . '/ ' . $ file , time () - (60 * 60 * 24 * 5 ));
32
+
33
+ touch ($ this ->testFilesPath . '/ ' . $ file , time () - (60 * 60 * 24 * 5 ));
24
34
}
25
35
26
- $ this ->disk = new Illuminate \Filesystem \FilesystemAdapter (new Filesystem (new Local ($ this ->path )));
27
- $ this ->fileSelector = new FileSelector ($ this ->disk );
36
+ $ this ->disk = new Illuminate \Filesystem \FilesystemAdapter (new Filesystem (new Local ($ this ->root )));
37
+ $ this ->fileSelector = new FileSelector ($ this ->disk , $ this -> path );
28
38
}
29
39
30
40
/**
@@ -56,17 +66,30 @@ public function it_gets_files_older_than_the_given_date()
56
66
{
57
67
$ testFileName = 'test_it_gets_files_older_than_the_given_date.zip ' ;
58
68
59
- touch ($ this ->path . '/ ' .$ testFileName , time () - (60 * 60 * 24 * 10 ) + 60 ); //create a file that is 10 days and a minute old
69
+ touch ($ this ->testFilesPath . '/ ' .$ testFileName , time () - (60 * 60 * 24 * 10 ) + 60 ); //create a file that is 10 days and a minute old
60
70
61
71
$ oldFiles = $ this ->fileSelector ->getFilesOlderThan ((new DateTime ())->sub (new DateInterval ('P9D ' )), ['zip ' ]);
62
- $ this ->assertTrue (in_array ($ testFileName , $ oldFiles ));
72
+
73
+ $ this ->assertTrue (in_array ($ this ->path .'/ ' .$ testFileName , $ oldFiles ));
63
74
64
75
$ oldFiles = $ this ->fileSelector ->getFilesOlderThan ((new DateTime ())->sub (new DateInterval ('P10D ' )), ['zip ' ]);
65
- $ this ->assertFalse (in_array ($ testFileName , $ oldFiles ));
76
+ $ this ->assertFalse (in_array ($ this -> path . ' / ' . $ testFileName , $ oldFiles ));
66
77
67
78
$ oldFiles = $ this ->fileSelector ->getFilesOlderThan ((new DateTime ())->sub (new DateInterval ('P11D ' )), ['zip ' ]);
68
- $ this ->assertFalse (in_array ($ testFileName , $ oldFiles ));
79
+ $ this ->assertFalse (in_array ($ this ->path .'/ ' .$ testFileName , $ oldFiles ));
80
+ }
81
+
82
+ /**
83
+ * @test
84
+ */
85
+ public function it_excludes_files_outside_given_path ()
86
+ {
87
+ $ files = $ this ->fileSelector ->getFilesOlderThan (new DateTime (), ['zip ' ]);
88
+
89
+ touch (realpath ('tests/_data/disk/root/TomJones.zip ' ), time () - (60 * 60 * 24 * 10 ) + 60 );
69
90
91
+ $ this ->assertFalse (in_array ($ this ->path . '/ ' . 'TomJones.zip ' , $ files ));
92
+ $ this ->assertTrue (in_array ($ this ->path . '/ ' . 'test.zip ' , $ files ));
70
93
}
71
94
72
95
/**
0 commit comments