Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alganet/env_deprecated
Lightweight, transparent, testable and awesome enviroment wrapper
https://github.com/alganet/env_deprecated
Last synced: about 1 month ago
JSON representation
Lightweight, transparent, testable and awesome enviroment wrapper
- Host: GitHub
- URL: https://github.com/alganet/env_deprecated
- Owner: alganet
- Created: 2010-10-04T16:14:44.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2010-10-14T01:09:55.000Z (about 14 years ago)
- Last Synced: 2024-10-14T10:51:34.075Z (3 months ago)
- Language: PHP
- Homepage:
- Size: 92.8 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.textile
Awesome Lists containing this project
README
h2. About
Respect\Env is a tool for wrapping up native PHP functions and resources. It should be very useful to improve testability and modularity on code that uses functions like getenv, shell_exec, filter_input and so on by mocking these functions behaviors on test conditions.
Decoupling these functionality from your code is as easy as importing and prefixing some namespaces in strategic locations, and Respect\Env is smart enough to keep state when mocking variables (ex. getenv, putenv and filter_var(INPUT_ENV)).
You can also go Wrapper::evil($ns) to eval() functions without prefixing anything, but thats just wrong and we took measures to allow that only in test environments (PHPUnit loaded).
h2. Support
The current supported functions are:
-getenv
-putenv
-shell_exec
-sys_get_temp_dir
-filter_input
-filter_input_array
-filter_has_varRoadmap:
-getopt
-passthru
-exec
-system
-file_get_contents
-file_put_contentsh2. Usage (prefixed)
The following code has a testability problem: It must run as root, but running tests on root is not advisable. The following code is a kind of mock/stub:
Class file:
Test file:
namespace MyNS;
use Respect\Env\Wrapper;
class MyClassTest extends \PHPUnit_Framework_TestCase
{
public function testFoobar()
{
Wrapper::set("custom");
Wrapper::getCurrent()->setShellCallback(
function() { return 'root';}
);
$this->assertTrue(MyClass::hasPermissions());
}
}h2. Evil usage (no prefix, works only when PHPUnit is loaded)
Class file: