Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 8e277c6

Browse files
committed
Merge pull request #65 from Headd2k/master
Fix typos in DirWriteable result descriptions, add DirWritable unit tests.
2 parents 2eeb413 + f79acc5 commit 8e277c6

File tree

4 files changed

+105
-9
lines changed

4 files changed

+105
-9
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"videlalvaro/php-amqplib" : "2.*",
2727
"predis/predis" : "0.8.*",
2828
"phpunit/phpunit" : "4.7.*",
29-
"doctrine/migrations" : "~1.0@dev"
29+
"doctrine/migrations" : "~1.0@dev",
30+
"mikey179/vfsStream" : "1.6.*"
3031
},
3132
"suggest" : {
3233
"ext-bcmath" : "Required by Check\\CpuPerformance",

src/ZendDiagnostics/Check/DirWritable.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct($path)
2828
{
2929
if (is_object($path) && !$path instanceof Traversable) {
3030
throw new InvalidArgumentException(
31-
'Expected a dir name (string) , an array or Traversable of strings, got ' . get_class($path)
31+
'Expected a dir name (string), an array or Traversable of strings, got ' . get_class($path)
3232
);
3333
}
3434

@@ -67,23 +67,23 @@ public function check()
6767
// Construct failure message
6868
$failureString = '';
6969
if (count($nonDirs) > 1) {
70-
$failureString .= 'The following paths are not valid directories: ' . join(', ', $nonDirs).' ';
70+
$failureString .= sprintf('The following paths are not valid directories: %s. ', join(', ', $nonDirs));
7171
} elseif (count($nonDirs) == 1) {
72-
$failureString .= current($nonDirs) . ' is not a valid directory. ';
72+
$failureString .= sprintf('%s is not a valid directory. ', current($nonDirs));
7373
}
7474

7575
if (count($unwritable) > 1) {
76-
$failureString .= 'The following directories are not writable: ' . join(', ', $unwritable);
76+
$failureString .= sprintf('The following directories are not writable: %s. ', join(', ', $unwritable));
7777
} elseif (count($unwritable) == 1) {
78-
$failureString .= current($unwritable) . ' directory is not writable.';
78+
$failureString .= sprintf('%s directory is not writable. ', current($unwritable));
7979
}
8080

8181
// Return success or failure
8282
if ($failureString) {
8383
return new Failure(trim($failureString), array('nonDirs' => $nonDirs, 'unwritable' => $unwritable));
8484
} else {
8585
return new Success(
86-
count($this->dir) > 1 ? 'All paths are writable directories.' : 'The path is a a writable directory.',
86+
count($this->dir) > 1 ? 'All paths are writable directories.' : 'The path is a writable directory.',
8787
$this->dir
8888
);
8989
}

tests/ZendDiagnosticsTest/ChecksTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public function testDirWritable()
392392
$result = $check->check();
393393
$this->assertInstanceOf('ZendDiagnostics\Result\Failure', $result, 'Non-dir path');
394394
$this->assertStringMatchesFormat('%s' . $path1 . '%s', $result->getMessage());
395-
$this->assertStringMatchesFormat('%s' . $path2, $result->getMessage());
395+
$this->assertStringMatchesFormat('%s' . $path2 . '%s', $result->getMessage());
396396

397397
// create a barrage of unwritable directories
398398
$tmpDir = sys_get_temp_dir();
@@ -453,7 +453,7 @@ public function testDirWritable()
453453
$this->assertInstanceOf('ZendDiagnostics\Result\Failure', $result);
454454
$this->assertStringMatchesFormat('%s' . $dir1 . '%s', $result->getMessage());
455455
$this->assertStringMatchesFormat('%s' . $dir2 . '%s', $result->getMessage());
456-
$this->assertStringMatchesFormat('%simprobabledir999999999999', $result->getMessage());
456+
$this->assertStringMatchesFormat('%simprobabledir999999999999%s', $result->getMessage());
457457

458458
chmod($dir1, 0777);
459459
chmod($dir2, 0777);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
namespace ZendDiagnosticsTest;
3+
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+
}

0 commit comments

Comments
 (0)