I have to test my web application inside a scenario where there isn’t any disk space remaining, i.e. I am unable to write anymore files. However I shouldn't fill my hard disk with junk simply to make certain there’s really no space left. Things I want would be to simulate this case withing a specific process (really, a PHP application).
Indeed, temporarily barring disk creates to some process should be enough.
What’s the simplest method of doing this? I’m using Mac OS X 10.6.2 with built-in Apache/PHP bundle. Thanks.
Edit: Disk free space check won't be reliable because it can alter any time. Many pages are now being offered concurrently. There might be enough free space when checking, but none of them through the moment you really write something. Also, checking for disk free space will need altering the code everywhere I write personal files, which isn't things i want :-) Finally, this solution is the complete opposite of what I’m attempting to test: how my application will behave if this cannot write anymore.
Give my sister use of the equipment for fifteen minutes.
Bonus: you will be testing your virus/adware and spyware protection simultaneously.
I wager you might make your own .dmg file with file system of size ... say 2Mb and email it. If the works, then its super-simple for testing - you simply mount it and switch the road for testing. When the dmg is sufficiently small, you can most likely even upload it towards the source control.
After I needed to get this done I produced an online machine with only a little space allotted towards the virtual disk.
You don't need to make use of a prefilled dummy filesystem.
disk_free_space() to mock the FileSystem
disk_free_space() - Given a string that contains a directory, this function will return the amount of bytes on the corresponding filesystem or disk partition.
To simulate, just wrap the function right into a FileSystem Class. Then inject it for your class doing the saving like a dependency and appearance when the drive is full before you decide to perform the actual saving. Inside your UnitTest, just swap the regular class using the class mocking a complete file system and you are done. By doing this it's not necessary to recreate the entire disk drive or keep your drive together with your project files constantly without notice to rerun your test, e.g.
and also to simulate a complete FileSystem do
If you wish to overload the function to come back whatsoever occasions, you could utilize the RunKit Pecl extension and do:
As a substitute consider vfsStream:
vfsStream is really a stream wrapper for any virtual file system that might be useful in unit tests to mock the actual file system. You can use it with any unit test framework, like PHPUnit or SimpleTest.
I made use of a thumb drive, because the volume for that process.
I am unsure of methods to get it done on OSX but on Linux, I'd most likely put a disk quota on my small test user after which run the application.
Or possibly produce a null file (a little one), format it as being an ext3 partition, mount it while using loopback tool and run the PHP application within it. This is nearer to an actual disk that's lacking space.
A fast and simple solution could be establishing a Quota for any specialized user account. Quota support on Mac OS X
If you do not mind the trouble to put it together, cheap you most likely require a second license for the operating-system, an online Machine is most likely the very best idea most abundant in lengthy-term options.
Produce a disk/filesystem image inside a regular file (of limited size) and loop mount it.
But when you will be carrying this out frequently I'd produce a virtual machine&mdashyou'll find chance to reuse it.