Skip to content

Commit

Permalink
Merge pull request #22 from swagindustries/feature/prepare-version-3
Browse files Browse the repository at this point in the history
✨ Prepare version 3
  • Loading branch information
Nek- authored Aug 1, 2024
2 parents 6275a32 + 84543a3 commit 9f03bca
Show file tree
Hide file tree
Showing 35 changed files with 198 additions and 825 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added

- Complete support for Symfony 7
- Support for Doctrine ORM 3
- Remove limitations on usage on proxies! :tada:

### Changed

- New way of injecting the dispatcher to entities. This is great and also supports proxies! (which was previously a limitation)
- The easy crew got us! The configuration is now deadly simple. Look at the UPGRADE guide to learn how to move from v2 to v3.

## [2.3.3] - 2023-05-16

### Added
Expand Down
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@ As your model needs a dispatcher you need to call the `setDispatcher()` method a

> It doesn't use the constructor to add the dispatcher because in PHP you can create objects without the constructor. For instance, that's what Doctrine does.
```php
use Biig\Component\Domain\Model\Instantiator\Instantiator;
use Doctrine\ORM\EntityManager;

class SomeController
{
public function index(Instantiator $instantiator, EntityManager $entityManager)
{
$model = $instantiator->instantiate(YourModel::class);
$entityManager->persist($model);
$entityManager->flush();
}
}
```

Integration to Symfony
----------------------

Expand All @@ -98,10 +113,13 @@ Learn more about [Symfony Integration](/docs/domain_event_dispatcher.md#symfony-
Versions
--------

| Version | Status | Documentation | Symfony Version | PHP Version |
|---------|------------|---------------| --------------- | ------------|
| 1.x | Maintained | [v1][v1-doc] | '>= 3.3 && <5' | '>= 7.1' |
| 2.x | Latest | [v2][v2-doc] | '>= 4.3' | '>= 7.1' |
| Version | Status | Documentation | Symfony Version | PHP Version | Misc |
|---------|--------------|---------------|-----------------|-------------|---------------------------------|
| 1.x | Unmaintained | [v1][v1-doc] | >= 3.3 && <5 | >= 7.1 | |
| 2.x | Maintained | [v2][v2-doc] | >= 4.3 | >= 7.4 | |
| 3.x | Latest | [v3][v3-doc] | >= 5.4 | >= 8.1 | See [UPGRADE](v3-upgrade) guide |

[v1-doc]: https://github.com/biig-io/DomainComponent/tree/v1
[v2-doc]: https://github.com/biig-io/DomainComponent
[v1-doc]: https://github.com/swagindustries/doctrine-domain-events/tree/v1.5.2/docs
[v2-doc]: https://github.com/swagindustries/doctrine-domain-events/tree/v2.3.3/docs
[v3-docs]: https://github.com/swagindustries/doctrine-domain-events/tree/master/docs
[v3-upgrade]: https://github.com/swagindustries/doctrine-domain-events/tree/master/UPGRADE.md
3 changes: 1 addition & 2 deletions Tests/Event/DelayedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Biig\Component\Domain\Event\DomainEventDispatcher;
use Biig\Component\Domain\Exception\InvalidDomainEvent;
use Biig\Component\Domain\Model\DomainModel;
use Biig\Component\Domain\PostPersistListener\DoctrinePostPersistListener;
use Biig\Component\Domain\Rule\PostPersistDomainRuleInterface;
use Biig\Component\Domain\Tests\fixtures\Entity\FakeModel;
use Biig\Component\Domain\Tests\SetupDatabaseTrait;
Expand Down Expand Up @@ -103,7 +102,7 @@ public function testItDoesNotExecuteManyTimesSameEvent()
{
// Test setup
$dispatcher = new DomainEventDispatcher();
$entityManager = $this->setupDatabase($dispatcher, 'testItInsertInBddAfterFlushing');
$entityManager = $this->setupDatabase($dispatcher, 'testItDoesNotExecuteManyTimesSameEvent');

$model = new FakeModel();
$model->setFoo(0);
Expand Down

This file was deleted.

56 changes: 0 additions & 56 deletions Tests/Model/Instantiator/DoctrineConfig/ClassMetadataTest.php

This file was deleted.

28 changes: 0 additions & 28 deletions Tests/Model/Instantiator/DoctrineConfig/InstantiatorTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function testAnEntityThatDoesntHaveDispatcherWhileFlushedThrowAnError()
{
self::bootKernel(['debug' => true]);
// You should not create your entites this way in your own code !
// Use the Biig\Component\Domain\Model\Instantiator\Instantiator service to instanciate your entities.
// Use the Biig\Component\Domain\Model\Instantiator\Instantiator service to instantiate your entities.
$model = new FakeModel();

$this->expectException(FlushedEntityDoesntContainsDispatcherException::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testItCallPersistForEachFlushedModel()
$entityManager = $this->prophesize(EntityManager::class);
$entityManager->getUnitOfWork()->willReturn($unitOfWork->reveal());
$onFlushEvent = $this->prophesize(OnFlushEventArgs::class);
$onFlushEvent->getEntityManager()->willReturn($entityManager->reveal());
$onFlushEvent->getObjectManager()->willReturn($entityManager->reveal());

$postPersistListener = new DoctrinePostPersistListener($dispatcher->reveal());
$postPersistListener->onFlush($onFlushEvent->reveal());
Expand Down
7 changes: 2 additions & 5 deletions Tests/SetupDatabaseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@ private function setupDatabase(DomainEventDispatcherInterface $dispatcher, strin
copy(__DIR__ . '/fixtures/dbtest/initial_fake_model.db', $this->dbPath);

$config = ORMSetup::createAttributeMetadataConfiguration(array(__DIR__ . '/../fixtures/Entity'), true);
$config->setClassMetadataFactoryName(ClassMetadataFactory::class);
$conn = [
'driver' => 'pdo_sqlite',
'path' => $this->dbPath,
];

$entityManager = EntityManager::create($conn, $config);
$entityManager->getEventManager()->addEventSubscriber(new DoctrinePostPersistListener($dispatcher));
$entityManager->getEventManager()->addEventSubscriber(new PostLoadDispatcherInjectionListener($dispatcher));

$entityManager->getMetadataFactory()->setDispatcher($dispatcher);
$entityManager->getEventManager()->addEventListener(['postFlush', 'onFlush'], new DoctrinePostPersistListener($dispatcher));
$entityManager->getEventManager()->addEventListener(['postLoad'], new PostLoadDispatcherInjectionListener($dispatcher));

return $entityManager;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Biig\Component\Domain\Tests\Symfony\DependencyInjection\CompilerPass;

use Biig\Component\Domain\Model\Instantiator\DoctrineConfig\PostLoadDispatcherInjectionListener;
use Biig\Component\Domain\PostPersistListener\DoctrinePostPersistListener;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

class RegisterListenersCompilerPassTest extends KernelTestCase
{
public function testItRegistersThePostLoadListener(): void
{
self::bootKernel();

$this->assertInstanceOf(PostLoadDispatcherInjectionListener::class, $this->getContainer()->get('biig_domain.postload_listener'));
$this->assertInstanceOf(DoctrinePostPersistListener::class, $this->getContainer()->get('biig_domain.post_persist_listener.doctrine_default'));
}
}
Loading

0 comments on commit 9f03bca

Please sign in to comment.