-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
467 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,6 @@ | |
# Project | ||
/vendor/ | ||
/config/config.php | ||
|
||
/config/config.testing.php | ||
/phpunit.xml | ||
/.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd" | ||
bootstrap="./tests/bootstrap.php" | ||
colors="true" | ||
> | ||
|
||
<testsuites> | ||
<testsuite name="Pile Feature Tests"> | ||
<directory>./tests/Feature</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
<source> | ||
<include> | ||
<directory>./src/</directory> | ||
</include> | ||
</source> | ||
|
||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bloatless\Pile\Tests\Doubles; | ||
|
||
use Bloatless\Pile\Pile; | ||
|
||
class PileDouble extends Pile | ||
{ | ||
protected string $requestBody = ''; | ||
|
||
public function setRequestBody(string $requestBody): void | ||
{ | ||
$this->requestBody = $requestBody; | ||
} | ||
|
||
protected function getRequestBody(): string | ||
{ | ||
return $this->requestBody; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bloatless\Pile\Tests\Feature; | ||
|
||
use Bloatless\Pile\Pile; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ApplicationTest extends TestCase | ||
{ | ||
public function testAppCanBeInitialized() | ||
{ | ||
$config = include PATH_ROOT . '/config/config.testing.php'; | ||
$app = new Pile($config); | ||
$this->assertInstanceOf(Pile::class, $app); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bloatless\Pile\Tests\Feature; | ||
|
||
use Bloatless\Pile\Tests\Doubles\PileDouble; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AuthorizationTest extends TestCase | ||
{ | ||
public function testHomepageRequiresAuthorization() | ||
{ | ||
$config = include PATH_ROOT . '/config/config.testing.php'; | ||
$app = new PileDouble($config); | ||
|
||
$response = $app->__invoke([], [ | ||
'REQUEST_METHOD' => 'GET', | ||
'REQUEST_URI' => '/', | ||
]); | ||
|
||
$this->assertStringContainsString('Authorization required.', $response); | ||
} | ||
|
||
public function testLoginIsPossibleWithValidCredentials() | ||
{ | ||
$config = include PATH_ROOT . '/config/config.testing.php'; | ||
$app = new PileDouble($config); | ||
|
||
$response = $app->__invoke([], [ | ||
'REQUEST_METHOD' => 'GET', | ||
'REQUEST_URI' => '/', | ||
'HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('foo:bar'), | ||
]); | ||
|
||
$this->assertStringContainsString('<div class="container">', $response); | ||
} | ||
|
||
public function testLoginIsNotPossibleWithInvalidCredentials() | ||
{ | ||
$config = include PATH_ROOT . '/config/config.testing.php'; | ||
$app = new PileDouble($config); | ||
|
||
$response = $app->__invoke([], [ | ||
'REQUEST_METHOD' => 'GET', | ||
'REQUEST_URI' => '/', | ||
'HTTP_AUTHORIZATION' => 'Basic ' . base64_encode('foo:baz'), | ||
]); | ||
|
||
$this->assertStringContainsString('Authorization required.', $response); | ||
} | ||
|
||
public function testApiRequestIsPossibleWithValidKey() | ||
{ | ||
$config = include PATH_ROOT . '/config/config.testing.php'; | ||
$app = new PileDouble($config); | ||
$app->setRequestBody('[]'); | ||
|
||
$response = $app->__invoke([], [ | ||
'REQUEST_METHOD' => 'POST', | ||
'REQUEST_URI' => '/api/v1/log', | ||
'HTTP_X_API_KEY' => '123123123', | ||
]); | ||
|
||
$this->assertStringContainsString('Error: Invalid data', $response); | ||
} | ||
|
||
public function testApiRequestIsNotPossibleWithInvalidKey() | ||
{ | ||
$config = include PATH_ROOT . '/config/config.testing.php'; | ||
$app = new PileDouble($config); | ||
|
||
$response = $app->__invoke([], [ | ||
'REQUEST_METHOD' => 'POST', | ||
'REQUEST_URI' => '/api/v1/log', | ||
'HTTP_X_API_KEY' => 'non-existent-key', | ||
]); | ||
|
||
$this->assertStringContainsString('Error 401: Unauthorized', $response); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bloatless\Pile\Tests\Feature; | ||
|
||
use Bloatless\Pile\Pile; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class ConfigurationTest extends TestCase | ||
{ | ||
public function testDbConfigurationIsValidated() | ||
{ | ||
$config = include PATH_ROOT . '/config/config.testing.php'; | ||
|
||
unset($config['db']['dsn']); | ||
$app = new Pile($config); | ||
$response = $app->__invoke([], []); | ||
$this->assertStringContainsString('Invalid database configuration', $response); | ||
|
||
unset($config['db']); | ||
$app = new Pile($config); | ||
$response = $app->__invoke([], []); | ||
$this->assertStringContainsString('Database configuration missing', $response); | ||
} | ||
|
||
public function testAuthConfigurationIsValidated() | ||
{ | ||
$config = include PATH_ROOT . '/config/config.testing.php'; | ||
|
||
unset($config['auth']['users']); | ||
$app = new Pile($config); | ||
$response = $app->__invoke([], []); | ||
$this->assertStringContainsString('Auth configuration is invalid', $response); | ||
|
||
unset($config['auth']); | ||
$app = new Pile($config); | ||
$response = $app->__invoke([], []); | ||
$this->assertStringContainsString('Auth configuration missing', $response); | ||
} | ||
|
||
public function testViewConfigurationIsValidated() | ||
{ | ||
$config = include PATH_ROOT . '/config/config.testing.php'; | ||
|
||
unset($config['path_views']); | ||
$app = new Pile($config); | ||
$response = $app->__invoke([], []); | ||
$this->assertStringContainsString('Path to views missing in config', $response); | ||
|
||
$config['path_views'] = 'non_existent_path'; | ||
$app = new Pile($config); | ||
$response = $app->__invoke([], []); | ||
$this->assertStringContainsString('Paths to views is invalid', $response); | ||
} | ||
} |
Oops, something went wrong.