Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

upgrade examples

  • Loading branch information...
commit fc2886b19af48f9c95170a004e37052a9a07f3ab 1 parent 6007e9e
Frank Kleine authored
17 examples/Example.php
View
@@ -1,29 +1,28 @@
<?php
/**
- * Example class.
+ * 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
*/
+namespace org\bovigo\vfs\example;
/**
* Example class.
- *
- * @package bovigo_vfs
- * @subpackage examples
*/
class Example
{
/**
* id of the example
*
- * @var string
+ * @type string
*/
protected $id;
/**
* a directory where we do something..
*
- * @var string
+ * @type string
*/
protected $directory;
34 examples/ExampleTestCaseOldWay.php
View
@@ -1,28 +1,26 @@
<?php
/**
- * Test case for class Example.
+ * 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';
+namespace org\bovigo\vfs\example;
require_once 'Example.php';
/**
* Test case for class Example.
- *
- * @package bovigo_vfs
- * @subpackage examples
*/
-class ExampleTestCaseOldWay extends PHPUnit_Framework_TestCase
+class ExampleTestCaseOldWay extends \PHPUnit_Framework_TestCase
{
/**
* set up test environmemt
*/
public function setUp()
{
- if (file_exists(dirname(__FILE__) . '/id') === true) {
- rmdir(dirname(__FILE__) . '/id');
+ if (file_exists(__DIR__ . '/id') === true) {
+ rmdir(__DIR__ . '/id');
}
}
@@ -31,20 +29,20 @@ public function setUp()
*/
public function tearDown()
{
- if (file_exists(dirname(__FILE__) . '/id') === true) {
- rmdir(dirname(__FILE__) . '/id');
+ if (file_exists(__DIR__ . '/id') === true) {
+ rmdir(__DIR__ . '/id');
}
}
/**
- * test that the directory is created
+ * @test
*/
- public function testDirectoryIsCreated()
+ public function directoryIsCreated()
{
$example = new Example('id');
- $this->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'));
}
}
?>
32 examples/ExampleTestCaseWithVfsStream.php
View
@@ -1,13 +1,14 @@
<?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.
@@ -15,25 +16,32 @@
* @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'));
}
}
?>
17 examples/FailureExample.php
View
@@ -1,23 +1,22 @@
<?php
/**
- * Example class to demonstrate testing of failure behaviour with vfsStream.
+ * 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
*/
+namespace org\bovigo\vfs\example;
/**
* Example class to demonstrate testing of failure behaviour with vfsStream.
- *
- * @package bovigo_vfs
- * @subpackage examples
*/
class FailureExample
{
/**
* filename to write data
*
- * @var string
+ * @type string
*/
protected $filename;
@@ -42,7 +41,7 @@ public function writeData($data)
if (false === $bytes) {
return 'could not write data';
}
-
+
return 'ok';
}
56 examples/FailureExampleTestCase.php
View
@@ -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());
}
}
?>
36 examples/FileModeExampleTestCaseOldWay.php
View
@@ -1,28 +1,26 @@
<?php
/**
- * Test case for class FilemodeExample.
+ * 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 stubbles_vfs
- * @subpackage examples
- * @version $Id$
+ * @package org\bovigo\vfs
*/
-require_once 'PHPUnit/Framework.php';
+namespace org\bovigo\vfs\example;
require_once 'FilemodeExample.php';
/**
* Test case for class FilemodeExample.
- *
- * @package stubbles_vfs
- * @subpackage examples
*/
-class FileModeExampleTestCaseOldWay extends PHPUnit_Framework_TestCase
+class FilemodeExampleTestCaseOldWay extends \PHPUnit_Framework_TestCase
{
/**
* set up test environmemt
*/
public function setUp()
{
- if (file_exists(dirname(__FILE__) . '/id') === true) {
- rmdir(dirname(__FILE__) . '/id');
+ if (file_exists(__DIR__ . '/id') === true) {
+ rmdir(__DIR__ . '/id');
}
}
@@ -31,8 +29,8 @@ public function setUp()
*/
public function tearDown()
{
- if (file_exists(dirname(__FILE__) . '/id') === true) {
- rmdir(dirname(__FILE__) . '/id');
+ if (file_exists(__DIR__ . '/id') === true) {
+ rmdir(__DIR__ . '/id');
}
}
@@ -42,12 +40,12 @@ public function tearDown()
public function testDirectoryHasCorrectDefaultFilePermissions()
{
$example = new FilemodeExample('id');
- $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(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')));
}
}
}
15 examples/FilePermissionsExample.php
View
@@ -1,16 +1,15 @@
<?php
/**
- * Example showing correct file permission support introduced with 0.7.0.
+ * 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
*/
+namespace org\bovigo\vfs\example;
/**
* Example showing correct file permission support introduced with 0.7.0.
- *
- * @package bovigo_vfs
- * @subpackage examples
*/
class FilePermissionsExample
{
@@ -22,7 +21,7 @@ class FilePermissionsExample
*/
public function writeConfig($config, $configFile)
{
- file_put_contents($configFile, serialize($config));
+ @file_put_contents($configFile, serialize($config));
}
// more methods here
18 examples/FilePermissionsExampleTestCase.php
View
@@ -1,21 +1,19 @@
<?php
/**
- * Test for FilePermissionsExample.
+ * 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 'FilePermissionsExample.php';
/**
* Test for FilePermissionsExample.
- *
- * @package bovigo_vfs
- * @subpackage examples
*/
-class FilePermissionsExampleTestCase extends PHPUnit_Framework_TestCase
+class FilePermissionsExampleTestCase extends \PHPUnit_Framework_TestCase
{
/**
* @test
19 examples/FilemodeExample.php
View
@@ -1,35 +1,34 @@
<?php
/**
- * Example class.
+ * 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 stubbles_vfs
- * @subpackage examples
- * @version $Id$
+ * @package org\bovigo\vfs
*/
+namespace org\bovigo\vfs\example;
/**
* Example class.
- *
- * @package stubbles_vfs
- * @subpackage examples
*/
class FilemodeExample
{
/**
* id of the example
*
- * @var string
+ * @type string
*/
protected $id;
/**
* a directory where we do something..
*
- * @var string
+ * @type string
*/
protected $directory;
/**
* file mode for newly created directories
*
- * @var int
+ * @type int
*/
protected $fileMode;
33 examples/FilemodeExampleTestCaseWithVfsStream.php
View
@@ -1,28 +1,33 @@
<?php
/**
- * Test case for class FilemodeExample.
+ * 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 stubbles_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 'FilemodeExample.php';
/**
- * Test case for class Example.
- *
- * @package stubbles_vfs
- * @subpackage examples
+ * Test case for class FilemodeExample.
*/
-class FilemodeExampleTestCaseWithVfsStream extends PHPUnit_Framework_TestCase
+class FilemodeExampleTestCaseWithVfsStream 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');
}
/**
@@ -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());
}
}
?>
3  examples/bootstrap.php
View
@@ -0,0 +1,3 @@
+<?php
+require __DIR__ . '/../vendor/.composer/autoload.php';
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.