3 * This file is part of vfsStream.
5 * For the full copyright and license information, please view the LICENSE
6 * file that was distributed with this source code.
8 * @package org\bovigo\vfs
10 namespace org\bovigo\vfs;
12 * Test for quota related functionality of org\bovigo\vfs\vfsStreamWrapper.
16 class vfsStreamWrapperQuotaTestCase extends \PHPUnit_Framework_TestCase
21 * @type vfsStreamDirectory
26 * set up test environment
28 public function setUp()
30 $this->root = vfsStream::setup();
31 vfsStream::setQuota(10);
37 public function writeLessThanQuotaWritesEverything()
39 $this->assertEquals(9, file_put_contents(vfsStream::url('root/file.txt'), '123456789'));
40 $this->assertEquals('123456789', $this->root->getChild('file.txt')->getContent());
46 public function writeUpToQotaWritesEverything()
48 $this->assertEquals(10, file_put_contents(vfsStream::url('root/file.txt'), '1234567890'));
49 $this->assertEquals('1234567890', $this->root->getChild('file.txt')->getContent());
55 public function writeMoreThanQotaWritesOnlyUpToQuota()
58 file_put_contents(vfsStream::url('root/file.txt'), '12345678901');
59 } catch (\PHPUnit_Framework_Error $e) {
60 $this->assertEquals('file_put_contents(): Only 10 of 11 bytes written, possibly out of free disk space',
65 $this->assertEquals('1234567890', $this->root->getChild('file.txt')->getContent());
71 public function considersAllFilesForQuota()
73 vfsStream::newFile('foo.txt')
75 ->at(vfsStream::newDirectory('bar')
79 file_put_contents(vfsStream::url('root/file.txt'), '12345678901');
80 } catch (\PHPUnit_Framework_Error $e) {
81 $this->assertEquals('file_put_contents(): Only 7 of 11 bytes written, possibly out of free disk space',
86 $this->assertEquals('1234567', $this->root->getChild('file.txt')->getContent());
93 public function truncateToLessThanQuotaWritesEverything()
95 if (version_compare(PHP_VERSION, '5.4.0', '<')) {
96 $this->markTestSkipped('Requires PHP 5.4');
99 if (strstr(PHP_VERSION, 'hiphop') !== false) {
100 $this->markTestSkipped('Not supported on hhvm');
103 $fp = fopen(vfsStream::url('root/file.txt'), 'w+');
104 $this->assertTrue(ftruncate($fp, 9));
106 $this->assertEquals(9,
107 $this->root->getChild('file.txt')->size()
109 $this->assertEquals("\0\0\0\0\0\0\0\0\0",
110 $this->root->getChild('file.txt')->getContent()
118 public function truncateUpToQotaWritesEverything()
120 if (version_compare(PHP_VERSION, '5.4.0', '<')) {
121 $this->markTestSkipped('Requires PHP 5.4');
124 if (strstr(PHP_VERSION, 'hiphop') !== false) {
125 $this->markTestSkipped('Not supported on hhvm');
128 $fp = fopen(vfsStream::url('root/file.txt'), 'w+');
129 $this->assertTrue(ftruncate($fp, 10));
131 $this->assertEquals(10,
132 $this->root->getChild('file.txt')->size()
134 $this->assertEquals("\0\0\0\0\0\0\0\0\0\0",
135 $this->root->getChild('file.txt')->getContent()
143 public function truncateToMoreThanQotaWritesOnlyUpToQuota()
145 if (version_compare(PHP_VERSION, '5.4.0', '<')) {
146 $this->markTestSkipped('Requires PHP 5.4');
149 if (strstr(PHP_VERSION, 'hiphop') !== false) {
150 $this->markTestSkipped('Not supported on hhvm');
153 $fp = fopen(vfsStream::url('root/file.txt'), 'w+');
154 $this->assertTrue(ftruncate($fp, 11));
156 $this->assertEquals(10,
157 $this->root->getChild('file.txt')->size()
159 $this->assertEquals("\0\0\0\0\0\0\0\0\0\0",
160 $this->root->getChild('file.txt')->getContent()
168 public function truncateConsidersAllFilesForQuota()
170 if (version_compare(PHP_VERSION, '5.4.0', '<')) {
171 $this->markTestSkipped('Requires PHP 5.4');
174 if (strstr(PHP_VERSION, 'hiphop') !== false) {
175 $this->markTestSkipped('Not supported on hhvm');
178 vfsStream::newFile('bar.txt')
180 ->at(vfsStream::newDirectory('bar')
183 $fp = fopen(vfsStream::url('root/file.txt'), 'w+');
184 $this->assertTrue(ftruncate($fp, 11));
186 $this->assertEquals(7,
187 $this->root->getChild('file.txt')->size()
189 $this->assertEquals("\0\0\0\0\0\0\0",
190 $this->root->getChild('file.txt')->getContent()
198 public function canNotTruncateToGreaterLengthWhenDiscQuotaReached()
200 if (version_compare(PHP_VERSION, '5.4.0', '<')) {
201 $this->markTestSkipped('Requires PHP 5.4');
204 if (strstr(PHP_VERSION, 'hiphop') !== false) {
205 $this->markTestSkipped('Not supported on hhvm');
208 vfsStream::newFile('bar.txt')
209 ->withContent('1234567890')
210 ->at(vfsStream::newDirectory('bar')
213 $fp = fopen(vfsStream::url('root/file.txt'), 'w+');
214 $this->assertFalse(ftruncate($fp, 11));
216 $this->assertEquals(0,
217 $this->root->getChild('file.txt')->size()
219 $this->assertEquals('',
220 $this->root->getChild('file.txt')->getContent()