1+ <?php
2+
3+ namespace ZendDiagnosticsTest ;
4+ use org \bovigo \vfs \vfsStream ;
5+ use ZendDiagnostics \Check \DirWritable ;
6+
7+ class DirWritableTest extends \PHPUnit_Framework_TestCase
8+ {
9+ /**
10+ * @var string
11+ */
12+ private $ checkClass = 'ZendDiagnostics\Check\DirWritable ' ;
13+
14+ /**
15+ * @test
16+ */
17+ public function shouldImplementCheckInterface ()
18+ {
19+ $ this ->assertInstanceOf (
20+ 'ZendDiagnostics\Check\CheckInterface ' ,
21+ $ this ->prophesize ($ this ->checkClass )->reveal ()
22+ );
23+ }
24+
25+ /**
26+ * @dataProvider providerValidConstructorArguments
27+ */
28+ public function testConstructor ($ arguments )
29+ {
30+ $ object = new DirWritable ($ arguments );
31+ }
32+
33+ public function providerValidConstructorArguments ()
34+ {
35+ return array (
36+ array (__DIR__ ),
37+ array (vfsStream::setup ()->url ()),
38+ array (array (__DIR__ , vfsStream::setup ()->url ()))
39+ );
40+ }
41+
42+ public function testCheckSuccessSinglePath ()
43+ {
44+ $ object = new DirWritable (vfsStream::setup ()->url ());
45+ $ r = $ object ->check ();
46+ $ this ->assertInstanceOf ('ZendDiagnostics\Result\Success ' , $ r );
47+ $ this ->assertEquals ('The path is a writable directory. ' , $ r ->getMessage ());
48+ }
49+
50+ public function testCheckSuccessMultiplePaths ()
51+ {
52+ $ object = new DirWritable (array (__DIR__ , vfsStream::setup ()->url ()));
53+ $ r = $ object ->check ();
54+ $ this ->assertInstanceOf ('ZendDiagnostics\Result\Success ' , $ r );
55+ $ this ->assertEquals ('All paths are writable directories. ' , $ r ->getMessage ());
56+ }
57+
58+ public function testCheckFailureSingleInvalidDir ()
59+ {
60+ $ object = new DirWritable ('notadir ' );
61+ $ r = $ object ->check ();
62+ $ this ->assertInstanceOf ('ZendDiagnostics\Result\Failure ' , $ r );
63+ $ this ->assertContains ('notadir is not a valid directory. ' , $ r ->getMessage ());
64+ }
65+
66+ public function testCheckFailureMultipleInvalidDirs ()
67+ {
68+ $ object = new DirWritable (array ('notadir1 ' , 'notadir2 ' ));
69+ $ r = $ object ->check ();
70+ $ this ->assertInstanceOf ('ZendDiagnostics\Result\Failure ' , $ r );
71+ $ this ->assertContains ('The following paths are not valid directories: notadir1, notadir2. ' , $ r ->getMessage ());
72+ }
73+
74+ public function testCheckFailureSingleUnwritableDir ()
75+ {
76+ $ root = vfsStream::setup ();
77+ $ unwritableDir = vfsStream::newDirectory ('unwritabledir ' , 000 )->at ($ root );
78+ $ object = new DirWritable ($ unwritableDir ->url ());
79+ $ r = $ object ->check ();
80+ $ this ->assertInstanceOf ('ZendDiagnostics\Result\Failure ' , $ r );
81+ $ this ->assertEquals ('vfs://root/unwritabledir directory is not writable. ' , $ r ->getMessage ());
82+ }
83+
84+ public function testCheckFailureMultipleUnwritableDirs ()
85+ {
86+ $ root = vfsStream::setup ();
87+ $ unwritableDir1 = vfsStream::newDirectory ('unwritabledir1 ' , 000 )->at ($ root );
88+ $ unwritableDir2 = vfsStream::newDirectory ('unwritabledir2 ' , 000 )->at ($ root );
89+
90+ $ object = new DirWritable (array ($ unwritableDir1 ->url (), $ unwritableDir2 ->url ()));
91+ $ r = $ object ->check ();
92+ $ this ->assertInstanceOf ('ZendDiagnostics\Result\Failure ' , $ r );
93+ $ this ->assertEquals ('The following directories are not writable: vfs://root/unwritabledir1, vfs://root/unwritabledir2. ' , $ r ->getMessage ());
94+ }
95+
96+ }
0 commit comments