PageRenderTime 23ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 0ms app.codeStats 0ms

/library/Zend/Test/PHPUnit/Db/DataSet/QueryTable.php

https://bitbucket.org/hamidrezas/melobit
PHP | 91 lines | 35 code | 5 blank | 51 comment | 4 complexity | 2d8cdac7ccbcf9cd688372ba23649f30 MD5 | raw file
Possible License(s): AGPL-1.0
 1<?php
 2/**
 3 * Zend Framework
 4 *
 5 * LICENSE
 6 *
 7 * This source file is subject to the new BSD license that is bundled
 8 * with this package in the file LICENSE.txt.
 9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
14 *
15 * @category   Zend
16 * @package    Zend_Test
17 * @subpackage PHPUnit
18 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
20 * @version    $Id: QueryTable.php 24594 2012-01-05 21:27:01Z matthew $
21 */
22
23/**
24 * @see PHPUnit_Extensions_Database_DataSet_QueryTable
25 */
26require_once "PHPUnit/Extensions/Database/DataSet/QueryTable.php";
27
28/**
29 * @see PHPUnit_Extensions_Database_DB_IDatabaseConnection
30 */
31require_once "PHPUnit/Extensions/Database/DB/IDatabaseConnection.php";
32
33/**
34 * Represent a PHPUnit Database Extension table with Queries using a Zend_Db adapter for assertion against other tables.
35 *
36 * @uses       PHPUnit_Extensions_Database_DataSet_QueryTable
37 * @category   Zend
38 * @package    Zend_Test
39 * @subpackage PHPUnit
40 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
41 * @license    http://framework.zend.com/license/new-bsd     New BSD License
42 */
43class Zend_Test_PHPUnit_Db_DataSet_QueryTable extends PHPUnit_Extensions_Database_DataSet_QueryTable
44{
45    /**
46     * Creates a new database query table object.
47     *
48     * @param string $table_name
49     * @param string $query
50     * @param PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection
51     */
52    public function __construct($tableName, $query, PHPUnit_Extensions_Database_DB_IDatabaseConnection $databaseConnection)
53    {
54        if( !($databaseConnection instanceof Zend_Test_PHPUnit_Db_Connection) ) {
55            require_once "Zend/Test/PHPUnit/Db/Exception.php";
56            throw new Zend_Test_PHPUnit_Db_Exception("Zend_Test_PHPUnit_Db_DataSet_QueryTable only works with Zend_Test_PHPUnit_Db_Connection connections-");
57        }
58        parent::__construct($tableName, $query, $databaseConnection);
59    }
60
61    /**
62     * Load data from the database.
63     *
64     * @return void
65     */
66    protected function loadData()
67    {
68        if($this->data === null) {
69            $stmt = $this->databaseConnection->getConnection()->query($this->query);
70            $this->data = $stmt->fetchAll(Zend_Db::FETCH_ASSOC);
71        }
72    }
73
74    /**
75     * Create Table Metadata
76     */
77    protected function createTableMetaData()
78    {
79        if ($this->tableMetaData === NULL)
80        {
81            $this->loadData();
82            $keys = array();
83            if(count($this->data) > 0) {
84                $keys = array_keys($this->data[0]);
85            }
86            $this->tableMetaData = new PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData(
87                $this->tableName, $keys
88            );
89        }
90    }
91}