You've already forked Php-Template
chore/dev-env (#6)
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m55s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m56s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m10s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 1m56s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m45s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 53s
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 1m55s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 1m56s
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m10s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 1m56s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m45s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 53s
Reviewed-on: #6 Co-authored-by: Ron Rise <ron@siteworxpro.com> Co-committed-by: Ron Rise <ron@siteworxpro.com>
This commit was merged in pull request #6.
This commit is contained in:
16
tests/Controllers/AbstractController.php
Normal file
16
tests/Controllers/AbstractController.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\Controllers;
|
||||
|
||||
use Nyholm\Psr7\ServerRequest;
|
||||
use Siteworxpro\Tests\Unit;
|
||||
|
||||
abstract class AbstractController extends Unit
|
||||
{
|
||||
protected function getMockRequest(string $method = 'GET', string $uri = '/'): ServerRequest
|
||||
{
|
||||
return new ServerRequest($method, $uri);
|
||||
}
|
||||
}
|
||||
54
tests/Controllers/ControllerTest.php
Normal file
54
tests/Controllers/ControllerTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\Controllers;
|
||||
|
||||
use Siteworxpro\App\Controllers\Controller;
|
||||
|
||||
class ControllerTest extends AbstractController
|
||||
{
|
||||
public function testNotFoundExceptions()
|
||||
{
|
||||
$testClass = new TestClass();
|
||||
|
||||
$this->expectException(\League\Route\Http\Exception\NotFoundException::class);
|
||||
$testClass->get($this->getMockRequest());
|
||||
}
|
||||
|
||||
public function testNotFoundExceptionPost()
|
||||
{
|
||||
$testClass = new TestClass();
|
||||
|
||||
$this->expectException(\League\Route\Http\Exception\NotFoundException::class);
|
||||
$testClass->post($this->getMockRequest());
|
||||
}
|
||||
|
||||
public function testNotFoundExceptionPut()
|
||||
{
|
||||
$testClass = new TestClass();
|
||||
|
||||
$this->expectException(\League\Route\Http\Exception\NotFoundException::class);
|
||||
$testClass->put($this->getMockRequest());
|
||||
}
|
||||
|
||||
public function testNotFoundExceptionDelete()
|
||||
{
|
||||
$testClass = new TestClass();
|
||||
|
||||
$this->expectException(\League\Route\Http\Exception\NotFoundException::class);
|
||||
$testClass->delete($this->getMockRequest());
|
||||
}
|
||||
|
||||
public function testNotFoundExceptionPatch()
|
||||
{
|
||||
$testClass = new TestClass();
|
||||
|
||||
$this->expectException(\League\Route\Http\Exception\NotFoundException::class);
|
||||
$testClass->patch($this->getMockRequest());
|
||||
}
|
||||
}
|
||||
|
||||
class TestClass extends Controller // phpcs:ignore
|
||||
{
|
||||
}
|
||||
25
tests/Controllers/IndexControllerTest.php
Normal file
25
tests/Controllers/IndexControllerTest.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\Controllers;
|
||||
|
||||
use Siteworxpro\App\Controllers\IndexController;
|
||||
|
||||
class IndexControllerTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public function testGet(): void
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
|
||||
$controller = new IndexController();
|
||||
|
||||
$response = $controller->get($this->getMockRequest());
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertEquals('{"status_code":200,"message":"Server is running"}', (string)$response->getBody());
|
||||
}
|
||||
}
|
||||
32
tests/Facades/AbstractFacade.php
Normal file
32
tests/Facades/AbstractFacade.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\Facades;
|
||||
|
||||
use Siteworxpro\App\Services\Facade;
|
||||
use Siteworxpro\Tests\Unit;
|
||||
|
||||
abstract class AbstractFacade extends Unit
|
||||
{
|
||||
abstract protected function getFacadeClass(): string;
|
||||
abstract protected function getConcrete(): string;
|
||||
|
||||
public function testFacadeAccessor(): void
|
||||
{
|
||||
/** @var Facade | string $class */
|
||||
$class = $this->getFacadeClass();
|
||||
|
||||
$this->assertTrue(
|
||||
method_exists($class, 'getFacadeAccessor'),
|
||||
sprintf('The class %s must implement the method getFacadeAccessor.', $class)
|
||||
);
|
||||
|
||||
$facade = $class::getFacadeRoot();
|
||||
|
||||
$this->assertNotNull(
|
||||
$facade,
|
||||
sprintf('The facade %s is not properly initialized.', $this->getConcrete())
|
||||
);
|
||||
}
|
||||
}
|
||||
21
tests/Facades/RedisTest.php
Normal file
21
tests/Facades/RedisTest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\Facades;
|
||||
|
||||
use Predis\Client;
|
||||
use Siteworxpro\App\Services\Facades\Redis;
|
||||
|
||||
class RedisTest extends AbstractFacade
|
||||
{
|
||||
protected function getFacadeClass(): string
|
||||
{
|
||||
return Redis::class;
|
||||
}
|
||||
|
||||
protected function getConcrete(): string
|
||||
{
|
||||
return Client::class;
|
||||
}
|
||||
}
|
||||
43
tests/ServiceProviders/AbstractServiceProvider.php
Normal file
43
tests/ServiceProviders/AbstractServiceProvider.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\ServiceProviders;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Siteworxpro\Tests\Unit;
|
||||
|
||||
abstract class AbstractServiceProvider extends Unit
|
||||
{
|
||||
abstract protected function getProviderClass(): string;
|
||||
|
||||
/**
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
public function testProvider(): void
|
||||
{
|
||||
$container = new Container();
|
||||
|
||||
$providerClass = $this->getProviderClass();
|
||||
|
||||
/** @var ServiceProvider $providerClass */
|
||||
$provider = new $providerClass($container);
|
||||
|
||||
$this->assertInstanceOf($providerClass, $provider);
|
||||
$provider->register();
|
||||
|
||||
$bindings = $provider->bindings;
|
||||
foreach ($bindings as $abstract => $concrete) {
|
||||
$this->assertTrue($container->bound($abstract), "The $abstract is not bound in the container.");
|
||||
$this->assertNotNull($container->make($abstract), "The $abstract could not be resolved.");
|
||||
|
||||
$this->assertInstanceOf(
|
||||
$concrete,
|
||||
$container->make($abstract),
|
||||
"The $abstract is not an instance of $concrete."
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
tests/ServiceProviders/LoggerServiceProviderTest.php
Normal file
15
tests/ServiceProviders/LoggerServiceProviderTest.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\ServiceProviders;
|
||||
|
||||
use Siteworxpro\App\Services\ServiceProviders\LoggerServiceProvider;
|
||||
|
||||
class LoggerServiceProviderTest extends AbstractServiceProvider
|
||||
{
|
||||
protected function getProviderClass(): string
|
||||
{
|
||||
return LoggerServiceProvider::class;
|
||||
}
|
||||
}
|
||||
15
tests/ServiceProviders/RedisServiceProviderTest.php
Normal file
15
tests/ServiceProviders/RedisServiceProviderTest.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\ServiceProviders;
|
||||
|
||||
use Siteworxpro\App\Services\ServiceProviders\RedisServiceProvider;
|
||||
|
||||
class RedisServiceProviderTest extends AbstractServiceProvider
|
||||
{
|
||||
protected function getProviderClass(): string
|
||||
{
|
||||
return RedisServiceProvider::class;
|
||||
}
|
||||
}
|
||||
@@ -5,21 +5,29 @@ declare(strict_types=1);
|
||||
namespace Siteworxpro\Tests;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Siteworx\Config\Config as SWConfig;
|
||||
use Siteworxpro\App\Services\Facade;
|
||||
use Siteworxpro\App\Services\Facades\Config;
|
||||
|
||||
abstract class Unit extends TestCase
|
||||
{
|
||||
/**
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$container = new Container();
|
||||
Facade::setFacadeApplication($container);
|
||||
Facade::setFacadeContainer($container);
|
||||
|
||||
$container->bind(SWConfig::class, function () {
|
||||
return SWConfig::load(__DIR__ . '/../config.php');
|
||||
});
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Config::clearResolvedInstances();
|
||||
Facade::setFacadeApplication(null);
|
||||
Facade::setFacadeContainer(null);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user