Skip to content

Commit

Permalink
Add some more things
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Kąkol committed Apr 19, 2024
1 parent ba3332c commit 9d55a4b
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 47 deletions.
5 changes: 5 additions & 0 deletions config/services_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use DualMedia\DoctrineEventConverterBundle\Service\EventService;
use DualMedia\DoctrineEventConverterBundle\Service\SubEventService;
use DualMedia\DoctrineEventConverterBundle\Tests\Fixtures\Doctrine\EntityFixtures;

return static function (ContainerConfigurator $container) {
$services = $container->services()
->defaults()
->public();

$services->set(EventService::class);
$services->set(SubEventService::class);

$services->set(EntityFixtures::class)->tag('doctrine.fixture.orm');
};
24 changes: 0 additions & 24 deletions src/EventSubscriber/DispatchingSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public function getSubscribedEvents(): array
];
}

/**
* @internal
*/
public function prePersist(
PrePersistEventArgs $args
): void {
Expand All @@ -73,37 +70,25 @@ public function prePersist(
}
}

/**
* @internal
*/
public function preFlush(
PreFlushEventArgs $args
): void {
$this->preFlush = true;
}

/**
* @internal
*/
public function postFlush(
PostFlushEventArgs $args
): void {
$this->dispatcher->submitDelayed();
$this->preFlush = false;
}

/**
* @internal
*/
public function postPersist(
PostPersistEventArgs $args
): void {
$this->process(Events::postPersist, $args->getObject());
}

