public function testCheckFailureMultipleUnwritableDirs()
 {
     $root = vfsStream::setup();
     $unwritableDir1 = vfsStream::newDirectory('unwritabledir1', 00)->at($root);
     $unwritableDir2 = vfsStream::newDirectory('unwritabledir2', 00)->at($root);
     $object = new DirWritable(array($unwritableDir1->url(), $unwritableDir2->url()));
     $r = $object->check();
     $this->assertInstanceOf('ZendDiagnostics\\Result\\Failure', $r);
     $this->assertEquals('The following directories are not writable: vfs://root/unwritabledir1, vfs://root/unwritabledir2.', $r->getMessage());
 }
 /**
  * Covers the specific diagnostic checks for the module.
  *
  * @return array
  */
 public function getDiagnostics()
 {
     return array('Cache & Log Directories Available' => function () {
         $diagnostic = new DirWritable(array(__DIR__ . '/../../data/cache', __DIR__ . '/../../data/log'));
         return $diagnostic->check();
     }, 'Check PHP extensions' => function () {
         $diagnostic = new ExtensionLoaded(array('json', 'pdo', 'pdo_pgsql', 'intl', 'session', 'pcre', 'zlib', 'Zend OPcache'));
         return $diagnostic->check();
     }, 'Check Apache is running' => function () {
         $diagnostic = new ProcessRunning('apache2');
         return $diagnostic->check();
     }, 'Check PostgreSQL is running' => function () {
         $diagnostic = new ProcessRunning('postgresql');
         return $diagnostic->check();
     }, 'Check Memcached is running' => function () {
         $diagnostic = new ProcessRunning('beanstalkd');
         return $diagnostic->check();
     }, 'Check PHP Version' => function () {
         $diagnostic = new PhpVersion('5.3.0', '>=');
         return $diagnostic->check();
     });
 }
 public function testDirWritable()
 {
     // single non-existent dir
     $path = __DIR__ . '/simprobabledir999999999999';
     $check = new DirWritable($path);
     $result = $check->check();
     $this->assertInstanceOf('ZendDiagnostics\\Result\\Failure', $result, 'Non-existent path');
     $this->assertStringMatchesFormat($path . '%s', $result->getMessage());
     // non-dir path
     $path = __FILE__;
     $check = new DirWritable($path);
     $result = $check->check();
     $this->assertInstanceOf('ZendDiagnostics\\Result\\Failure', $result, 'Non-dir path');
     $this->assertStringMatchesFormat($path . '%s', $result->getMessage());
     // multiple non-dir paths
     $path1 = __FILE__;
     $path2 = __DIR__ . '/BasicClassesTest.php';
     $check = new DirWritable(array($path1, $path2));
     $result = $check->check();
     $this->assertInstanceOf('ZendDiagnostics\\Result\\Failure', $result, 'Non-dir path');
     $this->assertStringMatchesFormat('%s' . $path1 . '%s', $result->getMessage());
     $this->assertStringMatchesFormat('%s' . $path2, $result->getMessage());
     // create a barrage of unwritable directories
     $tmpDir = sys_get_temp_dir();
     if (!is_dir($tmpDir) || !is_writable($tmpDir)) {
         $this->markTestSkipped('Cannot access writable system temp dir to perform the test... ');
         return;
     }
     // this should succeed
     $check = new DirWritable($tmpDir);
     $result = $check->check();
     $this->assertInstanceOf('ZendDiagnostics\\Result\\Success', $result, 'Single writable dir');
     // generate a random dir name
     while (($dir1 = $tmpDir . '/test' . mt_rand(1, PHP_INT_MAX)) && file_exists($dir1)) {
     }
     while (($dir2 = $tmpDir . '/test' . mt_rand(1, PHP_INT_MAX)) && file_exists($dir2)) {
     }
     // create temporary writable directories
     if (!mkdir($dir1) || !mkdir($dir2)) {
         $this->markTestSkipped('Cannot create unreadable temporary directory to perform the test... ');
         return;
     }
     // we should now have 3 writable directories
     $check = new DirWritable(array($tmpDir, $dir1, $dir2));
     $result = $check->check();
     $this->assertInstanceOf('ZendDiagnostics\\Result\\Success', $result, 'Multiple writable dirs');
     // make temporary dirs unwritable
     if (!chmod($dir1, 00) || !chmod($dir2, 00)) {
         $this->markTestSkipped('Cannot create unreadable temporary directory to perform the test... ');
         return;
     }
     // single unwritable dir
     $check = new DirWritable($dir1);
     $result = $check->check();
     $this->assertInstanceOf('ZendDiagnostics\\Result\\Failure', $result);
     $this->assertStringMatchesFormat($dir1 . '%s', $result->getMessage());
     // this should now fail
     $check = new DirWritable(array($dir1, $dir2, $tmpDir, __DIR__ . '/simprobabledir999999999999'));
     $result = $check->check();
     $this->assertInstanceOf('ZendDiagnostics\\Result\\Failure', $result);
     $this->assertStringMatchesFormat('%s' . $dir1 . '%s', $result->getMessage());
     $this->assertStringMatchesFormat('%s' . $dir2 . '%s', $result->getMessage());
     $this->assertStringMatchesFormat('%simprobabledir999999999999', $result->getMessage());
     chmod($dir1, 0777);
     chmod($dir2, 0777);
     rmdir($dir1);
     rmdir($dir2);
 }