Mappingexception in mappingexception php

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

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

MappingException: Invalid mapping file User.orm.yml #2026

MappingException: Invalid mapping file User.orm.yml #2026

Comments

Hi there, i have a problem with running unittest in symfony project as below:

1) *******\Tests\Controller\*******ControllerTest::testIndex Doctrine\Common\Persistence\Mapping\MappingException: Invalid mapping file '*****.UserBundle.Entity.User.orm.yml' for class '*****\UserBundle\Entity\User'. 

I can not figure out why this happens by running phpunit but not when doctrine:schem:update or doctrine:generate:entities !

 namespace *****\UserBundle\Entity; use FOS\UserBundle\Model\User as BaseUser; use Doctrine\ORM\Mapping as ORM; /** * */ class User extends BaseUser < /** * @var integer */ protected $confirm; /** * Set confirm * * @param integer $confirm * @return User */ public function setConfirm($confirm) < $this->confirm = $confirm; return $this; > /** * Get confirm * * @return integer */ public function getConfirm() < return $this->confirm; > >

And this is the User.orm.yml:

********\UserBundle\Entity\User: type: entity table: fos_user repositoryClass: ******\UserBundle\Entity\UserRepository id: id: type: integer #id: true generator: strategy: AUTO fields: confirm: type: smallint lifecycleCallbacks:

The text was updated successfully, but these errors were encountered:

btw, if you look at the exception message, it does not talk about a User.orm.yml file, so this may be why things fail

Hi, there are exceptions like below:

/var/www/_/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/MappingException.php:86
/var/www/****************/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/FileDriver.php:127
/var/www/****************/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php:56
/var/www/_
/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/Driver/MappingDriverChain.php:102
/var/www/**
_/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:116
/var/www/**********/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:332
/var/www/_
_/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:216
/var/www/
*****************/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:265
/var/www/__/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php:67
/var/www/_
/vendor/doctrine/orm/lib/Doctrine/ORM/Repository/DefaultRepositoryFactory.php:50
/var/www/**
/vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:665
/var/www/**
*********_/vendor/friendsofsymfony/user-bundle/Doctrine/UserManager.php:40
/var/www/_
/app/cache/test/appTestDebugProjectContainer.php:1694
/var/www/**
_/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:312
/var/www/*************/app/cache/test/appTestDebugProjectContainer.php:4117
/var/www/*************/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:312
/var/www/*************/app/cache/test/appTestDebugProjectContainer.php:4175
/var/www/_
_/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:312
/var/www/_
_/app/cache/test/appTestDebugProjectContainer.php:2660
/var/www/_
_/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:312
/var/www/_
_/app/cache/test/appTestDebugProjectContainer.php:3774
/var/www/_
_/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:312
/var/www/_
_/app/cache/test/appTestDebugProjectContainer.php:476
/var/www/_
_/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:312
/var/www/_
/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:523
/var/www/»»»»»»»»»»»»»»»/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:133
/var/www/**
/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/KernelTestCase.php:142
/var/www/»»»»»»»»»»’//vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Test/WebTestCase.php:33
/var/www/**
/src/***_Bundle/Tests/Controller/_*******ControllerTest.php:11

Message said about invalid mapping of User.orm.yaml

  1. _\Tests\Controller*__ControllerTest::testIndex
    Doctrine\Common\Persistence\Mapping\MappingException: Invalid mapping file ‘
    _.UserBundle.Entity.User.orm.yml’ for class ‘***\UserBundle\Entity\User’.

No, the file in the exception message is .UserBundle.Entity.User.orm.yml , not User.orm.yaml . This may be related to your issue (maybe you configured the mapping in a wrong way)

and btw, what you pasted in the previous comment is not the message of a linked exception, but the stack trace of this exception (but I found the code triggering the exception in Doctrine and there is no linked exception).

Ah ok thx but realy i dont understand what you mean.

You mean this have to been only like:
User.orm,yml
And not
XY.UserBundle.Entity.User.orm.yml?

With other words, when User.orm.yml is placed in
XY/UserBundle/Resources/config/doctrine
and User.php in:
XY/UserBundle/Entity

So the message should say about the file like below:
XY.UserBundle.Resources.config.doctrine.User.orm.yml

No. Your orm is ok.
PHPUNIT Test framework uses the newest yaml parser of symfony version 3. But when you running symfony version < version 3 you would get with unittesting in problems because the parsing of yaml file would be depricated and would throw exception.

Recently I was experiencing similar «MappingException: Invalid mapping file» exceptions using the following code:

//bootstrap.php $config = Setup::createYAMLMetadataConfiguration(array(__DIR__ . "/../config/dcm"), $isDevMode);

Using Symfony Yaml 2.*, everything worked fine. But with Symfony Yaml ^3.3 I would get the invalid mapping file exception. I traced it to how the different Yaml library parse functions work. When using Doctrine to parse yaml files, it will use the YamlDriver class which loads yaml files using this function:

// vendor/doctrine/orm/lib/Doctrine/Orm/Mapping/Driver/YamlDriver.php protected function loadMappingFile($file) < return Yaml::parse($file); >

In Yaml 2.*, passing a filename string to parse works without problem, but with Yaml ^3.3, the parse function expects a yaml string. Some ways to get around this include using xml config files or writing your own Yaml driver and obtaining the config by bypassing the Setup::createYAMLMetadataConfiguration and using the this code:

$config = self::createConfiguration($isDevMode, $proxyDir, $cache); $config->setMetadataDriverImpl(new \MyNamespace\YamlDriver($paths)); return $config;

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

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

Fatal error: Uncaught Doctrine\ORM\Mapping\MappingException #7109

Fatal error: Uncaught Doctrine\ORM\Mapping\MappingException #7109

Comments

Here is generated entity code:

)>) * @ORM\Entity */ class User < /** * @var integer * * @ORM\Column(name="id", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $id; /** * @var string * * @ORM\Column(name="username", type="text", length=65535, nullable=false) */ private $username; /** * @var \Address * * @ORM\ManyToOne(targetEntity="Address") * @ORM\JoinColumns(< * @ORM\JoinColumn(name="address_id", referencedColumnName="id") * >) */ private $address; /** * Get id * * @return integer */ public function getId() < return $this->id; > /** * Set username * * @param string $username * * @return User */ public function setUsername($username) < $this->username = $username; return $this; > /** * Get username * * @return string */ public function getUsername() < return $this->username; > /** * Set address * * @param \Address $address * * @return User */ public function setAddress(\Address $address = null) < $this->address = $address; return $this; > /** * Get address * * @return \Address */ public function getAddress() < return $this->address; > > id; > /** * Set phone * * @param string $phone * * @return Address */ public function setPhone($phone) < $this->phone = $phone; return $this; > /** * Get phone * * @return string */ public function getPhone() < return $this->phone; > > 

