Symfony table entity has itself recognized as repository as well - php

New to both Symfony and StackOverflow as an OP.
I'm on a way adding new mysql table entities and repositories on Symfony(4.3.2) and get stuck as I test it.
I really appreciate someone's help.
The error I got was
[2020-07-13 03:25:59] request.CRITICAL: Uncaught PHP Exception RuntimeException: "The "App\Entity\Foo" entity has a repositoryClass set to "App\Repository\Foo", but this is not a valid class. Check your class naming. If this is meant to be a service id, make sure this service exists and is tagged with "doctrine.repository_service"." at /var/www/html/bar_project/vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php line 66 {"exception":"[object] (RuntimeException(code: 0): The \"App\\Entity\\Foo\" entity has a repositoryClass set to \"App\\Repository\\Foo\", but this is not a valid class. Check your class naming. If this is meant to be a service id, make sure this service exists and is tagged with \"doctrine.repository_service\". at /var/www/html/bar_project/vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php:66)"} []
where Foo at /App/Entity/ is an entity for the table foo.
and the problem is that it tries to refer to Foo at App/Repository/ as its repository which doesn't exist, but not FooRepository which exists.
(Updated this paragraph following the comment from Jakumi)
(FooController.php)
$repository = $this->getDoctrine()->getRepository(Foo::class);
(Foo.php)
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Table(name="foo")
* #ORM\Entity(repositoryClass="App\Repository\FooRepository") // *1
*/
class Foo
{
...
(FooRepository.php)
<?php
namespace App\Repository;
use App\Entity\Foo;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Symfony\Bridge\Doctrine\RegistryInterface;
/**
* #method Foo|null find($id, $lockMode = null, $lockVersion = null)
* ...
*/
class FooRepository extends ServiceEntityRepository
{
...
One thing I find mysterious is that the same error log still shows up even if I remove *1.
(I think I have yarn watch and cache clear appropriately working.)
Additional Info 1
(doctrine.yaml)
doctrine:
dbal:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '8.0'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
# dbname:
# host:
# port:
# user:
# password:
url: '%env(resolve:DATABASE_URL)%'
options:
1002: 'SET sql_mode=(SELECT REPLACE(##sql_mode, "ONLY_FULL_GROUP_BY", ""))'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
metadata_cache_driver: apcu
result_cache_driver: apcu
query_cache_driver: apcu
connection: ~
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
dql:
string_functions:
group_concat: DoctrineExtensions\Query\Mysql\GroupConcat
date_format: DoctrineExtensions\Query\Mysql\DateFormat

Related

How to fix migrations running on both databases when setting up multiple databases with symfony4 and doctrine

I am trying to setup a second database for a symfony 4.2 project. Everything seems to working fine up until the point where I run migrations where all migrations execute on the given connection instead of only the migrations for the connection it was created.
Following symfony's own documentation about this, my doctrine.yaml looks like this:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(DATABASE_URL)%'
logging:
driver: 'pdo_mysql'
server_version: '5.7'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(DATABASE_URL_LOG)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: default
entity_managers:
default:
connection: default
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
logging:
connection: logging
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: false
mappings:
Log:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Log'
prefix: 'App\Log'
alias: Log
Now with this configuration I am able to run the migration commands with the --em=log/default parameter like this:
php bin/console doctrine:migrations:diff --em=log
php bin/console doctrine:migrations:migrate --em=log
And you get the expected results: It only creates a new migration for a new entity I created at src/Log when I add --em=log.
this is the new entity:
<?php
namespace App\Log;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity()
*/
class LogItem
{
/**
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
* #ORM\Column(type="integer")
*/
private $id;
}
However, the migration is created in the default src/Migrations folder and as a result:
1) this migration is also executed when I run doctrine:migrations:migrate --em=default (creating the table in the default database)
2) the entire default schema is loaded into the log database when I run doctrine:migrations:migrate --em=log
So I think the solution would be to split the migration files between the to entity managers into different directories. But I have been spending hours and can't find the way to do this for symfony4. Also, since the symfony documentation mentions absolutely nothing about this I feel like maybe something is wrong in the way it is setup now.
So can anyone tell me what I am doing wrong here? Or can (and if yes: how) do I split the migration files so it will only execute the migrations created for the given entity manager?
doctrine/doctrine-migrations-bundle doesn't support migrations for multiple entity managers out of the box. There are various workarounds to this problem, including:
Container aware migrations (only feasible on Symfony <4)
Storing migration configuration for each entity manager separately and passing it directly via the --configuration option of the doctrine:migrations:migrate command (only feasible if you don't need to inject services/dependencies into your migrations)
Using avaibooksports/doctrine-migrations-multiple-database-bundle (or rolling your own bundle), which implements support for separate configuration per-entity-manager (in which you can specify a separate directory for each entity's migrations, and inject services via factories as needed).
There's an open GitHub issue (opened in 2012) that describes these approaches in more detail. Also see this answer for a summary.
I think you have a typo in your samples.
In your doctrine.yaml file, the names of your entity managers are "default" and "logging".
But in your command line samples you use the entity manager name "log".
It should work when you change the flag from --em=log to --em=logging.

"Unknown Entity namespace alias" exception

I'm experiencing troubles with my new bundle, AdminBundle, I've just created. I see the following ORMException message:
Unknown Entity namespace alias 'AdminBundle'.
This is the DefaultController.php:
<?php
namespace AdminBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
class DefaultController extends Controller
{
/**
* #Route("/dashboard", name="admin_default_dashboard")
* #return Response
*/
public function dashboardAction()
{
$manager = $this->getDoctrine()->getManager();
$rObject = $manager->getRepository('AdminBundle:Object');
return $this->render('AdminBundle:Default:dashboard.html.twig');
}
}
This is the doctrine configuration in my config.yml file:
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
And this is ObjectRepository.php file:
<?php
namespace AdminBundle\Repository;
use Doctrine\ORM\EntityRepository;
use AppBundle\Entity\Object;
class ObjectRepository extends EntityRepository
{
}
I've tried to check out solutions from similar threads but none of them worked to me.
edit:
This is the Object entity code: http://collabedit.com/agyh8
PS. Thanks, Arkovsky, for your advice. I'm going to change the entity name for sure.
it seems that you made a bundle without a vendor name, and that's probably why it's bugging.
When you create a bundle in Symfony use this console command in your symfony project :
php bin/console generate:bundle
Then they ask you a name for your bundle. Here you got to write something with this pattern : Bob\AdminBundle
(You can change "Bob" by whatever vendor name you like). Then follow the instructions and it should work fine.
From now, the entire name of your bundle that you are going to use in your controller is going to be : "BobAdminBundle".
Example :
return $this->render('BobAdminBundle:Default:dashboard.html.twig');

"Class XXX is not a valid entity or a mapped super class" error when using php app/console

I'm following this Symfony2/Doctrine guide and I've come to the part where I need to create getters/setters. but I am stuck with this part:
$ php app/console doctrine:generate:entities Acme/StoreBundle/Entity/Job
I've searched the net for possible solutions (seems to mainly revolve around using 2 asterisks for the start) but couldn't find the solution.
Some info:
Bundle is properly loaded (via AppKernel.php) as I have a test "hello world" and that works.
The namespace path is correct
Job.php exists in the right folder
I'm using postgres as my database. I'm not sure if this matters.
I have tried with and without the use Doctrine\ORM\Mapping line in model class (see below for code)
I don't think I'm running a accelerator at least according to get_loaded_extensions function
Any ideas would be very helpful.
Thanks a lot :)
snippet of my settings.yml
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
Model class
<?php
// src/MyApp/MyBundle/Model/Job.php
namespace MyApp\MyBundle\Model;
use Doctrine\ORM\Mapping as ORM;
/**
* MyApp\MyBundle\Model\Job
*
* #ORM\Entity
* #ORM\Table(name="myschema.jobs")
*/
class Job {
/**
* #ORM\Column(name="job_id", type="integer")
* #ORM\Id
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $jobid;
/**
* #ORM\Column(name="name", type="text")
*/
protected $name;
/**
* #ORM\Column(name="job_desc", type="text")
*/
protected $description;
/**
* #ORM\Column(name="personal_req", type="text")
*/
protected $requirements;
}
did you create your entity using doctrine? I saw on your Job.php entity you are using annotation as mapping format.
In error output it said doctrine can't find any mapped entities. I've been there and it solved with specific configuration of your config.yml.
Try to change this on your config.yml
doctrine:
dbal:
driver: "%database_driver%"
#etc
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: false
mappings:
MyAppMyBundle:
type: annotation #On your case it should be annotation
dir: Resources/Model/
Read this maybe it can help:
Doctrine Mapping in Symfony2 using YAML
Have you tried using following console command ?
$ php app/console doctrine:generate:entities MyApp/MyBundle/Model
I hope it will work. Your entity namespace is different than Acme/StoreBundle/Entity/Product. Your entities are in Model directory/namespace so you should use first argument of command a valid namespace. So that following cmd generates error as you have mentioned above.
$ php app/console doctrine:generate:entities Acme/StoreBundle/Entity/Product

Error generating entity with Symfony2

I am generating an Entity from php Class:
<?php
// src/Printing/Productesbundle/Entity/User.php
namespace Printing\ProductesBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="UsersStamp")
*/
class UserStamp
{
/**
* #ORM\Column(type="integer")
* #ORM\Id
* #ORM\GeneratedValue
*/
private $id;
}
?>
When I execute
php app/console doctrine:generate:entities Printing/ProductesBundle/Entity/UserStamp
it returns me the following error
[Doctrine\ORM\Mapping\MappingException]
Class "Printing\ProductesBundle\Entity\UserStamp" is not a valid entity or mapped super class.
What am i missing??
Thank you!
PS:
That's my Doctrine Configuration:
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
Could you try command below?
app/console doctrine:generate:entities PrintingProductesBundle:UserStamp
I think you need to execute something like this
php app/console doctrine:generate:entities ProductesBundle
After trying some tricks I found the solution.
I guess the error radicates on the fact that I have entities generated previously from database.
To solve this question, you have to remove the content of the config/doctrine folder.
Thanks to #Javad to keep trying!

