Skip to content

Commit b63339a

Browse files
committed
[TASK] Add regression test for temp directory creation
Adds a unit test to verify that the temp directory is created before calling tempnam(), preventing the E_NOTICE regression.
1 parent 7d831c7 commit b63339a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of phpDocumentor.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*
11+
* @link https://phpdoc.org
12+
*/
13+
14+
namespace phpDocumentor\Guides\Graphs\Renderer;
15+
16+
use phpDocumentor\Guides\RenderContext;
17+
use PHPUnit\Framework\TestCase;
18+
use Psr\Log\NullLogger;
19+
20+
use function is_dir;
21+
use function rmdir;
22+
use function sys_get_temp_dir;
23+
24+
final class PlantumlRendererTest extends TestCase
25+
{
26+
/**
27+
* @runInSeparateProcess
28+
*/
29+
public function testRenderCreatesTempDirectoryWhenMissing(): void
30+
{
31+
$tempDir = sys_get_temp_dir() . '/phpdocumentor';
32+
33+
// Remove the directory if it exists to test creation
34+
if (is_dir($tempDir)) {
35+
@rmdir($tempDir);
36+
}
37+
38+
// Skip if we can't remove it (contains files from other processes)
39+
if (is_dir($tempDir)) {
40+
self::markTestSkipped('Cannot remove temp directory - it contains files from other processes');
41+
}
42+
43+
// Use a non-existent binary path - the render will fail but directory should be created first
44+
$renderer = new PlantumlRenderer(new NullLogger(), '/non/existent/plantuml');
45+
46+
$renderContext = $this->createMock(RenderContext::class);
47+
$renderContext->method('getLoggerInformation')->willReturn([]);
48+
49+
// The render will fail due to missing binary, but the temp directory should be created
50+
$renderer->render($renderContext, 'A -> B');
51+
52+
self::assertDirectoryExists($tempDir);
53+
54+
// Clean up
55+
@rmdir($tempDir);
56+
}
57+
}

0 commit comments

Comments
 (0)