Skip to content

Commit

Permalink
Ready for projection tests
Browse files Browse the repository at this point in the history
  • Loading branch information
galeaspablo committed Sep 17, 2024
1 parent f8121fc commit f9dc205
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
1 change: 0 additions & 1 deletion application/monolith/code/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ services:
### EVENT STORE ####

Galeas\Api\Service\EventStore\SQLEventStoreConnection:
public: true # so it's available in our kernel tests
class: Galeas\Api\Service\EventStore\SQLEventStoreConnection
arguments:
- '%event_store_database_name%'
Expand Down
43 changes: 43 additions & 0 deletions application/monolith/code/config/services_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
services: # default configuration for services in *this* file
_defaults:
# automatically injects dependencies in your services
autowire: true
# automatically registers your services as commands, event subscribers, etc.
autoconfigure: false
# false means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
bind:
$eventStore: '@Galeas\Api\Service\EventStore\SQLEventStore'
$reactionDocumentManager: '@doctrine_mongodb.odm.reaction_document_manager'
$projectionDocumentManager: '@doctrine_mongodb.odm.projection_document_manager'
Galeas\Api\Service\EventStore\SQLEventStoreConnection:
public: true
class: Galeas\Api\Service\EventStore\SQLEventStoreConnection
arguments:
- '%event_store_database_name%'
- '%event_store_database_host%'
- '%event_store_database_port%'
- '%event_store_database_user%'
- '%event_store_database_password%'
Galeas\Api\Service\ODM\DocumentManagerForTests:
public: true
class: Galeas\Api\Service\ODM\DocumentManagerForTests
galeas.bounded_context_services:
public: true
namespace: Galeas\Api\BoundedContext\
resource: '../src/BoundedContext/'
_instanceof:
Galeas\Api\Common\Controller\BaseController:
calls:
- setJsonPostRequestMapper: [ '@Galeas\Api\Service\RequestMapper\JsonPostRequestMapper' ]
- setJsonSchemaFetcher: [ '@Galeas\Api\JsonSchema\JsonSchemaFetcher' ]
- setJsonSchemaValidator: [ '@Galeas\Api\JsonSchema\JsonSchemaValidator' ]
- setPhpOutLogger: [ '@Galeas\Api\Service\Logger\PhpOutLogger' ]
Symfony\Bundle\FrameworkBundle\Controller\AbstractController:
# Handlers and their dependencies will only be testable if they're in the test container.
# For this to be true at least one public service has to use them. Controllers will do the job.
public: true
tags: [ 'controller.service_arguments' ]
calls:
- [ 'setContainer', [ '@service_container' ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Galeas\Api\Service\ODM;


use Doctrine\ODM\MongoDB\DocumentManager;

class DocumentManagerForTests {
private DocumentManager $projectionDocumentManager;
private DocumentManager $reactionDocumentManager;
public function __construct($projectionDocumentManager, $reactionDocumentManager)
{
$this->projectionDocumentManager = $projectionDocumentManager;
$this->reactionDocumentManager = $reactionDocumentManager;
}

public function projectionDocumentManager(): DocumentManager
{
return $this->projectionDocumentManager;
}

public function reactionDocumentManager(): DocumentManager
{
return $this->reactionDocumentManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\ODM\MongoDB\DocumentManager;
use Galeas\Api\Kernel;
use Galeas\Api\Service\EventStore\SQLEventStoreConnection;
use Galeas\Api\Service\ODM\DocumentManagerForTests;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -67,12 +68,16 @@ protected function getContainer(): Container

protected function getProjectionDocumentManager(): DocumentManager
{
return $this->container->get('doctrine_mongodb.odm.projection_document_manager');
/** @var DocumentManagerForTests $documentManagerForTests */
$documentManagerForTests = $this->container->get(DocumentManagerForTests::class);
return $documentManagerForTests->projectionDocumentManager();
}

protected function getReactionDocumentManager(): DocumentManager
{
return $this->container->get('doctrine_mongodb.odm.reaction_document_manager');
/** @var DocumentManagerForTests $documentManagerForTests */
$documentManagerForTests = $this->container->get(DocumentManagerForTests::class);
return $documentManagerForTests->reactionDocumentManager();
}

protected function getEventStoreConnection(): Connection
Expand Down

0 comments on commit f9dc205

Please sign in to comment.