Skip to content

Commit

Permalink
Start unit/integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
terremoth committed Dec 12, 2024
1 parent 899801a commit 7e3ff61
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tests/Terremoth/AsyncTest/PhpFileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Tests\Terremoth\AsyncTest;

use Exception;
use InvalidArgumentException;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\Test;
use Terremoth\Async\PhpFile;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

class PhpFileTest extends TestCase
{
/**
* @throws Exception
*/
#[Test]
#[CoversNothing]
public function shouldOnlyAcceptPhpFiles(): void
{
$this->expectException(Exception::class);
$tempFile = tmpfile();
$htmlString = '<!DOCTYPE html><html lang="en"><body><h1>Hello World</h1></body></html>';
fwrite($tempFile, $htmlString);
$path = stream_get_meta_data($tempFile)['uri'];
$phpFile = new PhpFile($path);
$phpFile->run();
fclose($tempFile);
unlink($path);
}

/**
* @throws InvalidArgumentException|Exception
*/
#[Test]
#[CoversNothing]
public function shouldOnlyAcceptReadablePhpFiles(): void
{
$this->expectException(InvalidArgumentException::class);

if (PHP_OS_FAMILY == 'Windows') {
$this->expectException(Exception::class);
}

$tempFile = tmpfile();
$htmlString = '<!DOCTYPE html><html lang="en"><body><h1>Hello World</h1></body></html>';
fwrite($tempFile, $htmlString);
$path = stream_get_meta_data($tempFile)['uri'];
$writeAndExecOnly = 0330;
chmod($path, $writeAndExecOnly); // set as only write and exec, not readable
$phpFile = new PhpFile($path);
$phpFile->run();
fclose($tempFile);
unlink($path);
}
}

0 comments on commit 7e3ff61

Please sign in to comment.