Symfony 4.1 : You have requested a non-existent service "doctrine"

Hello i'm making a new project on symfony 4.1,
i use postgres 10.5 as my SGBD.
i created an entity with the maker bundle of symfony and now i try to make a migration still with the maker bundle with that command :
php bin/console make:migration
here is the stack trace :
In Container.php line 274:
You have requested a non-existent service "doctrine". Did you mean one of these: "console.command.public_alias.doctrine_cache.contains_command", "console.command.public
_alias.doctrine_cache.delete_command", "console.command.public_alias.doctrine_cache.flush_command", "console.command.public_alias.doctrine_cache.stats_command", "consol
e.command.public_alias.doctrine_migrations.diff_command", "console.command.public_alias.doctrine_migrations.execute_command", "console.command.public_alias.doctrine_mig
rations.generate_command", "console.command.public_alias.doctrine_migrations.latest_command", "console.command.public_alias.doctrine_migrations.migrate_command", "conso
le.command.public_alias.doctrine_migrations.status_command", "console.command.public_alias.doctrine_migrations.version_command"?
Exception trace:
Symfony\Component\DependencyInjection\Container->make() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/Container.php:222
Symfony\Component\DependencyInjection\Container->get() at /opt/www/jame/dataneo-erp/vendor/doctrine/doctrine-migrations-bundle/Command/Helper/DoctrineCommandHelper.php:21
Doctrine\Bundle\MigrationsBundle\Command\Helper\DoctrineCommandHelper::setApplicationHelper() at /opt/www/jame/dataneo-erp/vendor/doctrine/doctrine-migrations-bundle/Command/MigrationsDiffDoctrineCommand.php:34
Doctrine\Bundle\MigrationsBundle\Command\MigrationsDiffDoctrineCommand->execute() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Command/Command.php:251
Symfony\Component\Console\Command\Command->run() at /opt/www/jame/dataneo-erp/vendor/symfony/maker-bundle/src/Maker/MakeMigration.php:78
Symfony\Bundle\MakerBundle\Maker\MakeMigration->generate() at /opt/www/jame/dataneo-erp/vendor/symfony/maker-bundle/src/Command/MakerCommand.php:100
Symfony\Bundle\MakerBundle\Command\MakerCommand->execute() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Command/Command.php:251
Symfony\Component\Console\Command\Command->run() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Application.php:904
Symfony\Component\Console\Application->doRunCommand() at /opt/www/jame/dataneo-erp/vendor/symfony/framework-bundle/Console/Application.php:89
Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Application.php:262
Symfony\Component\Console\Application->doRun() at /opt/www/jame/dataneo-erp/vendor/symfony/framework-bundle/Console/Application.php:75
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Application.php:145
Symfony\Component\Console\Application->run() at /opt/www/jame/dataneo-erp/bin/console:39
here is the code of some config files :
services.yaml
# This file is the entry point to configure your own services.
# Files in the packages/ subdirectory configure your dependencies.
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: 'fr'
services:
autowire: true
autoconfigure: true
public: false
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
config/packages/doctrine.yaml
parameters:
env(DATABASE_URL): ''
doctrine:
dbal:
driver: 'pdo_pgsql'
server_version: '10.5'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
and my .env
APP_ENV=dev
APP_SECRET=secret
DATABASE_URL="pgsql://erp_dev:My_PASSWORD#127.0.0.1:5432/erp"
MAILER_URL=null://localhost
Edit :
I tried to put "services : public : true" in services.yaml as mentioned in second answer and the result is a new error :
In DefinitionErrorExceptionPass.php line 54:
[Symfony\Component\DependencyInjection\Exception\RuntimeException]
Cannot autowire service "App\Repository\SocieteRepository": argument "$registry" of method "__construct()" refer
ences interface "Symfony\Bridge\Doctrine\RegistryInterface" but no such service exists. Did you create a class t
hat implements this interface?
Exception trace:
Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass->processValue() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:60
Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->processValue() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/Compiler/DefinitionErrorExceptionPass.php:32
Symfony\Component\DependencyInjection\Compiler\DefinitionErrorExceptionPass->processValue() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/Compiler/AbstractRecursivePass.php:39
Symfony\Component\DependencyInjection\Compiler\AbstractRecursivePass->process() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/Compiler/Compiler.php:95
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /opt/www/jame/dataneo-erp/vendor/symfony/dependency-injection/ContainerBuilder.php:736
Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /opt/www/jame/dataneo-erp/vendor/symfony/http-kernel/Kernel.php:519
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /opt/www/jame/dataneo-erp/vendor/symfony/http-kernel/Kernel.php:123
Symfony\Component\HttpKernel\Kernel->boot() at /opt/www/jame/dataneo-erp/vendor/symfony/framework-bundle/Console/Application.php:65
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /opt/www/jame/dataneo-erp/vendor/symfony/console/Application.php:145
Symfony\Component\Console\Application->run() at /opt/www/jame/dataneo-erp/bin/console:39
Here is the result of the command
php bin/console debug:container | grep doctrine
console.command.public_alias.doctrine_cache.contains_command alias for "doctrine_cache.contains_command"
console.command.public_alias.doctrine_cache.delete_command alias for "doctrine_cache.delete_command"
console.command.public_alias.doctrine_cache.flush_command alias for "doctrine_cache.flush_command"
console.command.public_alias.doctrine_cache.stats_command alias for "doctrine_cache.stats_command"
console.command.public_alias.doctrine_migrations.diff_command alias for "doctrine_migrations.diff_command"
console.command.public_alias.doctrine_migrations.execute_command alias for "doctrine_migrations.execute_command"
console.command.public_alias.doctrine_migrations.generate_command alias for "doctrine_migrations.generate_command"
console.command.public_alias.doctrine_migrations.latest_command alias for "doctrine_migrations.latest_command"
console.command.public_alias.doctrine_migrations.migrate_command alias for "doctrine_migrations.migrate_command"
console.command.public_alias.doctrine_migrations.status_command alias for "doctrine_migrations.status_command"
console.command.public_alias.doctrine_migrations.version_command alias for "doctrine_migrations.version_command"
doctrine_cache.abstract.apc Doctrine\Common\Cache\ApcCache
doctrine_cache.abstract.apcu Doctrine\Common\Cache\ApcuCache
doctrine_cache.abstract.array Doctrine\Common\Cache\ArrayCache
doctrine_cache.abstract.chain Doctrine\Common\Cache\ChainCache
doctrine_cache.abstract.couchbase Doctrine\Common\Cache\CouchbaseCache
doctrine_cache.abstract.file_system Doctrine\Common\Cache\FilesystemCache
doctrine_cache.abstract.memcache Doctrine\Common\Cache\MemcacheCache
doctrine_cache.abstract.memcached Doctrine\Common\Cache\MemcachedCache
doctrine_cache.abstract.mongodb Doctrine\Common\Cache\MongoDBCache
doctrine_cache.abstract.php_file Doctrine\Common\Cache\PhpFileCache
doctrine_cache.abstract.predis Doctrine\Common\Cache\PredisCache
doctrine_cache.abstract.redis Doctrine\Common\Cache\RedisCache
doctrine_cache.abstract.riak Doctrine\Common\Cache\RiakCache
doctrine_cache.abstract.sqlite3 Doctrine\Common\Cache\SQLite3Cache
doctrine_cache.abstract.void Doctrine\Common\Cache\VoidCache
doctrine_cache.abstract.wincache Doctrine\Common\Cache\WinCacheCache
doctrine_cache.abstract.xcache Doctrine\Common\Cache\XcacheCache
doctrine_cache.abstract.zenddata Doctrine\Common\Cache\ZendDataCache
doctrine_cache.contains_command Doctrine\Bundle\DoctrineCacheBundle\Command\ContainsCommand
doctrine_cache.delete_command Doctrine\Bundle\DoctrineCacheBundle\Command\DeleteCommand
doctrine_cache.flush_command Doctrine\Bundle\DoctrineCacheBundle\Command\FlushCommand
doctrine_cache.stats_command Doctrine\Bundle\DoctrineCacheBundle\Command\StatsCommand
doctrine_migrations.diff_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsDiffDoctrineCommand
doctrine_migrations.execute_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsExecuteDoctrineCommand
doctrine_migrations.generate_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsGenerateDoctrineCommand
doctrine_migrations.latest_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsLatestDoctrineCommand
doctrine_migrations.migrate_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsMigrateDoctrineCommand
doctrine_migrations.status_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsStatusDoctrineCommand
doctrine_migrations.version_command Doctrine\Bundle\MigrationsBundle\Command\MigrationsVersionDoctrineCommand
maker.doctrine_helper Symfony\Bundle\MakerBundle\Doctrine\DoctrineHelper
sensio_framework_extra.converter.doctrine.orm Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\DoctrineParamConverter
sensio_framework_extra.converter.doctrine.orm.expression_language alias for "sensio_framework_extra.converter.doctrine.orm.expression_language.default"
sensio_framework_extra.converter.doctrine.orm.expression_language.default Symfony\Component\ExpressionLanguage\ExpressionLanguage
Thank you a lot.
Change the following line in your services.yml
services:
public: false
by
services:
public: true
I had the same error when I tried to add unit tests for my custom symfony bundle. In /tests/App/AppKernel.php I have loaded DoctrineBundle:
<?php
namespace App\Tests\App;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
class AppKernel extends Kernel
{
use MicroKernelTrait;
public function __construct()
{
parent::__construct('test', true);
}
public function registerBundles(): iterable
{
return array(
new FrameworkBundle(),
new DoctrineBundle(),
);
}
protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader): void
{
$loader->load(__DIR__.'/config/config.yml');
$loader->load(__DIR__.'/config/services.yml');
}
}
I did not need DB connection so I did not add doctrine configurations, but because doctrine configuration was missing I got this error.
The Solution was to add doctrine configuration for tests /tests/App/config/doctrine.yml:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/Entity'
prefix: 'MainBundle\Entity'
alias: App
and load it in /tests/App/AppKernel.php:
protected function configureContainer(ContainerBuilder $containerBuilder, LoaderInterface $loader): void
{
$loader->load(__DIR__.'/config/config.yml');
$loader->load(__DIR__.'/config/services.yml');
$loader->load(__DIR__.'/config/doctrine.yml');
}
Note: you will need to configure phpunit.xml.dist to use this AppKernel file.
I needed EntityManager for my tests, for this I had to add doctrine.dbal and doctrine.orm, but just to solve this error doctrine.dbal configuration is enough.

Categories