commitall

This commit is contained in:
Sampanna Rimal
2024-07-10 18:28:19 +05:45
parent 140abda4e6
commit 9cd05ef3cb
15723 changed files with 4818733 additions and 0 deletions

View File

@ -0,0 +1,54 @@
<?php
/**
* 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 org\bovigo\vfs
*/
namespace org\bovigo\vfs\example;
/**
* Example class.
*/
class Example
{
/**
* id of the example
*
* @type string
*/
protected $id;
/**
* a directory where we do something..
*
* @type string
*/
protected $directory;
/**
* constructor
*
* @param string $id
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* sets the directory
*
* @param string $directory
*/
public function setDirectory($directory)
{
$this->directory = $directory . DIRECTORY_SEPARATOR . $this->id;
if (file_exists($this->directory) === false) {
mkdir($this->directory, 0700, true);
}
}
// more source code here...
}
?>

View File

@ -0,0 +1,48 @@
<?php
/**
* 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 org\bovigo\vfs
*/
namespace org\bovigo\vfs\example;
require_once 'Example.php';
/**
* Test case for class Example.
*/
class ExampleTestCaseOldWay extends \PHPUnit_Framework_TestCase
{
/**
* set up test environmemt
*/
public function setUp()
{
if (file_exists(__DIR__ . '/id') === true) {
rmdir(__DIR__ . '/id');
}
}
/**
* clear up test environment
*/
public function tearDown()
{
if (file_exists(__DIR__ . '/id') === true) {
rmdir(__DIR__ . '/id');
}
}
/**
* @test
*/
public function directoryIsCreated()
{
$example = new Example('id');
$this->assertFalse(file_exists(__DIR__ . '/id'));
$example->setDirectory(__DIR__);
$this->assertTrue(file_exists(__DIR__ . '/id'));
}
}
?>

View File

@ -0,0 +1,47 @@
<?php
/**
* 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 org\bovigo\vfs
*/
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
{
/**
* root directory
*
* @type vfsStreamDirectory
*/
protected $root;
/**
* set up test environmemt
*/
public function setUp()
{
$this->root = vfsStream::setup('exampleDir');
}
/**
* @test
*/
public function directoryIsCreated()
{
$example = new Example('id');
$this->assertFalse($this->root->hasChild('id'));
$example->setDirectory(vfsStream::url('exampleDir'));
$this->assertTrue($this->root->hasChild('id'));
}
}
?>

View File

@ -0,0 +1,50 @@
<?php
/**
* 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 org\bovigo\vfs
*/
namespace org\bovigo\vfs\example;
/**
* Example class to demonstrate testing of failure behaviour with vfsStream.
*/
class FailureExample
{
/**
* filename to write data
*
* @type string
*/
protected $filename;
/**
* constructor
*
* @param string $id
*/
public function __construct($filename)
{
$this->filename = $filename;
}
/**
* sets the directory
*
* @param string $directory
*/
public function writeData($data)
{
$bytes = @file_put_contents($this->filename, $data);
if (false === $bytes) {
return 'could not write data';
}
return 'ok';
}
// more source code here...
}
?>

View File

@ -0,0 +1,58 @@
<?php
/**
* 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 org\bovigo\vfs
*/
namespace org\bovigo\vfs\example;
use org\bovigo\vfs\vfsStream;
require_once 'FailureExample.php';
/**
* Test case for class FailureExample.
*/
class FailureExampleTestCase extends \PHPUnit_Framework_TestCase
{
/**
* root directory
*
* @type vfsStreamDirectory
*/
protected $root;
/**
* set up test environmemt
*/
public function setUp()
{
$this->root = vfsStream::setup('exampleDir');
}
/**
* @test
*/
public function returnsOkOnNoFailure()
{
$example = new FailureExample(vfsStream::url('exampleDir/test.txt'));
$this->assertSame('ok', $example->writeData('testdata'));
$this->assertTrue($this->root->hasChild('test.txt'));
$this->assertSame('testdata', $this->root->getChild('test.txt')->getContent());
}
/**
* @test
*/
public function returnsErrorMessageIfWritingToFileFails()
{
$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($this->root->hasChild('test.txt'));
$this->assertSame('notoverwritten', $this->root->getChild('test.txt')->getContent());
}
}
?>

View File

