Skip to content

Commit 406534c

Browse files
committed
Fix unit test error
1 parent 2829fd8 commit 406534c

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

src/PhpWord/Writer/AbstractWriter.php

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,25 @@ abstract class AbstractWriter implements WriterInterface
4949
private $diskCachingDirectory = './';
5050

5151
/**
52-
* Original file name
52+
* Temporary directory
5353
*
5454
* @var string
5555
*/
56-
private $originalFilename;
56+
private $tempDir = '';
5757

5858
/**
59-
* Temporary file name
59+
* Original file name
6060
*
6161
* @var string
6262
*/
63-
private $tempFilename;
63+
private $originalFilename;
6464

6565
/**
66-
* Temporary directory
66+
* Temporary file name
6767
*
6868
* @var string
6969
*/
70-
private $tempDir;
70+
private $tempFilename;
7171

7272
/**
7373
* Get PhpWord object
@@ -88,7 +88,7 @@ public function getPhpWord()
8888
* Set PhpWord object
8989
*
9090
* @param PhpWord
91-
* @return $this
91+
* @return self
9292
*/
9393
public function setPhpWord(PhpWord $phpWord = null)
9494
{
@@ -126,7 +126,7 @@ public function getUseDiskCaching()
126126
*
127127
* @param boolean $pValue
128128
* @param string $pDirectory
129-
* @return $this
129+
* @return self
130130
*/
131131
public function setUseDiskCaching($pValue = false, $pDirectory = null)
132132
{
@@ -153,6 +153,32 @@ public function getDiskCachingDirectory()
153153
return $this->diskCachingDirectory;
154154
}
155155

156+
/**
157+
* Get temporary directory
158+
*
159+
* @return string
160+
*/
161+
public function getTempDir()
162+
{
163+
return $this->tempDir;
164+
}
165+
166+
/**
167+
* Set temporary directory
168+
*
169+
* @param string $value
170+
* @return self
171+
*/
172+
public function setTempDir($value)
173+
{
174+
if (!is_dir($value)) {
175+
mkdir($value);
176+
}
177+
$this->tempDir = $value;
178+
179+
return $this;
180+
}
181+
156182
/**
157183
* Get temporary file name
158184
*
@@ -164,7 +190,7 @@ public function getDiskCachingDirectory()
164190
protected function getTempFile($filename)
165191
{
166192
// Temporary directory
167-
$this->setTempDir();
193+
$this->setTempDir(sys_get_temp_dir() . '/PHPWordWriter/');
168194

169195
// Temporary file
170196
$this->originalFilename = $filename;
@@ -179,26 +205,6 @@ protected function getTempFile($filename)
179205
return $this->tempFilename;
180206
}
181207

182-
/**
183-
* Get temporary directory
184-
*/
185-
protected function getTempDir()
186-
{
187-
return $this->tempDir;
188-
}
189-
190-
/**
191-
* Set temporary directory
192-
*/
193-
protected function setTempDir()
194-
{
195-
$tempDir = sys_get_temp_dir() . '/PHPWordMedia/';
196-
if (!is_dir($tempDir)) {
197-
mkdir($tempDir);
198-
}
199-
$this->tempDir = $tempDir;
200-
}
201-
202208
/**
203209
* Cleanup temporary file
204210
*/

src/PhpWord/Writer/HTML.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct(PhpWord $phpWord = null)
6060
public function save($filename = null)
6161
{
6262
if (!is_null($this->getPhpWord())) {
63-
$this->setTempDir();
63+
$this->setTempDir(sys_get_temp_dir() . '/PHPWordWriter/');
6464
$hFile = fopen($filename, 'w') or die("can't open file");
6565
fwrite($hFile, $this->writeDocument());
6666
fclose($hFile);

0 commit comments

Comments
 (0)