We are happy to inform You, that our fitness service MapaFitness.pl is back online.
We’ll try to restore features one by one, because of our technical problems. For now the basic features are avilable :)
Sometimes you want to test something against database. You could use WebTestCase to get the current kernel and its all services, including Entity Manager, but also you could initialize Enitity Manager in \PHPUnit_Framework_TestCase
protected $entityManager = null;
public function setUp()
{
$conn = \Doctrine\DBAL\DriverManager::getConnection(array(
'driver' => 'pdo_sqlite',
'memory' => true
));
$config = new \Doctrine\ORM\Configuration();
$config->setAutoGenerateProxyClasses(true);
$config->setProxyDir(\sys_get_temp_dir());
$config->setProxyNamespace('BrillanteTests\Entities');
$config->setMetadataDriverImpl(new AnnotationDriver(new IndexedReader(new AnnotationReader())));
$config->setQueryCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
$params = array(
'driver' => 'pdo_sqlite',
'memory' => true,
);
$this->entityManager = \Doctrine\ORM\EntityManager::create($params, $config);
$schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->entityManager);
$classes = array(
$this->entityManager->getClassMetadata("\Brillante\SampleBundle\Entity\Account"),
$this->entityManager->getClassMetadata("\Brillante\SampleBundle\Entity\User"),
);
$schemaTool->dropSchema($classes);
$schemaTool->createSchema($classes);
}
We initialize the default in memory sqllite db, load the metadata, recreate schema for entities that you want to use. Then you can do persisting and flushing on $entityManager :)
If you’re missing the rails object.valid? in assertions in Symfony, there is quick littke solution to that. We build the default validator context and with its use, we can test properties and objects of our Entites. It reads annotations by default. If you are using yml or xml, you must provide paths.
public function testIncorrectValuesOfUsernameWhileCallingValidation()
{
$v = \Symfony\Component\Validator\ValidatorFactory::buildDefault();
$validator = $v->getValidator();
$not_valid = array(
'as', '1234567890_234567890_234567890_234567890_dadadwadwad231',
"tab\t", "newline\n",
"Iñtërnâtiônàlizætiøn hasn't happened to ", 'trśżź',
'semicolon;', 'quote"', 'tick\'', 'backtick`', 'percent%', 'plus+', 'space ', 'mich@l'
);
foreach ($not_valid as $key) {
$violations = $validator->validatePropertyValue("\Brillante\SampleBundle\Entity\User", "username", $key);
$this->assertGreaterThan(0, count($violations) ,"dissalow username to be ($key)");
}
}
Our team have attended Symfony Live conference in Paris in march this year. We have recently started first internal project with Symfony2. We’ll keep you informed :)
Welcome,
from today we are starting our brillante.pl web blog. We’ll be discussing mostly the technical issues related with Ruby on Rails and Symfony2.
Kind regards,
brillante.pl Team :)
Design by Simon Fletcher. Powered by Tumblr.
© Copyright 2010