16
16
abstract class WorkingDirectoryAwareTestCase extends \PHPUnit_Framework_TestCase
17
17
{
18
18
19
- /**
20
- * Original value of "HOME" environment variable.
21
- *
22
- * @var string
23
- */
24
- private $ _homeDirectoryBackup ;
25
-
26
19
protected function setUp ()
27
20
{
28
21
parent ::setUp ();
29
22
30
- $ this ->_homeDirectoryBackup = getenv ('HOME ' );
31
-
32
23
if ( $ this ->requireWorkingDirectory () ) {
33
24
$ this ->_createTempHomeDirectory ();
34
25
}
@@ -51,7 +42,13 @@ protected function requireWorkingDirectory()
51
42
*/
52
43
protected function getWorkingDirectory ()
53
44
{
54
- $ working_directory = new WorkingDirectory ();
45
+ $ sub_folder = array_key_exists ('working_directory ' , $ _SERVER ) ? $ _SERVER ['working_directory ' ] : '' ;
46
+
47
+ if ( !strlen ($ sub_folder ) ) {
48
+ $ this ->fail ('Please set "working_directory" environment variable before calling ' . __METHOD__ . '. ' );
49
+ }
50
+
51
+ $ working_directory = new WorkingDirectory ($ sub_folder );
55
52
56
53
return $ working_directory ->get ();
57
54
}
@@ -60,7 +57,7 @@ protected function tearDown()
60
57
{
61
58
parent ::tearDown ();
62
59
63
- $ this ->_restoreHomeDirectory ($ this -> _homeDirectoryBackup );
60
+ $ this ->_restoreHomeDirectory ();
64
61
}
65
62
66
63
/**
@@ -80,10 +77,17 @@ private function _createTempHomeDirectory()
80
77
/**
81
78
* Restores original home directory and removes temporary one.
82
79
*
83
- * @param string $original_home_directory Directory.
80
+ * @return void
81
+ * @throws \LogicException When original home directory is empty.
84
82
*/
85
- private function _restoreHomeDirectory ($ original_home_directory )
83
+ private function _restoreHomeDirectory ()
86
84
{
85
+ $ original_home_directory = $ _SERVER ['HOME ' ];
86
+
87
+ if ( empty ($ original_home_directory ) ) {
88
+ throw new \LogicException ('Unable to restore empty home directory. ' );
89
+ }
90
+
87
91
$ current_home_directory = getenv ('HOME ' );
88
92
89
93
if ( $ current_home_directory && $ current_home_directory != $ original_home_directory ) {
0 commit comments