We have created a bundle to integrate CartoDB in Symfony2 projects. This bundle doesn't create any entity itself, because it 'listen' for events such as persist or flush on your own entities to synchronize info between your data and cartodb data. Here is the workflow:
Create an entity object --> persist --> listen event --> add data to cartoDB throught their API --> get cartoDB object id --> update it in your created object
Here is an example for CartoDB Bundle annotations:
/**
* @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 have decided to include an Entity in the test folder to test synchronization with cartoDB data, and add it in the test folder, we have followed this steps:
- Add Doctrine Bundle to our bundle composer.json.
- Create an entity class in this route:
Company/Tests/CartoDB/Entity/TestDB.php
This entity looks like this:
<?php
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;
.....
?>
Now its turn for the test 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 runs ok, we call objects methods and everything goes right, and last pass:
$em->persist($test);
$em->flush();
Doctrine\Common\Persistence\Mapping\MappingException: The class 'Company\CartoDBBundle\Tests\CartoDB\Entity\TestDB' was not found in the chain configured namespaces
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
Don't know what we are missing, can anyone help us?