@@ -115,4 +115,82 @@ public function testCopyCreatesTargetDirectoryIfItDoesNotExist()
115115 unlink ($ targetFilePath );
116116 rmdir ($ targetFileDirectory );
117117 }
118+ 
119+  public  function  testMkdirCreatesDirectoriesRecursively ()
120+  {
121+  $ directory  = sys_get_temp_dir ().DIRECTORY_SEPARATOR .time ();
122+  $ subDirectory  = $ directory .DIRECTORY_SEPARATOR .'sub_directory ' ;
123+ 
124+  $ filesystem  = new  Filesystem ();
125+  $ result  = $ filesystem ->mkdir ($ subDirectory );
126+ 
127+  $ this  ->assertTrue ($ result );
128+  $ this  ->assertTrue (is_dir ($ subDirectory ));
129+ 
130+  rmdir ($ subDirectory );
131+  rmdir ($ directory );
132+  }
133+ 
134+  public  function  testMkdirCreatesDirectoriesFromArray ()
135+  {
136+  $ basePath  = sys_get_temp_dir ().DIRECTORY_SEPARATOR .time ();
137+  $ directories  = array (
138+  $ basePath .'1 ' , $ basePath .'2 ' , $ basePath .'3 ' 
139+  );
140+ 
141+  $ filesystem  = new  Filesystem ();
142+  $ result  = $ filesystem ->mkdir ($ directories );
143+ 
144+  $ this  ->assertTrue ($ result );
145+  $ this  ->assertTrue (is_dir ($ basePath .'1 ' ));
146+  $ this  ->assertTrue (is_dir ($ basePath .'2 ' ));
147+  $ this  ->assertTrue (is_dir ($ basePath .'3 ' ));
148+ 
149+  rmdir ($ basePath .'1 ' );
150+  rmdir ($ basePath .'2 ' );
151+  rmdir ($ basePath .'3 ' );
152+  }
153+ 
154+  public  function  testMkdirCreatesDirectoriesFromTraversableObject ()
155+  {
156+  $ basePath  = sys_get_temp_dir ().DIRECTORY_SEPARATOR .time ();
157+  $ directories  = new  \ArrayObject (array (
158+  $ basePath .'1 ' , $ basePath .'2 ' , $ basePath .'3 ' 
159+  ));
160+ 
161+  $ filesystem  = new  Filesystem ();
162+  $ result  = $ filesystem ->mkdir ($ directories );
163+ 
164+  $ this  ->assertTrue ($ result );
165+  $ this  ->assertTrue (is_dir ($ basePath .'1 ' ));
166+  $ this  ->assertTrue (is_dir ($ basePath .'2 ' ));
167+  $ this  ->assertTrue (is_dir ($ basePath .'3 ' ));
168+ 
169+  rmdir ($ basePath .'1 ' );
170+  rmdir ($ basePath .'2 ' );
171+  rmdir ($ basePath .'3 ' );
172+  }
173+ 
174+  public  function  testMkdirCreatesDirectoriesEvenIfItFailsToCreateOneOfThem ()
175+  {
176+  $ basePath  = sys_get_temp_dir ().DIRECTORY_SEPARATOR .time ();
177+  $ directories  = array (
178+  $ basePath .'1 ' , $ basePath .'2 ' , $ basePath .'3 ' 
179+  );
180+ 
181+  // create a file to make that directory cannot be created 
182+  file_put_contents ($ basePath .'2 ' , '' );
183+ 
184+  $ filesystem  = new  Filesystem ();
185+  $ result  = $ filesystem ->mkdir ($ directories );
186+ 
187+  $ this  ->assertFalse ($ result );
188+  $ this  ->assertTrue (is_dir ($ basePath .'1 ' ));
189+  $ this  ->assertFalse (is_dir ($ basePath .'2 ' ));
190+  $ this  ->assertTrue (is_dir ($ basePath .'3 ' ));
191+ 
192+  rmdir ($ basePath .'1 ' );
193+  unlink ($ basePath .'2 ' );
194+  rmdir ($ basePath .'3 ' );
195+  }
118196}
0 commit comments