refactor: get the repository from the container

This commit is contained in:
Oliver Davies 2022-01-13 21:02:13 +00:00
parent 78841ad9d6
commit bc747a1f70
3 changed files with 17 additions and 6 deletions

5
.editorconfig Normal file
View file

@ -0,0 +1,5 @@
root = true
[*.yaml]
indent_style = space
indent_size = 4

View file

@ -8,20 +8,23 @@ parameters:
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
resource: "../src/*"
exclude: "../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}"
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
resource: "../src/Controller"
tags: ["controller.service_arguments"]
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
App\EventRepository:
class: App\Tests\FakeEventRepository
public: true

View file

@ -2,13 +2,16 @@
namespace App\Tests;
use App\EventRepository;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
final class FakeEventRepositoryTest extends KernelTestCase
{
/** @test */
public function should_only_return_attendees_with_a_yes_rsvp(): void {
$repository = new FakeEventRepository();
$container = self::bootKernel()->getContainer();
$repository = $container->get(EventRepository::class);
$attendees = $repository->getConfirmedAttendees();
$this->assertCount(3, $attendees->pluck('name'));