Esempio n. 1
0
 public function setUp()
 {
     $conn = new PDO('sqlite::memory:');
     $db = new Db($conn);
     $conn->exec((string) Sql::createTable('posts', array('id INTEGER PRIMARY KEY', 'title VARCHAR(255)', 'text TEXT', 'author_id INTEGER')));
     $conn->exec((string) Sql::createTable('authors', array('id INTEGER PRIMARY KEY', 'name VARCHAR(255)')));
     $conn->exec((string) Sql::createTable('comments', array('id INTEGER PRIMARY KEY', 'post_id INTEGER', 'text TEXT')));
     $conn->exec((string) Sql::createTable('categories', array('id INTEGER PRIMARY KEY', 'name VARCHAR(255)', 'category_id INTEGER')));
     $conn->exec((string) Sql::createTable('post_categories', array('id INTEGER PRIMARY KEY', 'post_id INTEGER', 'category_id INTEGER')));
     $this->posts = array((object) array('id' => 5, 'title' => 'Post Title', 'text' => 'Post Text', 'author_id' => 1));
     $this->authors = array((object) array('id' => 1, 'name' => 'Author 1'));
     $this->comments = array((object) array('id' => 7, 'post_id' => 5, 'text' => 'Comment Text'), (object) array('id' => 8, 'post_id' => 4, 'text' => 'Comment Text 2'));
     $this->categories = array((object) array('id' => 2, 'name' => 'Sample Category', 'category_id' => null), (object) array('id' => 3, 'name' => 'NONON', 'category_id' => null));
     $this->postsCategories = array((object) array('id' => 66, 'post_id' => 5, 'category_id' => 2));
     foreach ($this->authors as $author) {
         $db->insertInto('authors', (array) $author)->values((array) $author)->exec();
     }
     foreach ($this->posts as $post) {
         $db->insertInto('posts', (array) $post)->values((array) $post)->exec();
     }
     foreach ($this->comments as $comment) {
         $db->insertInto('comments', (array) $comment)->values((array) $comment)->exec();
     }
     foreach ($this->categories as $category) {
         $db->insertInto('categories', (array) $category)->values((array) $category)->exec();
     }
     foreach ($this->postsCategories as $postCategory) {
         $db->insertInto('post_categories', (array) $postCategory)->values((array) $postCategory)->exec();
     }
     $this->conn = $conn;
     $this->style = new CakePHP();
     $this->mapper = new Mapper($conn);
     $this->mapper->setStyle($this->style);
     $this->mapper->entityNamespace = __NAMESPACE__ . '\\';
 }
Esempio n. 2
0
 public function test_ignoring_last_insert_id_errors()
 {
     $conn = $this->getMock('PDO', array('lastInsertId'), array('sqlite::memory:'));
     $conn->exec('CREATE TABLE foo(id INTEGER PRIMARY KEY)');
     $conn->expects($this->any())->method('lastInsertId')->will($this->throwException(new \PDOException()));
     $mapper = new Mapper($conn);
     $obj = new \stdClass();
     $obj->id = null;
     $mapper->foo->persist($obj);
     $mapper->flush();
     //Ok, should not throw PDOException on this.
 }
Esempio n. 3
0
 public function testeInflectedTypedEntityName()
 {
     $db = new Db($this->conn);
     $schema = new SchemaDecorators\Typed(new SchemaDecorators\Inflected(new Schemas\Infered()), __NAMESPACE__);
     $mapper = new Mapper($db, $schema);
     $c66 = $mapper->postCategory[66]->fetch();
     $this->assertInstanceOf(__NAMESPACE__ . '\\PostCategory', $c66);
     $this->assertObjectHasAttribute('postId', $c66);
     $c66->categoryId = 3;
     $mapper->persist($c66);
     $mapper->flush();
 }