From fc2886b19af48f9c95170a004e37052a9a07f3ab Mon Sep 17 00:00:00 2001 From: Frank Kleine Date: Sat, 14 Jan 2012 23:15:22 +0100 Subject: [PATCH] upgrade examples --- examples/Example.php | 17 +++--- examples/ExampleTestCaseOldWay.php | 34 ++++++----- examples/ExampleTestCaseWithVfsStream.php | 32 +++++++---- examples/FailureExample.php | 17 +++--- examples/FailureExampleTestCase.php | 56 +++++++++---------- examples/FileModeExampleTestCaseOldWay.php | 36 ++++++------ examples/FilePermissionsExample.php | 15 +++-- examples/FilePermissionsExampleTestCase.php | 18 +++--- examples/FilemodeExample.php | 19 +++---- .../FilemodeExampleTestCaseWithVfsStream.php | 33 ++++++----- examples/bootstrap.php | 3 + 11 files changed, 142 insertions(+), 138 deletions(-) create mode 100644 examples/bootstrap.php diff --git a/examples/Example.php b/examples/Example.php index e90d4368..a12caeec 100644 --- a/examples/Example.php +++ b/examples/Example.php @@ -1,29 +1,28 @@ assertFalse(file_exists(dirname(__FILE__) . '/id')); - $example->setDirectory(dirname(__FILE__)); - $this->assertTrue(file_exists(dirname(__FILE__) . '/id')); + $this->assertFalse(file_exists(__DIR__ . '/id')); + $example->setDirectory(__DIR__); + $this->assertTrue(file_exists(__DIR__ . '/id')); } } ?> \ No newline at end of file diff --git a/examples/ExampleTestCaseWithVfsStream.php b/examples/ExampleTestCaseWithVfsStream.php index 4ef2ddf7..97c8a374 100644 --- a/examples/ExampleTestCaseWithVfsStream.php +++ b/examples/ExampleTestCaseWithVfsStream.php @@ -1,13 +1,14 @@ 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')); } } ?> \ No newline at end of file diff --git a/examples/FailureExample.php b/examples/FailureExample.php index 258d7457..472468b2 100644 --- a/examples/FailureExample.php +++ b/examples/FailureExample.php @@ -1,23 +1,22 @@ 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()); } } ?> \ No newline at end of file diff --git a/examples/FileModeExampleTestCaseOldWay.php b/examples/FileModeExampleTestCaseOldWay.php index f7867f3b..9f996711 100644 --- a/examples/FileModeExampleTestCaseOldWay.php +++ b/examples/FileModeExampleTestCaseOldWay.php @@ -1,28 +1,26 @@ setDirectory(dirname(__FILE__)); + $example->setDirectory(__DIR__); if (DIRECTORY_SEPARATOR === '\\') { // can not really test on windows, filemode from mkdir() is ignored - $this->assertEquals(40777, decoct(fileperms(dirname(__FILE__) . '/id'))); + $this->assertEquals(40777, decoct(fileperms(__DIR__ . '/id'))); } else { - $this->assertEquals(40700, decoct(fileperms(dirname(__FILE__) . '/id'))); + $this->assertEquals(40700, decoct(fileperms(__DIR__ . '/id'))); } } @@ -57,12 +55,12 @@ public function testDirectoryHasCorrectDefaultFilePermissions() public function testDirectoryHasCorrectDifferentFilePermissions() { $example = new FilemodeExample('id', 0755); - $example->setDirectory(dirname(__FILE__)); + $example->setDirectory(__DIR__); if (DIRECTORY_SEPARATOR === '\\') { // can not really test on windows, filemode from mkdir() is ignored - $this->assertEquals(40777, decoct(fileperms(dirname(__FILE__) . '/id'))); + $this->assertEquals(40777, decoct(fileperms(__DIR__ . '/id'))); } else { - $this->assertEquals(40755, decoct(fileperms(dirname(__FILE__) . '/id'))); + $this->assertEquals(40755, decoct(fileperms(__DIR__ . '/id'))); } } } diff --git a/examples/FilePermissionsExample.php b/examples/FilePermissionsExample.php index 0538e7d1..6258a5d7 100644 --- a/examples/FilePermissionsExample.php +++ b/examples/FilePermissionsExample.php @@ -1,16 +1,15 @@ root = vfsStream::setup('exampleDir'); } /** @@ -32,7 +37,7 @@ public function testDirectoryIsCreatedWithDefaultPermissions() { $example = new FilemodeExample('id'); $example->setDirectory(vfsStream::url('exampleDir')); - $this->assertEquals(0700, vfsStreamWrapper::getRoot()->getChild('id')->getPermissions()); + $this->assertEquals(0700, $this->root->getChild('id')->getPermissions()); } /** @@ -42,7 +47,7 @@ public function testDirectoryIsCreatedWithGivenPermissions() { $example = new FilemodeExample('id', 0755); $example->setDirectory(vfsStream::url('exampleDir')); - $this->assertEquals(0755, vfsStreamWrapper::getRoot()->getChild('id')->getPermissions()); + $this->assertEquals(0755, $this->root->getChild('id')->getPermissions()); } } ?> \ No newline at end of file diff --git a/examples/bootstrap.php b/examples/bootstrap.php new file mode 100644 index 00000000..998c43db --- /dev/null +++ b/examples/bootstrap.php @@ -0,0 +1,3 @@ + \ No newline at end of file