You've already forked Php-Template
feat: enhance service providers with provides method and integrate command bus in handlers
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m40s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m42s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m53s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m55s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 2m42s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m24s
All checks were successful
🧪✨ Tests Workflow / 🛡️ 🔒 License Check (push) Successful in 2m40s
🧪✨ Tests Workflow / 📝 ✨ Code Lint (push) Successful in 2m42s
🧪✨ Tests Workflow / 🛡️ 🔒 Library Audit (push) Successful in 2m53s
🧪✨ Tests Workflow / 🧪 ✨ Database Migrations (push) Successful in 2m55s
🧪✨ Tests Workflow / 🐙 🔍 Code Sniffer (push) Successful in 2m42s
🧪✨ Tests Workflow / 🧪 ✅ Unit Tests (push) Successful in 1m24s
This commit is contained in:
@@ -4,23 +4,31 @@ declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\Controllers;
|
||||
|
||||
use League\Tactician\CommandBus;
|
||||
use Siteworxpro\App\Controllers\IndexController;
|
||||
|
||||
class IndexControllerTest extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @throws \JsonException
|
||||
* @throws \JsonException|\ReflectionException
|
||||
*/
|
||||
public function testGet(): void
|
||||
{
|
||||
$this->assertTrue(true);
|
||||
|
||||
$this->getContainer()->bind(CommandBus::class, function () {
|
||||
return \Mockery::mock(CommandBus::class)
|
||||
->shouldReceive('handle')
|
||||
->andReturn('Hello World')
|
||||
->getMock();
|
||||
});
|
||||
|
||||
$controller = new IndexController();
|
||||
|
||||
$response = $controller->get($this->getMockRequest());
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertEquals('{"message":"Server is running"}', (string)$response->getBody());
|
||||
$this->assertEquals('{"message":"Server is running. Hello World"}', (string)$response->getBody());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,19 +4,32 @@ declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\GrpcHandlers;
|
||||
|
||||
use GRPC\Greeter\HelloRequest;
|
||||
use League\Tactician\CommandBus;
|
||||
use Siteworxpro\App\GrpcHandlers\GreeterHandler;
|
||||
use Siteworxpro\Tests\Unit;
|
||||
use Spiral\RoadRunner\GRPC\ContextInterface;
|
||||
|
||||
class GreeterHandlerTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @throws \ReflectionException
|
||||
*/
|
||||
public function testSayHello(): void
|
||||
{
|
||||
$request = new \GRPC\Greeter\HelloRequest();
|
||||
$this->getContainer()->bind(CommandBus::class, function () {
|
||||
return \Mockery::mock(CommandBus::class)
|
||||
->shouldReceive('handle')
|
||||
->andReturn('Hello World')
|
||||
->getMock();
|
||||
});
|
||||
|
||||
$request = new HelloRequest();
|
||||
$request->setName('World');
|
||||
|
||||
$context = \Mockery::mock(ContextInterface::class);
|
||||
|
||||
$handler = new \Siteworxpro\App\GrpcHandlers\GreeterHandler();
|
||||
$handler = new GreeterHandler();
|
||||
$response = $handler->SayHello($context, $request);
|
||||
$this->assertEquals('Hello World', $response->getMessage());
|
||||
}
|
||||
|
||||
@@ -28,16 +28,16 @@ abstract class AbstractServiceProvider extends Unit
|
||||
$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.");
|
||||
$abstract = $provider->provides()[0];
|
||||
$concrete = get_class($container->make($abstract));
|
||||
|
||||
$this->assertInstanceOf(
|
||||
$concrete,
|
||||
$container->make($abstract),
|
||||
"The $abstract is not an instance of $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/CommandBusServiceProviderTest.php
Normal file
15
tests/ServiceProviders/CommandBusServiceProviderTest.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests\ServiceProviders;
|
||||
|
||||
use Siteworxpro\App\Services\ServiceProviders\CommandBusProvider;
|
||||
|
||||
class CommandBusServiceProviderTest extends AbstractServiceProvider
|
||||
{
|
||||
protected function getProviderClass(): string
|
||||
{
|
||||
return CommandBusProvider::class;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use Illuminate\Container\Container;
|
||||
use Mockery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Siteworx\Config\Config as SWConfig;
|
||||
use Siteworxpro\App\Kernel;
|
||||
use Siteworxpro\App\Services\Facade;
|
||||
use Siteworxpro\App\Services\Facades\Config;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user