Skip to content

Commit 8018e38

Browse files
committed
Create dirs automatically if they don't exist
1 parent c88f4a4 commit 8018e38

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/BuildConfig.php

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace SymfonyDocsBuilder;
1111

1212
use Doctrine\RST\Configuration;
13+
use Symfony\Component\Filesystem\Filesystem;
1314
use Symfony\Component\Finder\Finder;
1415

1516
class BuildConfig
@@ -161,6 +162,7 @@ public function setSubdirectoryToBuild(string $contentSubDir): self
161162

162163
public function setOutputDir(string $outputDir): self
163164
{
165+
(new Filesystem())->mkdir($outputDir);
164166
if (!file_exists($outputDir)) {
165167
throw new \InvalidArgumentException(sprintf('Doc builder output directory "%s" does not exist', $outputDir));
166168
}
@@ -172,6 +174,7 @@ public function setOutputDir(string $outputDir): self
172174

173175
public function setCacheDir(string $cacheDir): self
174176
{
177+
(new Filesystem())->mkdir($cacheDir);
175178
if (!file_exists($cacheDir)) {
176179
throw new \InvalidArgumentException(sprintf('Doc builder cache directory "%s" does not exist', $cacheDir));
177180
}
@@ -187,6 +190,7 @@ public function setCacheDir(string $cacheDir): self
187190
*/
188191
public function setImagesDir(string $imagesDir): self
189192
{
193+
(new Filesystem())->mkdir($imagesDir);
190194
if (!file_exists($imagesDir)) {
191195
throw new \InvalidArgumentException(sprintf('Doc builder images directory "%s" does not exist', $imagesDir));
192196
}

tests/Command/BuildDocsCommandTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ public function testBuildDocsDefault()
5454

5555
public function testBuildDocsForPdf()
5656
{
57+
$buildConfig = $this->createBuildConfig();
58+
5759
$fs = new Filesystem();
5860
if ($fs->exists($buildConfig->getOutputDir())) {
5961
$fs->remove($buildConfig->getOutputDir());
6062
}
6163
$fs->mkdir($buildConfig->getOutputDir());
62-
63-
$buildConfig = $this->createBuildConfig();
6464

6565
$output = $this->executeCommand(
6666
$buildConfig,

0 commit comments

Comments
 (0)