public function setUp()
 {
     $conn = new PDO('sqlite::memory:');
     $db = new Db($conn);
     $conn->exec((string) Sql::createTable('post', array('id INTEGER PRIMARY KEY', 'title VARCHAR(255)', 'text TEXT')));
     $conn->exec((string) Sql::createTable('comment', array('id INTEGER PRIMARY KEY', 'post_id INTEGER', 'text TEXT')));
     $conn->exec((string) Sql::createTable('category', array('id INTEGER PRIMARY KEY', 'name VARCHAR(255)', 'category_id INTEGER')));
     $conn->exec((string) Sql::createTable('post_category', array('id INTEGER PRIMARY KEY', 'post_id INTEGER', 'category_id INTEGER')));
     $posts = array(array('id' => 5, 'title' => 'Post Title', 'text' => 'Post Text'));
     $comments = array(array('id' => 7, 'post_id' => 5, 'text' => 'Comment Text'), array('id' => 8, 'post_id' => 4, 'text' => 'Comment Text 2'));
     $categories = array(array('id' => 2, 'name' => 'Sample Category'), array('id' => 3, 'name' => 'NONON'));
     $postsCategories = array(array('id' => 66, 'post_id' => 5, 'category_id' => 2));
     foreach ($posts as $post) {
         $db->insertInto('post', $post)->values($post)->exec();
     }
     foreach ($comments as $comment) {
         $db->insertInto('comment', $comment)->values($comment)->exec();
     }
     foreach ($categories as $category) {
         $db->insertInto('category', $category)->values($category)->exec();
     }
     foreach ($postsCategories as $postCategory) {
         $db->insertInto('post_category', $postCategory)->values($postCategory)->exec();
     }
     $mapper = new Mapper($conn);
     $this->object = $mapper;
     $this->conn = $conn;
 }
Beispiel #2
0
 protected function createStatement(Collection $collection, $withExtra = null)
 {
     $query = $this->generateQuery($collection);
     if ($withExtra instanceof Sql) {
         $query->appendQuery($withExtra);
     }
     $statement = $this->db->prepare((string) $query, PDO::FETCH_NUM);
     $statement->execute($query->getParams());
     return $statement;
 }
Beispiel #3
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__ . '\\';
 }
Beispiel #4
0
 public function setUp()
 {
     $conn = new PDO('sqlite::memory:');
     $db = new Db($conn);
     $conn->exec((string) Sql::createTable('post', array('id INTEGER PRIMARY KEY', 'title VARCHAR(255)', 'text TEXT', 'author_id INTEGER')));
     $conn->exec((string) Sql::createTable('author', array('id INTEGER PRIMARY KEY', 'name VARCHAR(255)')));
     $conn->exec((string) Sql::createTable('comment', array('id INTEGER PRIMARY KEY', 'post_id INTEGER', 'text TEXT', 'datetime DATETIME')));
     $conn->exec((string) Sql::createTable('category', array('id INTEGER PRIMARY KEY', 'name VARCHAR(255)', 'category_id INTEGER')));
     $conn->exec((string) Sql::createTable('post_category', array('id INTEGER PRIMARY KEY', 'post_id INTEGER', 'category_id INTEGER')));
     $conn->exec((string) Sql::createTable('issues', array('id INTEGER PRIMARY KEY', 'type VARCHAR(255)', 'title VARCHAR(22)')));
     $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', 'datetime' => '2012-06-19 00:35:42'), (object) array('id' => 8, 'post_id' => 4, 'text' => 'Comment Text 2', 'datetime' => '2012-06-19 00:35:42'));
     $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));
     $this->issues = array((object) array('id' => 1, 'type' => 'bug', 'title' => 'Bug 1'), (object) array('id' => 2, 'type' => 'improvement', 'title' => 'Improvement 1'));
     foreach ($this->authors as $author) {
         $db->insertInto('author', (array) $author)->values((array) $author)->exec();
     }
     foreach ($this->posts as $post) {
         $db->insertInto('post', (array) $post)->values((array) $post)->exec();
     }
     foreach ($this->comments as $comment) {
         $db->insertInto('comment', (array) $comment)->values((array) $comment)->exec();
     }
     foreach ($this->categories as $category) {
         $db->insertInto('category', (array) $category)->values((array) $category)->exec();
     }
     foreach ($this->postsCategories as $postCategory) {
         $db->insertInto('post_category', (array) $postCategory)->values((array) $postCategory)->exec();
     }
     foreach ($this->issues as $issue) {
         $db->insertInto('issues', (array) $issue)->values((array) $issue)->exec();
     }
     $mapper = new Mapper($conn);
     $this->mapper = $mapper;
     $this->conn = $conn;
 }