mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-09-02 02:12:37 +02:00
Added initial unit tests
This commit is contained in:
13
phpunit.xml
Normal file
13
phpunit.xml
Normal file
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit bootstrap="vendor/autoload.php" colors="true">
|
||||
<testsuites>
|
||||
<testsuite name="Directory Lister Test Suite">
|
||||
<directory suffix="Test.php">tests/</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
<filter>
|
||||
<whitelist processUncoveredFilesFromWhitelist="true">
|
||||
<directory suffix=".php">src/</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
</phpunit>
|
30
tests/Unit/Controllers/DirectoryControllerTest.php
Normal file
30
tests/Unit/Controllers/DirectoryControllerTest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Controllers;
|
||||
|
||||
use App\Controllers\DirectoryController;
|
||||
use PHLAK\Config\Config;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Slim\Psr7\Response;
|
||||
use Slim\Views\Twig;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
class DirectoryControllerTest extends TestCase
|
||||
{
|
||||
public function test_it_returns_a_response()
|
||||
{
|
||||
$controller = new DirectoryController(
|
||||
$this->createMock(Config::class),
|
||||
$this->createMock(Twig::class)
|
||||
);
|
||||
|
||||
$response = $controller(
|
||||
$this->createMock(Finder::class),
|
||||
$this->createMock(Response::class),
|
||||
'tests/files'
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(ResponseInterface::class, $response);
|
||||
}
|
||||
}
|
49
tests/Unit/Support/HelpersTest.php
Normal file
49
tests/Unit/Support/HelpersTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Support;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class HelpersTest extends TestCase
|
||||
{
|
||||
public function test_it_can_get_an_environment_variable()
|
||||
{
|
||||
putenv('TEST_STRING=Test string; please ignore');
|
||||
|
||||
$env = env('TEST_STRING');
|
||||
|
||||
$this->assertEquals('Test string; please ignore', $env);
|
||||
}
|
||||
|
||||
public function test_it_can_return_a_default_value()
|
||||
{
|
||||
$env = env('DEFAULT_TEST', 'Test default; please ignore');
|
||||
|
||||
$this->assertEquals('Test default; please ignore', $env);
|
||||
}
|
||||
|
||||
public function test_it_can_a_retrieve_boolean_value()
|
||||
{
|
||||
putenv('TRUE_TEST=true');
|
||||
putenv('FALSE_TEST=false');
|
||||
|
||||
$this->assertTrue(env('TRUE_TEST'));
|
||||
$this->assertFalse(env('FALSE_TEST'));
|
||||
}
|
||||
|
||||
public function test_it_can_retrieve_a_null_value()
|
||||
{
|
||||
putenv('NULL_TEST=null');
|
||||
|
||||
$this->assertNull(env('NULL_TEST'));
|
||||
}
|
||||
|
||||
public function test_it_can_be_surrounded_bys_quotation_marks()
|
||||
{
|
||||
putenv('QUOTES_TEST="Test charlie; please ignore"');
|
||||
|
||||
$env = env('QUOTES_TEST');
|
||||
|
||||
$this->assertEquals('Test charlie; please ignore', $env);
|
||||
}
|
||||
}
|
1
tests/files/test.txt
Normal file
1
tests/files/test.txt
Normal file
@@ -0,0 +1 @@
|
||||
Test file; please ignore
|
Reference in New Issue
Block a user