コード例 #1
0
ファイル: FileTest.php プロジェクト: coretyson/coretyson
 /**
  * testReplaceText method
  *
  * @return void
  */
 public function testReplaceText()
 {
     $TestFile = new File(TEST_ROOT . '/Fixture/FileTest.txt');
     $TmpFile = new File(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'cakephp.file.test.tmp', true);
     // Copy the test file to the temporary location
     $TestFile->copy($TmpFile->getPath(), true);
     // Replace the contents of the temporary file
     $result = $TmpFile->replaceText('welcome.php', 'welcome.tmp');
     $this->assertTrue($result);
     // Double check
     $expected = 'This is the welcome.tmp file in vendors directory';
     $contents = $TmpFile->read();
     $this->assertContains($expected, $contents);
     $search = ['This is the', 'welcome.php file', 'in tmp directory'];
     $replace = ['This should be a', 'welcome.tmp file', 'in the Lib directory'];
     // Replace the contents of the temporary file
     $result = $TmpFile->replaceText($search, $replace);
     $this->assertTrue($result);
     // Double check
     $expected = 'This should be a welcome.tmp file in vendors directory';
     $contents = $TmpFile->read();
     $this->assertContains($expected, $contents);
     $TmpFile->delete();
 }