Exemple #1
0
 public function testCreateWithManyToManyAssociations()
 {
     $this->pdo->exec("CREATE TABLE blogs ( id INTEGER PRIMARY KEY, title TEXT )");
     $this->pdo->exec("CREATE TABLE tags ( id INTEGER PRIMARY KEY, name TEXT )");
     $this->pdo->exec("CREATE TABLE blogs_tags ( blog_id INTEGER, tag_id INTEGER )");
     Phactory::define('tag', array('name' => 'Test Tag'));
     Phactory::define('blog', array('title' => 'Test Title'), array('tags' => Phactory::manyToMany('tags', 'blogs_tags', 'id', 'blog_id', 'tag_id', 'id')));
     $tags = array(Phactory::create('tag'), Phactory::create('tag'));
     $blog = Phactory::createWithAssociations('blog', array('tags' => $tags));
     $result = $this->pdo->query("SELECT * FROM blogs_tags");
     foreach ($tags as $tag) {
         $row = $result->fetch();
         $this->assertNotEquals(false, $row);
         $this->assertEquals($blog->getId(), $row['blog_id']);
         $this->assertEquals($tag->getId(), $row['tag_id']);
     }
     $result->closeCursor();
     $this->pdo->exec("DROP TABLE blogs");
     $this->pdo->exec("DROP TABLE tags");
     $this->pdo->exec("DROP TABLE blogs_tags");
 }
Exemple #2
0
 public function testCreateWithEmbedsManyAssociation()
 {
     Phactory::define('tag', array('name' => 'Test Tag'));
     Phactory::define('blog', array('title' => 'Test Title'), array('tags' => Phactory::embedsMany('tag')));
     $tag = Phactory::build('tag');
     $blog = Phactory::createWithAssociations('blog', array('tags' => array($tag)));
     $this->assertEquals('Test Tag', $blog['tags'][0]['name']);
     $this->db->blogs->drop();
 }