assertFileExists() public static method

Asserts that a file exists.
public static assertFileExists ( string $filename, string $message = '' )
$filename string
$message string
 /**
  * @Then :file file should contain:
  *
  * @param string $file
  * @param PyStringNode $strings
  */
 public function fileShouldContain($file, PyStringNode $strings)
 {
     PHPUnit::assertFileExists($file);
     $contents = file_get_contents($file);
     $strings = $strings->getStrings();
     array_walk($strings, function ($string) use($contents) {
         PHPUnit::assertContains($string, $contents);
     });
 }
 /**
  * Checks whether specified file exists and contains specified string.
  *
  * @Then /^"([^"]*)" file should contain:$/
  *
  * @param string       $path file path
  * @param PyStringNode $text file content
  */
 public function fileShouldContain($path, PyStringNode $text)
 {
     $path = $this->workingDir . '/' . $path;
     PHPUnit_Framework_Assert::assertFileExists($path);
     $fileContent = trim(file_get_contents($path));
     // Normalize the line endings in the output
     if ("\n" !== PHP_EOL) {
         $fileContent = str_replace(PHP_EOL, "\n", $fileContent);
     }
     PHPUnit_Framework_Assert::assertEquals($this->getExpectedOutput($text), $fileContent);
 }
Example #3
0
 public function toExist()
 {
     if ($this->negate) {
         a::assertFileNotExists($this->actual);
     } else {
         a::assertFileExists($this->actual);
     }
 }
Example #4
0
 /**
  * Checks whether specified file exists and contains specified string.
  *
  * @Then /^"([^"]*)" should contain( the string|):$/
  */
 public function shouldContain($path, $subString, PyStringNode $string)
 {
     $subString = !empty($subString);
     if ($path[0] == '~') {
         $path = $this->homeDir . ltrim($path, '~');
     } else {
         $path = $this->workingDir . '/' . $path;
     }
     PHPUnit_Framework_Assert::assertFileExists($path);
     $fileContent = trim(file_get_contents($path));
     // Normalize the line endings in the output
     if ("\n" !== PHP_EOL) {
         $fileContent = str_replace(PHP_EOL, "\n", $fileContent);
     }
     // Trim trailing whitespace. It usually messes things up.
     $fileContent = trim(preg_replace("/ +\$/m", '', $fileContent));
     if ($subString) {
         PHPUnit_Framework_Assert::assertContains((string) $string, $fileContent);
     } else {
         PHPUnit_Framework_Assert::assertEquals((string) $string, $fileContent);
     }
 }
Example #5
0
 public function exists()
 {
     if (!$this->isFileExpectation) {
         throw new \Exception('exists() expectation should be called with expect_file()');
     }
     a::assertFileExists($this->actual, $this->description);
 }
Example #6
0
 /**
  * @Then The :key file should exists
  */
 public function theFileShouldExists($key)
 {
     \PHPUnit_Framework_Assert::assertFileExists($this->result[$key]);
     unlink($this->result[$key]);
 }
Example #7
0
 /**
  * @Then :name file should contain:
  */
 public function assertFileContents($name, PyStringNode $contents)
 {
     PHPUnit_Framework_Assert::assertFileExists($name);
     PHPUnit_Framework_Assert::assertContains($contents->getRaw(), file_get_contents($name));
 }
Example #8
0
 /**
  * Checks if file exists
  *  
  * @param string $filename
  * @param string $message
  */
 protected function assertFileExists($filename, $message = '')
 {
     \PHPUnit_Framework_Assert::assertFileExists($filename, $message);
 }
 /**
  * @Then /^the junit file "([^"]*)" should contain:$/
  */
 public function theJunitFileShouldContain($file, PyStringNode $text)
 {
     PHPUnit_Framework_Assert::assertFileExists($file);
     // replace random time ...
     $contents = preg_replace('@time="[0-9.]*"@', 'time="XXX"', file_get_contents($file));
     // replace random path
     $contents = preg_replace('@[0-9a-zA-Z]{32}@', 'XXX', $contents);
     // fix random path in exception ...
     $contents = preg_replace('@<!\\[CDATA\\[.*\\]\\]>@s', '<![CDATA[XXX]]>', $contents);
     PHPUnit_Framework_Assert::assertEquals($contents, (string) $text);
 }
Example #10
0
 /**
  * Asserts that a vfs file exists.
  *
  * @param $filename
  * @param string $message
  */
 public function assertVfsFileExists($filename, $message = '')
 {
     PHPUnit::assertFileExists($this->getPath($filename), $message);
 }
Example #11
0
 /**
  * @Then the file :file should exist in :project
  */
 public function theFileShouldExistInProject($file, $project)
 {
     $path = sprintf('%s/%s/%s', $this->cwd, $project, $file);
     Assert::assertFileExists($path);
 }
Example #12
0
 /**
  * Checks if file exists in path.
  * Opens a file when it's exists
  *
  * ``` php
  * <?php
  * $I->seeFileFound('UserModel.php','app/models');
  * ?>
  * ```
  *
  * @param $filename
  * @param string $path
  */
 public function seeFileFound($filename, $path = '')
 {
     if (file_exists($filename) and !$path) {
         $this->openFile($filename);
         $this->filepath = $filename;
         $this->debug($filename);
         \PHPUnit_Framework_Assert::assertFileExists($path . $filename);
         return;
     }
     $path = $this->absolutizePath($path);
     $this->debug($path);
     if (!file_exists($path)) {
         \PHPUnit_Framework_Assert::fail("Directory does not exist: {$path}");
     }
     $files = Finder::create()->files()->name($filename)->in($path);
     foreach ($files as $file) {
         $file = $file->getRealPath();
         $this->openFile($file);
         $this->filepath = $file;
         $this->debug($file);
         \PHPUnit_Framework_Assert::assertFileExists($file);
         return;
     }
     \Codeception\Util\Debug::pause();
     $this->fail("{$filename} in {$path}");
 }
 /**
  * Checks whether specified content and structure of the xml is correct without worrying about layout.
  *
  * @Then /^"([^"]*)" file xml should be like:$/
  *
  * @param string       $path file path
  * @param PyStringNode $text file content
  */
 public function fileXmlShouldBeLike($path, PyStringNode $text)
 {
     $path = $this->workingDir . '/' . $path;
     PHPUnit_Framework_Assert::assertFileExists($path);
     $fileContent = trim(file_get_contents($path));
     $dom = new DOMDocument();
     $dom->loadXML($text);
     $dom->formatOutput = true;
     PHPUnit_Framework_Assert::assertEquals(trim($dom->saveXML(null, LIBXML_NOEMPTYTAG)), $fileContent);
 }
Example #14
0
 public function shouldExist()
 {
     Assert::assertFileExists($this->it);
 }
Example #15
0
 /**
  * Expect that a file exists.
  *
  * @param string $message
  *
  * @return Expect
  */
 public function toExist($message = '')
 {
     Assert::assertFileExists($this->value, $message);
     return $this;
 }
Example #16
0
 /**
  * Checks if file exists in path.
  * Opens a file when it's exists
  *
  * ``` php
  * <?php
  * $I->seeFileFound('UserModel.php','app/models');
  * ?>
  * ```
  *
  * @param $filename
  * @param string $path
  */
 public function seeFileFound($filename, $path = '')
 {
     $path = $this->absolutizePath($path);
     $this->debug($path);
     if (!file_exists($path)) {
         \PHPUnit_Framework_Assert::fail("Directory does not exist: {$path}");
     }
     $files = \Symfony\Component\Finder\Finder::create()->files()->name($filename)->in($path);
     foreach ($files as $file) {
         $file = $file->getRealPath();
         $this->openFile($file);
         $this->filepath = $file;
         $this->debug($file);
         \PHPUnit_Framework_Assert::assertFileExists($file);
         return;
     }
     \PHPUnit_Framework_Assert::fail("{$filename} in {$path}");
 }
 /**
  * Checks whether a file at provided path exists.
  *
  * @Given /^file "([^"]*)" should exist$/
  *
  * @param   string $path
  */
 public function fileShouldExist($path)
 {
     \PHPUnit_Framework_Assert::assertFileExists($path);
 }
Example #18
0
/**
 * Asserts that a file exists.
 *
 * @param  string $filename
 * @param  string $message
 * @since  Method available since Release 3.0.0
 */
function assertFileExists($filename, $message = '')
{
    return PHPUnit_Framework_Assert::assertFileExists($filename, $message);
}
 /**
  * Checks whether specified file exists and contains specified string.
  *
  * @Given /^"([^"]*)" file should contain:$/
  *
  * @param   string       $path   file path
  * @param   PyStringNode $text   file content
  */
 public function fileShouldContain($path, PyStringNode $text)
 {
     \PHPUnit_Framework_Assert::assertFileExists($path);
     \PHPUnit_Framework_Assert::assertEquals((string) $text, trim(file_get_contents($path)));
 }
Example #20
0
 /**
  * @Then the log file :filename should contain :contents
  */
 public function theLogFileShouldContain($filename, $contents)
 {
     $absoluteFilename = $this->workingDir . DIRECTORY_SEPARATOR . (string) $filename;
     PHPUnit_Framework_Assert::assertFileExists($absoluteFilename);
     PHPUnit_Framework_Assert::assertContains($contents, file_get_contents($absoluteFilename));
 }
Example #21
0
 public function isExist()
 {
     Assert::assertFileExists($this->actual, $this->description);
     return $this;
 }