1
0
mirror of synced 2025-01-19 06:51:40 +03:00

81 lines
2.4 KiB
PHP
Raw Normal View History

<?php
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Export\ClassExporter;
use Doctrine\Tests\Models\CMS\CmsUser;
use Doctrine\Tests\Models\CMS\CmsPhonenumber;
require_once __DIR__ . '/../../TestInit.php';
/**
* Description of BasicCRUDTest
*
* @author robo
*/
class BasicCRUDTest extends \Doctrine\Tests\OrmFunctionalTestCase {
public function testSingleEntityCRUD() {
$em = $this->_em;
$exporter = new ClassExporter($this->_em);
2009-01-08 11:23:24 +00:00
$exporter->exportClasses(array(
$this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'),
$this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsPhonenumber')
));
// Create
$user = new CmsUser;
$user->name = 'romanb';
$em->save($user);
$this->assertTrue(is_numeric($user->id));
$this->assertTrue($em->contains($user));
// Read
$user2 = $em->find('Doctrine\Tests\Models\CMS\CmsUser', $user->id);
$this->assertTrue($user === $user2);
2009-01-08 11:23:24 +00:00
// Add a phonenumber
2009-01-08 11:23:24 +00:00
$ph = new CmsPhonenumber;
$ph->phonenumber = "12345";
$user->addPhonenumber($ph);
$em->flush();
$this->assertTrue($em->contains($ph));
$this->assertTrue($em->contains($user));
2009-01-29 17:00:44 +00:00
$this->assertTrue($user->phonenumbers instanceof \Doctrine\ORM\Collection);
2009-01-08 11:23:24 +00:00
2009-01-29 17:00:44 +00:00
// Update name
$user->name = 'guilherme';
$em->flush();
$this->assertEquals('guilherme', $user->name);
2009-01-29 17:00:44 +00:00
// Add another phonenumber
$ph2 = new CmsPhonenumber;
$ph2->phonenumber = "6789";
$user->addPhonenumber($ph2);
$em->flush();
$this->assertTrue($em->contains($ph2));
// Delete
$em->delete($user);
$this->assertTrue($em->getUnitOfWork()->isRegisteredRemoved($user));
2009-01-29 17:00:44 +00:00
$this->assertTrue($em->getUnitOfWork()->isRegisteredRemoved($ph));
$this->assertTrue($em->getUnitOfWork()->isRegisteredRemoved($ph2));
$em->flush();
$this->assertFalse($em->getUnitOfWork()->isRegisteredRemoved($user));
2009-01-29 17:00:44 +00:00
$this->assertFalse($em->getUnitOfWork()->isRegisteredRemoved($ph));
$this->assertFalse($em->getUnitOfWork()->isRegisteredRemoved($ph2));
}
2009-01-08 11:23:24 +00:00
2009-01-29 17:00:44 +00:00
/*public function testMore() {
$ph = new CmsPhonenumber;
$ph->phonenumber = 123456;
$this->_em->save($ph);
$this->_em->flush();
2009-01-29 17:00:44 +00:00
}*/
}