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

Improve CycleOrmBootloader bindings #33

Merged

Conversation

kafkiansky
Copy link

@kafkiansky kafkiansky commented May 26, 2022

Made the EntityManagerInterface a singleton, so that the persist and run operations could be called independently of each other and the operations on the entity were performed. Also, instead of clearing the heap with ORMInterface, did it using the EntityManagerInterface::clean method.

But I find it a bit strange that the EntityManager has an argument $cleanHeap in the clean method that is not in the EntityManagerInterface. IMHO, it should not be in EntityManager at all, so both heap and entity manager should be called in the finalizer as follows:

$finalizer->addFinalizer(
    static function () use ($container): void {
       if ($container->hasInstance(EntityManagerInterface::class)) {
           $container->get(EntityManagerInterface::class)->clean();
       }

       if ($container->hasInstance(ORMInterface::class)) {
           $container->get(ORMInterface::class)->getHeap()->clean();
       }
});

And EntityManager should only create a new UnitOfWork instance:

public function clean(): static
{
      $this->unitOfWork = new UnitOfWork($this->orm);

      return $this;
}

@wolfy-j wolfy-j requested a review from butschster May 26, 2022 10:59
@codecov
Copy link

codecov bot commented May 29, 2022

Codecov Report

Base: 67.84% // Head: 69.17% // Increases project coverage by +1.33% 🎉

Coverage data is based on head (cf533fb) compared to base (a018fba).
Patch coverage: 100.00% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff              @@
##             master      #33      +/-   ##
============================================
+ Coverage     67.84%   69.17%   +1.33%     
- Complexity      435      436       +1     
============================================
  Files            52       52              
  Lines          1132     1275     +143     
============================================
+ Hits            768      882     +114     
- Misses          364      393      +29     
Impacted Files Coverage Δ
src/Bootloader/CycleOrmBootloader.php 100.00% <100.00%> (+3.84%) ⬆️
.../DataGrid/Specification/Sorter/InjectionSorter.php 57.14% <0.00%> (-0.76%) ⬇️
...Console/Command/CycleOrm/Generator/ShowChanges.php 60.97% <0.00%> (-0.57%) ⬇️
src/polyfill.php 0.00% <0.00%> (ø)
src/Schema/Compiler.php 100.00% <0.00%> (ø)
src/Bootloader/CommandBootloader.php 100.00% <0.00%> (ø)
src/Interceptor/CycleInterceptor.php 100.00% <0.00%> (ø)
src/Bootloader/DataGridBootloader.php 100.00% <0.00%> (ø)
src/Bootloader/DatabaseBootloader.php 100.00% <0.00%> (ø)
src/DataGrid/Writer/BetweenWriter.php 100.00% <0.00%> (ø)
... and 21 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@butschster
Copy link
Member

@kafkiansky Hi!

Sorry for long response. Could you fix error with static analysis?

@kafkiansky
Copy link
Author

@butschster, Hi. I fixed it.

@butschster
Copy link
Member

@butschster, Hi. I fixed it.

Thank you! You are the best!

@butschster butschster self-assigned this Jun 6, 2022
@butschster butschster added the enhancement New feature or request label Jun 6, 2022
@butschster butschster requested a review from roxblnfk June 6, 2022 10:57
@butschster butschster requested a review from roxblnfk July 28, 2022 08:34
@roxblnfk
Copy link
Member

Can you add the second test please with EM mock?

  • bindSingleton(EntityManagerInterface::class => mock(EntityManagerInterface::class))
  • run $this->getContainer()->get(FinalizerInterface::class)->finalize();
  • check the method clean has been called

@butschster butschster added this to the v1.x milestone Feb 6, 2023
@butschster butschster merged commit dfa3d8a into spiral:master Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants