Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Frank Kleine
committed
Jan 14, 2012
1 parent
6007e9e
commit fc2886b
Showing
11 changed files
with
142 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,47 @@ | ||
<?php | ||
/** | ||
* Test case for class Example. | ||
* This file is part of vfsStream. | ||
* | ||
* @package bovigo_vfs | ||
* @subpackage examples | ||
* @version $Id$ | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package org\bovigo\vfs | ||
*/ | ||
require_once 'PHPUnit/Framework.php'; | ||
require_once 'vfsStream/vfsStream.php'; | ||
namespace org\bovigo\vfs\example; | ||
use org\bovigo\vfs\vfsStream; | ||
require_once 'Example.php'; | ||
/** | ||
* Test case for class Example. | ||
* | ||
* @package bovigo_vfs | ||
* @subpackage examples | ||
*/ | ||
class ExampleTestCaseWithVfsStream extends PHPUnit_Framework_TestCase | ||
class ExampleTestCaseWithVfsStream extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* root directory | ||
* | ||
* @type vfsStreamDirectory | ||
*/ | ||
protected $root; | ||
|
||
/** | ||
* set up test environmemt | ||
*/ | ||
public function setUp() | ||
{ | ||
vfsStream::setup('exampleDir'); | ||
$this->root = vfsStream::setup('exampleDir'); | ||
} | ||
|
||
/** | ||
* test that the directory is created | ||
* @test | ||
*/ | ||
public function testDirectoryIsCreated() | ||
public function directoryIsCreated() | ||
{ | ||
$example = new Example('id'); | ||
$this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('id')); | ||
$this->assertFalse($this->root->hasChild('id')); | ||
$example->setDirectory(vfsStream::url('exampleDir')); | ||
$this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('id')); | ||
$this->assertTrue($this->root->hasChild('id')); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,58 @@ | ||
<?php | ||
/** | ||
* Test case for class FailureExample. | ||
* This file is part of vfsStream. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package bovigo_vfs | ||
* @subpackage examples | ||
* @version $Id$ | ||
* @package org\bovigo\vfs | ||
*/ | ||
require_once 'PHPUnit/Framework.php'; | ||
require_once 'vfsStream/vfsStream.php'; | ||
namespace org\bovigo\vfs\example; | ||
use org\bovigo\vfs\vfsStream; | ||
require_once 'FailureExample.php'; | ||
/** | ||
* Test case for class FailureExample. | ||
* | ||
* @package bovigo_vfs | ||
* @subpackage examples | ||
*/ | ||
class FailureExampleTestCase extends PHPUnit_Framework_TestCase | ||
class FailureExampleTestCase extends \PHPUnit_Framework_TestCase | ||
{ | ||
/** | ||
* root directory | ||
* | ||
* @type vfsStreamDirectory | ||
*/ | ||
protected $root; | ||
|
||
/** | ||
* set up test environmemt | ||
*/ | ||
public function setUp() | ||
{ | ||
vfsStreamWrapper::register(); | ||
$this->root = vfsStream::setup('exampleDir'); | ||
} | ||
|
||
/** | ||
* no failure case | ||
* @test | ||
*/ | ||
public function testNoFailure() | ||
public function returnsOkOnNoFailure() | ||
{ | ||
$root = new vfsStreamDirectory('exampleDir'); | ||
vfsStreamWrapper::setRoot($root); | ||
$example = new FailureExample(vfsStream::url('exampleDir/test.txt')); | ||
$this->assertSame('ok', $example->writeData('testdata')); | ||
$this->assertTrue($root->hasChild('test.txt')); | ||
$this->assertSame('testdata', $root->getChild('test.txt')->getContent()); | ||
$this->assertTrue($this->root->hasChild('test.txt')); | ||
$this->assertSame('testdata', $this->root->getChild('test.txt')->getContent()); | ||
} | ||
|
||
/** | ||
* can't write to file | ||
* @test | ||
*/ | ||
public function testNoWrite() | ||
public function returnsErrorMessageIfWritingToFileFails() | ||
{ | ||
$root = new vfsStreamDirectory('exampleDir'); | ||
$file = $this->getMock('vfsStreamFile', array('write'), array('test.txt')); | ||
$file->setContent('notoverwritten'); | ||
$file->expects($this->once()) | ||
->method('write') | ||
->will($this->returnValue(false)); | ||
$root->addChild($file); | ||
vfsStreamWrapper::setRoot($root); | ||
$file = vfsStream::newFile('test.txt', 0000) | ||
->withContent('notoverwritten') | ||
->at($this->root); | ||
$example = new FailureExample(vfsStream::url('exampleDir/test.txt')); | ||
$this->assertSame('could not write data', $example->writeData('testdata')); | ||
$this->assertTrue($root->hasChild('test.txt')); | ||
$this->assertSame('notoverwritten', $root->getChild('test.txt')->getContent()); | ||
$this->assertTrue($this->root->hasChild('test.txt')); | ||
$this->assertSame('notoverwritten', $this->root->getChild('test.txt')->getContent()); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.