コード例 #1
1
ファイル: FileTest.php プロジェクト: justin-robinson/scoop
 public function test_delete_directory()
 {
     $fileName = getcwd() . DIRECTORY_SEPARATOR . microtime();
     // delete a file that doesn't exist
     $this->assertTrue(File::delete_directory($fileName), "deleting a file that doesn't exist should return true");
     // delete a file that does exist
     if (file_put_contents($fileName, 'something') !== false) {
         $this->assertTrue(File::delete_directory($fileName), "deleting a file that exist should return true");
         $this->assertFalse(file_exists($fileName), "file should not exist after deleting");
     }
     if (mkdir($fileName, 0777, true)) {
         foreach (range(0, 2) as $i) {
             file_put_contents($fileName . DIRECTORY_SEPARATOR . $i, $i);
         }
         $this->assertTrue(File::delete_directory($fileName), "deleting a directory should return true");
         $this->assertFalse(file_exists($fileName), "directory should not exist after deleting");
     }
 }
コード例 #2
0
ファイル: ConfigTest.php プロジェクト: justin-robinson/scoop
 public function test_get_db_config()
 {
     // base db config
     $expected = (require __DIR__ . "/../configs/db.php");
     $this->assertEquals($expected, Config::get_db_config());
     // site db config
     if (Config::option_exists('server_document_root')) {
         $docRoot = Config::get_option('server_document_root');
     }
     // set up a fake site document root
     Config::set_option('server_document_root', getcwd() . '/' . time());
     // get the expected config file path
     $siteDbConfigPath = Config::get_site_db_config_path();
     // create the expected config file path
     if (mkdir(Config::get_site_class_path(), 0777, true) && mkdir(dirname($siteDbConfigPath), 0777, true)) {
         // the site db config values
         $siteDbConfig = ['host' => 'new.host', 'user' => 'new.user'];
         // create the php code for the site config file
         $contents = '<?php return ' . var_export($siteDbConfig, true) . ';';
         // write the config to file
         $bytesWritten = file_put_contents($siteDbConfigPath, $contents, true);
         if ($bytesWritten !== false) {
             // reload global db config in hopes site values have overridden global ones
             $dbConfig = Config::get_db_config();
             // check that site db config values are there
             foreach ($siteDbConfig as $key => $value) {
                 $this->assertEquals($value, $dbConfig[$key], "options in site db config should override the global db config");
             }
             // check values not in site db config are still loaded from global config
             foreach ($expected as $key => $value) {
                 if (!array_key_exists($key, $siteDbConfig)) {
                     $this->assertEquals($value, $dbConfig[$key], "options not in site db config should be loaded from the global config");
                 }
             }
         }
     }
     // delete our tmp site doc root
     \Scoop\File::delete_directory(Config::get_option('server_document_root'));
     // set config values back to what they were
     if (isset($docRoot)) {
         Config::set_option('server_document_root', $docRoot);
     } else {
         Config::unset_option('server_document_root');
     }
 }
コード例 #3
0
 /**
  * @return int
  *
  * @throws \Exception
  */
 public function save()
 {
     // ensure path to output file exists
     File::create_path(dirname($this->filepath));
     // save file and set permissions
     $saved = file_put_contents($this->filepath, $this->get_file_contents());
     if ($saved) {
         chmod($this->filepath, 0777);
     }
     return $saved;
 }
コード例 #4
0
 public function test_save()
 {
     $filePath = '/tmp/scoopTests/testClass.php';
     $dirname = dirname($filePath);
     $generator = new ClassGenGenerator($this->class, $filePath);
     \Scoop\File::delete_directory($dirname);
     $generator->save();
     $this->assertFileExists($filePath, "saving a class generator should write to the file system");
     \Scoop\File::delete_directory($dirname);
 }