Here is my code I just made little change in generated entity and added database name before table name :

 'pdo_mysql', 'user' => 'xxxxx', 'password' => 'xxxxx', 'dbname' => 'database_a', ); $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode); $em = $entityManager = EntityManager::create($dbParams, $config); require_once "Entities/User.php"; require_once "Entities/Address.php"; $data = $em->getRepository('User'); $datax = $data->findAll(); foreach($datax as $d) < echo '
'; print_r($d); > 

error detail:

Fatal error: Uncaught Doctrine\ORM\Mapping\MappingException: Class "User" is not a valid entity or mapped super class. in D:\xampp\htdocs\docx\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\MappingException.php:346 Stack trace: #0 D:\xampp\htdocs\docx\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\Driver\AnnotationDriver.php(91): Doctrine\ORM\Mapping\MappingException::classIsNotAValidEntityOrMappedSuperClass('User') #1 D:\xampp\htdocs\docx\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\ClassMetadataFactory.php(151): Doctrine\ORM\Mapping\Driver\AnnotationDriver->loadMetadataForClass('User', Object(Doctrine\ORM\Mapping\ClassMetadata)) #2 D:\xampp\htdocs\docx\vendor\doctrine\common\lib\Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory.php(332): Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(Object(Doctrine\ORM\Mapping\ClassMetadata), NULL, false, Array) #3 D:\xampp\htdocs\docx\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\ClassMetadataFactory.php(78): Doctrine\Common\Persistence\Mapping\AbstractClassMetada in D:\xampp\htdocs\docx\vendor\doctrine\orm\lib\Doctrine\ORM\Mapping\MappingException.php on line 346 

The text was updated successfully, but these errors were encountered:

Источник

Читайте также:  Тег input, атрибут list
Оцените статью