Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symfony 4 components support, drop < 3.3 support #33

Merged
merged 17 commits into from
Feb 21, 2018

Conversation

mateuszsip
Copy link
Contributor

@mateuszsip mateuszsip commented Dec 23, 2017

Meant to resolve #30

@UFOMelkor do you have some specific tests in mind? Can I help somehow?

Compiler passes should get own tests for sure.

TODO:

  • Don't mark as public services that should stay private
  • Write compiler passes tests

Post rebase TODO:

  • Commands are not registered (only in test kernel?)
  • Enrichers are broken - failing tests

@sstok
Copy link
Contributor

sstok commented Jan 2, 2018

You properly want to have a look at https://github.com/SymfonyTest especially https://github.com/SymfonyTest/SymfonyDependencyInjectionTest

@mateuszsip
Copy link
Contributor Author

Tests needs some cleanup and more scenarios for ProjectorPass, but feel free to review.

@@ -50,6 +52,7 @@ public function load(array $configs, ContainerBuilder $container)
}

if (! empty($config['projections'])) {
// FIXME: Missing second argument
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The complete block can be safely removed. projections is not available in config.

)
// TODO: Remove me
->setPublic(true)
->setFactory([new Reference('prooph_event_store.repository_factory'), 'create'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factory can be moved to prooph_event_store.repository_definition.

->setClass('%prooph_event_store.metadata_enricher_aggregate.class%');
// TODO: Remove me
->setPublic(true)
->setClass(MetadataEnricherAggregate::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is setClass really necessary? It is inherited from prooph_event_store.metadata_enricher_aggregate_definition, isn't it?

->setClass('%prooph_event_store.metadata_enricher_plugin.class%');
// TODO: Remove me
->setPublic(true)
->setClass(MetadataEnricherPlugin::class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@@ -156,9 +159,11 @@ private function loadEventStore(string $name, array $options, ContainerBuilder $
$eventStoreDefinition = $container
->setDefinition(
$eventStoreId,
new DefinitionDecorator('prooph_event_store.store_definition')
new ChildDefinition('prooph_event_store.store_definition')
)
->setFactory([new Reference('prooph_event_store.store_factory'), 'createEventStore'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factory can be moved to prooph_event_store.store_definition


abstract class TestServices
{
public const EVENT_STORE_SERVICE_ID_PREFIX = 'prooph_event_store.';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I don't see a real value in adding a class for this constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel more confident with constant while refactoring, but it's not something I wll fight for.
Little value, 2 votes against - inlined in 12ebe0c

$this->compile();

$this->assertContainerBuilderHasServiceDefinitionWithArgument(
sprintf('prooph_event_store.%s.%s', 'metadata_enricher_aggregate', 'foo'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sprintf necessary?

);

$this->assertContainerBuilderHasServiceDefinitionWithArgument(
sprintf('prooph_event_store.%s.%s', 'metadata_enricher_aggregate', 'bar'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@bgaleotti
Copy link

In https://github.com/kejwmen/event-store-symfony-bundle/blob/e2f7b6ce2b75fcca69509d449b43bd7090282b41/src/DependencyInjection/ProophEventStoreExtension.php#L71, it should be:

use Prooph\EventStore\Projection\ProjectionManager;

//

            $projectionManagerDefintion
                ->setClass(ProjectionManager::class)
                ->setFactory([new Reference('prooph_event_store.projection_factory'), 'createProjectionManager'])

Otherwise, given the foobar_projection_manager it will trigger an error when building the container:

Please add the class to service "prooph_event_store.projection_manager.foobar_projection_manager" even if it is constructed by a factory since we might need to add method calls based on compile-time checks.

@mateuszsip
Copy link
Contributor Author

Thanks for review @UFOMelkor @bgaleotti.

@mateuszsip
Copy link
Contributor Author

Sorry for delay, I forgot about this PR :D

Today I want to finish it, do we want to merge this: #34 before? Looks like conflicts and (maybe?) duplicated test scenarios, I can rebase and fix it, just let me know.

@mateuszsip
Copy link
Contributor Author

mateuszsip commented Jan 28, 2018

What about testing private services?
I started with storing prefixed aliases in separate config file, do we have a better option?

DefaultEventStoreFactory use container to attach plugins.
What is the best way to handle that? Looks like a job for service locator, what do you think?

Introduced these changes in 4479ab1

I know test_aliases.yml looks messy, but I had to introduce aliases for services registered in tests using config fixtures. These tests can load additional file with services configuration, is it the way to go?

@UFOMelkor
Copy link
Member

@kejwmen May I ask you to review #34? Merging without having a second person looking on it … ;-)

@UFOMelkor
Copy link
Member

👍 for the plugin-ServiceLocator.

In addition, services not meant to be used by the application directly, should be defined as private.
Best Practices for Reusable Bundles

While I personally dislike using the container directly, I think the event-stores and the repositories should be public. Your thoughts on this?

@UFOMelkor
Copy link
Member

UFOMelkor commented Jan 31, 2018

So, for now the last review-comment 😉

The projection commands are accessing the container which will fail because the accessed services are not public. Perhaps another ServiceLocator as solution?

The MetadataEnricher will also need some love. Currently they are also fetched from the container. Tagging them as plugins instead of handling them seperately might be a simple solution.

I know test_aliases.yml looks messy, but I had to introduce aliases for services registered in tests using config fixtures.

I would suggest to put the aliases directly into the respective test/DependencyInjection/Fixture/config/xml|yml file.

Thank you for your commitment and your endurance!

@mateuszsip
Copy link
Contributor Author

While I personally dislike using the container directly, I think the event-stores and the repositories should be public. Your thoughts on this?

Heart says no, brain says 👍 - I don't see a valid use case to fetch them from container instead of injecting, but if there is any that can be painful to users.

The projection commands are accessing the container which will fail because the accessed services are not public. Perhaps another ServiceLocator as solution?

ServiceLocator sounds like a good idea to start.
#34 includes tests for these commands (thanks!), I will take care of that after rebase.

The MetadataEnricher will also need some love. Currently they are also fetched from the container. Tagging them as plugins instead of handling them seperately might be a simple solution.

Good idea, simplifies things a lot.
Implemented in e93636f

I would suggest to put the aliases directly into the respective test/DependencyInjection/Fixture/config/xml|yml file.

I forgot we can put service definitions there :D
Done.

Feel free to review latest commits, I will try to finish what's left tomorrow.

Copy link
Member

@UFOMelkor UFOMelkor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me 👍

@@ -41,7 +43,8 @@ public function process(ContainerBuilder $container)

$metadataEnricherId = sprintf('prooph_event_store.%s.%s', 'metadata_enricher_plugin', $name);
$metadataEnricherDefinition = $container->getDefinition($metadataEnricherId);
$metadataEnricherDefinition->setClass('%prooph_event_store.metadata_enricher_plugin.class%');
$metadataEnricherDefinition->setClass(MetadataEnricherPlugin::class);
$metadataEnricherDefinition->addTag(sprintf('prooph_event_store.%s.plugin', $name));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to ProophEventStoreExtension, it will fix the enrichers (MetadataEnricherPass is executed after the PluginPass).

new ProophEventStoreBundle(),
];
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add the Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass via build method and add the commands as services, commands should be recognized.

@mateuszsip mateuszsip changed the title [WIP] Symfony 4 components support, drop < 3.3 support Symfony 4 components support, drop < 3.3 support Feb 10, 2018
@lunetics
Copy link
Member

Testing your WIP, without any config i get:

The service "Prooph\Bundle\EventStore\Command\ProjectionNamesCommand" has a dependency on a non-existent parameter "prooph_event_store.projection_managers".

@lunetics
Copy link
Member

You should add the "event_store" key (definition) to the configuration (was type before)
https://github.com/kejwmen/event-store-symfony-bundle/blob/43d5ebf53892d25c669944fbea95ad75b132d8b5/src/DependencyInjection/Configuration.php#L86

@enumag enumag mentioned this pull request Feb 20, 2018
@codeliner
Copy link
Member

@kejwmen and/or @UFOMelkor can you resolve the conflicts? I tried it but tests are failing with:

1) ProophTest\Bundle\EventStore\DependencyInjection\XmlEventStoreExtensionTest::it_creates_an_event_store
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: The "prooph_event_store.projection_manager.main_projection_manager" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

Projection manager should also be a public service I guess

@mateuszsip
Copy link
Contributor Author

@codeliner I will take care of that later today

@codeliner
Copy link
Member

thx

@UFOMelkor
Copy link
Member

@kejwmen This will remove the necessity for an own service locator for the projection managers. (more public services, the heart is bleeding^^).
Projections and read models on the other hand should still have their own service locator.

Actually this should have it own test and be not just part of the it_creates_an_event_store test, but perhaps we focus on making projection managers public and getting this finally merged.

@codeliner
Copy link
Member

codeliner commented Feb 20, 2018

but perhaps we focus on making projection managers public and getting this finally merged.

👍 test cases can be added in a separate PR. Let's finish it as soon as possible, so that teams can finally upgrade to symfony 4.0

@codeliner
Copy link
Member

(more public services, the heart is bleeding^^).

Started a poll: https://twitter.com/prooph_software/status/965946184706723842
I'd say we go for the public option in this PR and if majority of people say we should make it private then we can do this in another PR

@mateuszsip
Copy link
Contributor Author

Rebased on master and made ProjectionManagers public, but dedicated locator is still there. Should I remove it before merging?

@UFOMelkor @codeliner

@coveralls
Copy link

Pull Request Test Coverage Report for Build 144

  • 62 of 73 (84.93%) changed or added relevant lines in 8 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.8%) to 81.549%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/Command/AbstractProjectionCommand.php 0 11 0.0%
Files with Coverage Reduction New Missed Lines %
src/Command/AbstractProjectionCommand.php 1 0.0%
Totals Coverage Status
Change from base Build 143: 0.8%
Covered Lines: 358
Relevant Lines: 439

💛 - Coveralls

@codeliner
Copy link
Member

@UFOMelkor Can we merge? Once merged I'd release a new version of the bundle to communicate symfony 4.0 support 🎉

I'd say further improvements can be made in separate PRs

@UFOMelkor
Copy link
Member

LGTM 👍

@codeliner codeliner merged commit da6386c into prooph:master Feb 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raise version of symfony dependencies
7 participants