/**
* @internal
*/
public function preUpdate(
PreUpdateEventArgs $args
): void {
Expand All @@ -116,9 +101,6 @@ public function preUpdate(
$this->process(Events::preUpdate, $object, null, $changes);
}

/**
* @internal
*/
public function postUpdate(
PostUpdateEventArgs $args
): void {
Expand All @@ -130,9 +112,6 @@ public function postUpdate(
$this->process(Events::postUpdate, $object, null, $changes);
}

/**
* @internal
*/
public function preRemove(
PreRemoveEventArgs $args
): void {
Expand All @@ -144,9 +123,6 @@ public function preRemove(
$this->process(Events::preRemove, $object);
}

/**
* @internal
*/
public function postRemove(
PostRemoveEventArgs $args
): void {
Expand Down
2 changes: 0 additions & 2 deletions tests/DependencyInjection/CompilerPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use DualMedia\DoctrineEventConverterBundle\DependencyInjection\CompilerPass\EventDetectionCompilerPass;
use DualMedia\DoctrineEventConverterBundle\DoctrineEventConverterBundle;
use DualMedia\DoctrineEventConverterBundle\Event\AbstractEntityEvent;
use DualMedia\DoctrineEventConverterBundle\EventSubscriber\DispatchingSubscriber;
use DualMedia\DoctrineEventConverterBundle\Exception\DependencyInjection\AbstractEntityEventNotExtendedException;
use DualMedia\DoctrineEventConverterBundle\Exception\DependencyInjection\EntityInterfaceMissingException;
use DualMedia\DoctrineEventConverterBundle\Exception\DependencyInjection\NoValidEntityFoundException;
Expand All @@ -28,7 +27,6 @@
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\EventDispatcher\EventDispatcher;

/**
Expand Down
21 changes: 10 additions & 11 deletions tests/Integration/ValidCompileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DualMedia\DoctrineEventConverterBundle\DoctrineEventConverterBundle;
use DualMedia\DoctrineEventConverterBundle\EventSubscriber\DispatchingSubscriber;
use DualMedia\DoctrineEventConverterBundle\Model\Event;
use DualMedia\DoctrineEventConverterBundle\Service\EventService;
use DualMedia\DoctrineEventConverterBundle\Tests\Fixtures\Entity\ComplexEntity;
use DualMedia\DoctrineEventConverterBundle\Tests\Fixtures\Entity\Item;
use DualMedia\DoctrineEventConverterBundle\Tests\Fixtures\Event\ComplexEntityEvent;
Expand All @@ -22,11 +23,12 @@
use DualMedia\DoctrineEventConverterProxy\DualMedia\DoctrineEventConverterBundle\Tests\Fixtures\Event\ItemPrePersistEvent;
use DualMedia\DoctrineEventConverterProxy\DualMedia\DoctrineEventConverterBundle\Tests\Fixtures\Event\ItemPreRemoveEvent;
use DualMedia\DoctrineEventConverterProxy\DualMedia\DoctrineEventConverterBundle\Tests\Fixtures\Event\ItemPreUpdateEvent;
use PHPUnit\Framework\Attributes\Depends;
use Symfony\Component\Finder\Finder;

class ValidCompileTest extends KernelTestCase
{
public function testGeneration()
public function testGeneration(): void
{
$this->assertFileExists(
$this->getProxyClassPath(ItemEvent::class, Events::prePersist),
Expand Down Expand Up @@ -80,10 +82,8 @@ public function testGeneration()
);
}

/**
* @depends testGeneration
*/
public function testAutoload()
#[Depends('testGeneration')]
public function testAutoload(): void
{
// ItemEvent
$this->assertTrue(class_exists(ItemPrePersistEvent::class));
Expand All @@ -100,12 +100,11 @@ public function testAutoload()
$this->assertTrue(class_exists(ComplexEntityStatusChangedPrePersistEvent::class));
}

/**
* @depends testGeneration
*/
public function testCorrectContainerDefinitions()
#[Depends('testGeneration')]
public function testCorrectContainerDefinitions(): void
{
$subscriber = $this->getContainer()->get(DispatchingSubscriber::class);
$service = $this->getContainer()->get(EventService::class);
/** @var EventService $service */

$list = [
Events::postPersist => [
Expand Down Expand Up @@ -150,7 +149,7 @@ public function testCorrectContainerDefinitions()
foreach ($entityList as $entity => $events) {
$this->checkArrayWithoutOrderImportance(
$events,
$subscriber->getEvents($event, $entity)
$service->get($event, $entity)
);
}
}
Expand Down
14 changes: 5 additions & 9 deletions tests/KernelTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ protected function getProxyClassPath(
string $class,
string $eventType
): string {
return $this->getContainer()->get(Generator::class)->resolveFilePath(Generator::getProxyFqcn($class, $eventType));
return $this->getContainer()->get(Generator::class)->resolveFilePath(Generator::getProxyFqcn($class, $eventType)); // @phpstan-ignore-line
}

protected function getItemRepo(): EntityRepository
{
return $this->getContainer()->get('doctrine')->getManager()->getRepository(Item::class);
return $this->getContainer()->get('doctrine')->getManager()->getRepository(Item::class); // @phpstan-ignore-line
}

protected function getComplexRepo(): EntityRepository
{
return $this->getContainer()->get('doctrine')->getManager()->getRepository(ComplexEntity::class);
return $this->getContainer()->get('doctrine')->getManager()->getRepository(ComplexEntity::class); // @phpstan-ignore-line
}

protected function getManager(): ObjectManager
{
return $this->getContainer()->get('doctrine')->getManager();
return $this->getContainer()->get('doctrine')->getManager(); // @phpstan-ignore-line
}

protected function getEventDispatcher(): EventDispatcherInterface
{
return $this->getContainer()->get('event_dispatcher');
return $this->getContainer()->get('event_dispatcher'); // @phpstan-ignore-line
}

/**
Expand Down Expand Up @@ -101,10 +101,6 @@ protected function addMappedListeners(

protected function clearListeners(): void
{
if (null === $this->getEventDispatcher()) {
return;
}

foreach ($this->listeners as $event => $listeners) {
foreach ($listeners as $listener) {
$this->getEventDispatcher()->removeListener(
Expand Down
6 changes: 5 additions & 1 deletion tests/Service/EventServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ class EventServiceTest extends TestCase
{
use ServiceMockHelperTrait;

private EventService $service;

protected function setUp(): void
{
$this->service = $this->createRealMockedServiceInstance(EventService::class);
$this->service = $this->createRealMockedServiceInstance(EventService::class, [
'entries' => [],
]);
}

public function test(): void
Expand Down

0 comments on commit 9d55a4b

Please sign in to comment.