@ -0,0 +1,67 @@
<?php
/**
* 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 org\bovigo\vfs
*/
namespace org\bovigo\vfs\example;
require_once 'FilemodeExample.php';
/**
* Test case for class FilemodeExample.
*/
class FilemodeExampleTestCaseOldWay extends \PHPUnit_Framework_TestCase
{
/**
* set up test environmemt
*/
public function setUp()
{
if (file_exists(__DIR__ . '/id') === true) {
rmdir(__DIR__ . '/id');
}
}
/**
* clear up test environment
*/
public function tearDown()
{
if (file_exists(__DIR__ . '/id') === true) {
rmdir(__DIR__ . '/id');
}
}
/**
* test correct file mode for created directory
*/
public function testDirectoryHasCorrectDefaultFilePermissions()
{
$example = new FilemodeExample('id');
$example->setDirectory(__DIR__);
if (DIRECTORY_SEPARATOR === '\\') {
// can not really test on windows, filemode from mkdir() is ignored
$this->assertEquals(40777, decoct(fileperms(__DIR__ . '/id')));
} else {
$this->assertEquals(40700, decoct(fileperms(__DIR__ . '/id')));
}
}
/**
* test correct file mode for created directory
*/
public function testDirectoryHasCorrectDifferentFilePermissions()
{
$example = new FilemodeExample('id', 0755);
$example->setDirectory(__DIR__);
if (DIRECTORY_SEPARATOR === '\\') {
// can not really test on windows, filemode from mkdir() is ignored
$this->assertEquals(40777, decoct(fileperms(__DIR__ . '/id')));
} else {
$this->assertEquals(40755, decoct(fileperms(__DIR__ . '/id')));
}
}
}
?>

View File

@ -0,0 +1,29 @@
<?php
/**
* 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 org\bovigo\vfs
*/
namespace org\bovigo\vfs\example;
/**
* Example showing correct file permission support introduced with 0.7.0.
*/
class FilePermissionsExample
{
/**
* reads configuration from given config file
*
* @param mixed $config
* @param string $configFile
*/
public function writeConfig($config, $configFile)
{
@file_put_contents($configFile, serialize($config));
}
// more methods here
}
?>

View File

@ -0,0 +1,44 @@
<?php
/**
* 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 org\bovigo\vfs
*/
namespace org\bovigo\vfs\example;
use org\bovigo\vfs\vfsStream;
require_once 'FilePermissionsExample.php';
/**
* Test for FilePermissionsExample.
*/
class FilePermissionsExampleTestCase extends \PHPUnit_Framework_TestCase
{
/**
* @test
*/
public function directoryWritable()
{
vfsStream::setup('exampleDir');
$example = new FilePermissionsExample();
$example->writeConfig(array('foo' => 'bar'),
vfsStream::url('exampleDir/writable.ini')
);
// assertions here
}
/**
* @test
*/
public function directoryNotWritable()
{
vfsStream::setup('exampleDir', 0444);
$example = new FilePermissionsExample();
$example->writeConfig(array('foo' => 'bar'),
vfsStream::url('exampleDir/notWritable.ini')
);
}
}
?>

View File

@ -0,0 +1,62 @@
<?php
/**
* 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 org\bovigo\vfs
*/
namespace org\bovigo\vfs\example;
/**
* Example class.
*/
class FilemodeExample
{
/**
* id of the example
*
* @type string
*/
protected $id;
/**
* a directory where we do something..
*
* @type string
*/
protected $directory;
/**
* file mode for newly created directories
*
* @type int
*/
protected $fileMode;
/**
* constructor
*
* @param string $id
* @param int $fileMode optional
*/
public function __construct($id, $fileMode = 0700)
{
$this->id = $id;
$this->fileMode = $fileMode;
}
/**
* sets the directory
*
* @param string $directory
*/
public function setDirectory($directory)
{
$this->directory = $directory . DIRECTORY_SEPARATOR . $this->id;
if (file_exists($this->directory) === false) {
mkdir($this->directory, $this->fileMode, true);
}
}
// more source code here...
}
?>

View File

@ -0,0 +1,53 @@
<?php
/**
* 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 org\bovigo\vfs
*/
namespace org\bovigo\vfs\example;
use org\bovigo\vfs\vfsStream;
require_once 'FilemodeExample.php';
/**
* Test case for class FilemodeExample.
*/
class FilemodeExampleTestCaseWithVfsStream extends \PHPUnit_Framework_TestCase
{
/**
* root directory
*
* @type vfsStreamDirectory
*/
protected $root;
/**
* set up test environmemt
*/
public function setUp()
{
$this->root = vfsStream::setup('exampleDir');
}
/**
* test that the directory is created
*/
public function testDirectoryIsCreatedWithDefaultPermissions()
{
$example = new FilemodeExample('id');
$example->setDirectory(vfsStream::url('exampleDir'));
$this->assertEquals(0700, $this->root->getChild('id')->getPermissions());
}
/**
* test that the directory is created
*/
public function testDirectoryIsCreatedWithGivenPermissions()
{
$example = new FilemodeExample('id', 0755);
$example->setDirectory(vfsStream::url('exampleDir'));
$this->assertEquals(0755, $this->root->getChild('id')->getPermissions());
}
}
?>

View File

@ -0,0 +1,3 @@
<?php
require __DIR__ . '/../vendor/.composer/autoload.php';
?>