2

I'm starting to migrate my application to symfony4 but I have the following deprecation notice in one of my third-party bundle ( tbbcmoneybundle . And I would like to know what to change in order to propose a PR

Currently the build is failing because of these errors (complete report here )

The "doctrine.database_create_command" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead: 25x
    12x in ConfigTest::setUp from Tbbc\MoneyBundle\Tests\Config
    6x in ConsoleTest::setUp from Tbbc\MoneyBundle\Tests\Console
    3x in ConsoleTest::testRunRatioList from Tbbc\MoneyBundle\Tests\Console
    2x in ConsoleTest::testRunRatioFetch from Tbbc\MoneyBundle\Tests\Console
    1x in ConfigTest::testHistoryOfFetchedRatio from Tbbc\MoneyBundle\Tests\Config
    1x in ConsoleTest::testRunSaveRatio from Tbbc\MoneyBundle\Tests\Console

I guess it's related to this code

    $this->runCommand($this->client,'doctrine:database:create');
    $this->runCommand($this->client,'doctrine:schema:update --force');

However I don't see see how to fix this and google seems unhelpful on this one.

allan.simon
  • 3,886
  • 6
  • 35
  • 60
  • @gp_sflover thanks for the pointer, but what I found lacking (and I wish to fill with this question) was some concrete examples on how to fix it – allan.simon Dec 31 '17 at 00:22
  • 1
    Two PR was already made and the last were posted 3 hours ago [Symfony4 support bis](https://github.com/TheBigBrainsCompany/TbbcMoneyBundle/pull/85). Just wait or give your availability to help them there :-) – gp_sflover Dec 31 '17 at 00:39
  • @gp_sflover actually I'm the guy who made the second MR :) and as i'm blocked by this, I don't want to let my PR die because I didn't find enough motivation to push the PR to the end. And I hope by trying to identify this specific case on a quite common library (doctrine) it may help people save 5~10 minutes on migrating or contributing themselves PR. – allan.simon Dec 31 '17 at 00:42
  • I'm really tired! Doesn't saw the same name o-O ahahah! I haven't the time now but tomorrow I'll go to take a look more closely :-) – gp_sflover Dec 31 '17 at 00:47
  • @gp_sflover haha no problem you made me check twice what was my avatar and my username :P thanks in advance for your help. – allan.simon Dec 31 '17 at 00:49

1 Answers1

1

The problem looks like it comes from the loss of container awareness (if that's a valid phrase) in Symfony 4, which started in Symfony 3.4. This blog talks about restricting container injection in 3.4 and how it will go away in 4.0.

It looks as though someone has opened a PR to upgrade to Symfony 4, but that is failing. (Looks like you're trying to help that along as well.)

According to this Travis integration test that is failing, the commands which extend "ContainerAwareCommand" are the source of the fail.

Which makes sense. The ContainerAwareCommand attempts to inject the Container, which is set to private in Symfony 4 (and deprecated since 3.4) as outlined in the blog post above. A fix, and I think you want to fix this in a PR to TBBC if I read your question correctly, seems to be to remove the extension of ContainerAwareCommand from those command classes and just inject the services necessary. See the new Symfony 4 doc on commands (and note that ContainerAware is no longer an option as it was in 2.8-ish.)

In short, get rid of the extension to ContainerAwareCommand and inject the services used by those commands. (Might need to do some extra configuration to ensure that the services are public.)

Ollie in PGH
  • 2,559
  • 2
  • 16
  • 19
  • 1
    hmmm after investigating more in the code of the bundle, it seems it was because the test were run with deprecation notice set to strict (making test fail if there's a deprecation notice), but the things were coming from the symfony framework itself, because it was using 3.1 and these deprecation notice was fixed internally only in later version.... – allan.simon Jan 06 '18 at 20:59
  • 1
    I will consider your answer as correct, as though for this very specific case it was not the "answer", but it actually lead me to the right direction :) – allan.simon Jan 06 '18 at 21:00