Skip to content

Commit

Permalink
[FEATURE] json file exists methods implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
higidi committed May 6, 2015
1 parent ab4b48f commit 02a1f44
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/T3ExtCli/Json/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ public function getPath()
return $this->path;
}

/**
* Checks whether json file exists.
*
* @return bool True if json file exists, otherwise false.
*/
public function exists()
{
return is_file($this->path);
}

}
39 changes: 37 additions & 2 deletions tests/src/T3ExtCli/Test/Json/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
{

const VIRTUAL_JSON_FILE_PATH = '/tmp/path/not/exists.json';
const REAL_JSON_FILE_PATH = '/tmp/php-test-file.json';

/**
* @var File
Expand All @@ -25,12 +26,46 @@ class FileTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->file = new File(self::VIRTUAL_JSON_FILE_PATH);
$this->createTestJsonFile();
$this->file = new File(self::REAL_JSON_FILE_PATH);
}

protected function tearDown()
{
$this->deleteTestJsonFile();
}

protected function createTestJsonFile()
{
$data = <<<EOF
{
"name": "T3ExtCli"
}
EOF;
file_put_contents(self::REAL_JSON_FILE_PATH, $data);
}

protected function deleteTestJsonFile()
{
if (is_file(self::REAL_JSON_FILE_PATH)) {
unlink(self::REAL_JSON_FILE_PATH);
}
}

public function testJsonPathWillBeApplied()
{
$this->assertSame(self::VIRTUAL_JSON_FILE_PATH, $this->file->getPath());
$this->assertSame(self::REAL_JSON_FILE_PATH, $this->file->getPath());
}

public function testJsonFileExistsWillReturnFalseForVirtualJsonFile()
{
$file = new File(self::VIRTUAL_JSON_FILE_PATH);
$this->assertFalse($file->exists());
}

public function testJsonFileExistsWillReturnTrueForRealJsonFile()
{
$this->assertTrue($this->file->exists());
}

}

0 comments on commit 02a1f44

Please sign in to comment.