Create an entity check for a symfony2 package that has no entities: the class was not found in the chain of names with a chain

we created a package to integrate CartoDB into Symfony2 projects. This package does not create any entity, because it "listens" for events, such as saving or a flash on your own entities, in order to synchronize information between your data and cartodb data. Here is the workflow:
Create an entity object β†’ persist β†’ listen event β†’ add data to cartoDB via your API β†’ get the identifier of the cartoDB object β†’ update it in the created object

Here is an example for CartoDB Bundle anotations:

/** * @ORM\Entity * @ORM\Table(name="testDB", options={"collate"="utf8_general_ci"}) * @CartoDB\CartoDBLink(connection="private", table="testDB", cascade={"persist", "remove"}) */ class TestDB { /** * @ORM\Column(name="cartodb_index", type="integer", nullable=true) * @CartoDB\CartoDBColumn(column="testdb_id", index=true) */ protected $cartodbId; 

We would like to create tests that cover any part of the code, so we decided to include Entity in the test folder to check synchronization with cartoDB data and add it to the test folder, we performed the following steps:
1- Add the doctrine kit to our composer.json kit.
2- Create an entity class in this route:

 Company/Tests/CartoDB/Entity/TestDB.php 

This object is as follows:

 namespace Company\CartoDBBundle\Tests\CartoDB\Entity; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="testDB", options={"collate"="utf8_general_ci"}) * @CartoDB\CartoDBLink(connection="private", table="testDB", cascade={"persist", "remove"}) */ class TestDB { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; ..... ?> 

3. Now it's his turn to test the script. We use the entity namespace:

 use Company\CartoDBBundle\Tests\CartoDB\Entity\TestDB; 

Next, we create an entity object:

 $test = new TestDB(); $test->setText("HI"); 

It works fine, we call object methods, and everything goes right, and the last pass:

 $em->persist($test); $em->flush(); 

Doctrine \ Common \ Persistence \ Mapping \ MappingException: class 'Company \ CartoDBBundle \ Tests \ CartoDB \ Entity \ TestDB' was not found in the chain name chain
Here is our doctrine configuration:

 doctrine: dbal: driver: pdo_sqlite path: "%kernel.root_dir%/sqlite.db" charset: UTF8 orm: auto_generate_proxy_classes: %kernel.debug% auto_mapping: true 

I don’t know what we are missing; can someone help us?
Thanks!

0
symfony testing bundle doctrine
source share
1 answer

The main problem is that, by default, Doctrine only looks at the Bundle / Entity directory. So you need a little more information in orm: in your configuration file.

The manual contains more detailed information: http://symfony.com/doc/current/reference/configuration/doctrine.html

 doctrine: orm: auto_generate_proxy_classes: %kernel.debug% auto_mapping: false mappings: name: type: php dir: %kernel.root_dir%/../src/Company/CartoDBBundle/Tests/CartoDB/Entity # alias: MyModels # prefix: MyBundle\OtherNamespacePart\Entity # is_bundle: true 

You might need futz with aliases and prefixes. When it is configured correctly, run:

 app/console doctrine:schema:update --dump-sql 

Resets table data.

0
source share

All Articles