From 196c5310ec739eef59a53dd73635f5681e8858d4 Mon Sep 17 00:00:00 2001 From: Maks3w Date: Thu, 12 Jul 2012 21:11:36 +0200 Subject: [PATCH 1/2] [PSR-2] fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed Applied php-cs-fixer --fixers=braces,elseif,short_tag,php_closing_tag,trailing_spaces,linefeed --- src/DbAdapter.php | 4 ++-- src/PHPUnit/Db/DataSet/QueryTable.php | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/DbAdapter.php b/src/DbAdapter.php index ed28ab0dcf..59d363c4a6 100644 --- a/src/DbAdapter.php +++ b/src/DbAdapter.php @@ -46,7 +46,7 @@ class DbAdapter extends \Zend\Db\Adapter\AbstractAdapter /** * @var string - */ + */ protected $_quoteIdentifierSymbol = ''; /** @@ -85,7 +85,7 @@ public function appendLastInsertIdToStack($id) /** * @var string - */ + */ public function setQuoteIdentifierSymbol($symbol) { $this->_quoteIdentifierSymbol = $symbol; diff --git a/src/PHPUnit/Db/DataSet/QueryTable.php b/src/PHPUnit/Db/DataSet/QueryTable.php index 41ca3731cb..80aec58127 100644 --- a/src/PHPUnit/Db/DataSet/QueryTable.php +++ b/src/PHPUnit/Db/DataSet/QueryTable.php @@ -54,8 +54,7 @@ protected function loadData() */ protected function createTableMetaData() { - if ($this->tableMetaData === NULL) - { + if ($this->tableMetaData === NULL) { $this->loadData(); $keys = array(); if(count($this->data) > 0) { From e9d9842338b3bb539c1b702a9f8c7df86bd68348 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Thu, 12 Jul 2012 15:49:12 -0500 Subject: [PATCH 2/2] [zen-78] Removal of Test component - Many of the assertion types in here are now available in PHPUnit, albeit with different syntax. Additionally, the main thrust of this was for testing ZF1 applications, and as such, has little relevance to ZF2 (other than the query selectors, which are in PHPUnit). Finally, the DB component has not been refactored for ZF2, and we may want to approach this differently anyways. --- composer.json | 6 +- src/DbAdapter.php | 318 -------------- src/DbStatement.php | 388 ------------------ src/Exception/ExceptionInterface.php | 15 - src/Exception/InvalidArgumentException.php | 15 - src/PHPUnit/AbstractDatabaseTestCase.php | 108 ----- src/PHPUnit/Db/Connection.php | 120 ------ src/PHPUnit/Db/DataSet/DbRowset.php | 54 --- src/PHPUnit/Db/DataSet/DbTable.php | 102 ----- src/PHPUnit/Db/DataSet/DbTableDataSet.php | 83 ---- src/PHPUnit/Db/DataSet/QueryDataSet.php | 60 --- src/PHPUnit/Db/DataSet/QueryTable.php | 68 --- src/PHPUnit/Db/Exception.php | 15 - .../Db/Exception/InvalidArgumentException.php | 16 - src/PHPUnit/Db/Metadata/Generic.php | 144 ------- src/PHPUnit/Db/Operation/DeleteAll.php | 43 -- src/PHPUnit/Db/Operation/Insert.php | 67 --- src/PHPUnit/Db/Operation/Truncate.php | 92 ----- src/PHPUnit/Db/SimpleTester.php | 53 --- src/PHPUnit/Exception/ExceptionInterface.php | 17 - .../Exception/InvalidArgumentException.php | 17 - test/DbAdapterTest.php | 158 ------- test/DbStatementTest.php | 151 ------- test/PHPUnit/Db/ConnectionTest.php | 78 ---- test/PHPUnit/Db/DataSet/DataSetTestCase.php | 42 -- test/PHPUnit/Db/DataSet/DbRowsetTest.php | 83 ---- .../PHPUnit/Db/DataSet/DbTableDataSetTest.php | 59 --- test/PHPUnit/Db/DataSet/DbTableTest.php | 74 ---- test/PHPUnit/Db/DataSet/QueryDataSetTest.php | 58 --- test/PHPUnit/Db/DataSet/QueryTableTest.php | 106 ----- .../Db/Integration/AbstractTestCase.php | 119 ------ .../Db/Integration/MysqlIntegrationTest.php | 55 --- .../Db/Integration/SqLiteIntegrationTest.php | 39 -- .../_files/sqliteIntegrationFixture.xml | 6 - test/PHPUnit/Db/Metadata/GenericTest.php | 96 ----- test/PHPUnit/Db/Operation/DeleteAllTest.php | 72 ---- test/PHPUnit/Db/Operation/InsertTest.php | 72 ---- test/PHPUnit/Db/Operation/TruncateTest.php | 96 ----- .../Db/Operation/_files/insertFixture.xml | 6 - .../Db/Operation/_files/truncateFixture.xml | 5 - test/PHPUnit/Db/SimpleTesterTest.php | 66 --- test/PHPUnit/Db/TestCaseTest.php | 99 ----- 42 files changed, 3 insertions(+), 3338 deletions(-) delete mode 100644 src/DbAdapter.php delete mode 100644 src/DbStatement.php delete mode 100644 src/Exception/ExceptionInterface.php delete mode 100644 src/Exception/InvalidArgumentException.php delete mode 100644 src/PHPUnit/AbstractDatabaseTestCase.php delete mode 100644 src/PHPUnit/Db/Connection.php delete mode 100644 src/PHPUnit/Db/DataSet/DbRowset.php delete mode 100644 src/PHPUnit/Db/DataSet/DbTable.php delete mode 100644 src/PHPUnit/Db/DataSet/DbTableDataSet.php delete mode 100644 src/PHPUnit/Db/DataSet/QueryDataSet.php delete mode 100644 src/PHPUnit/Db/DataSet/QueryTable.php delete mode 100644 src/PHPUnit/Db/Exception.php delete mode 100644 src/PHPUnit/Db/Exception/InvalidArgumentException.php delete mode 100644 src/PHPUnit/Db/Metadata/Generic.php delete mode 100644 src/PHPUnit/Db/Operation/DeleteAll.php delete mode 100644 src/PHPUnit/Db/Operation/Insert.php delete mode 100644 src/PHPUnit/Db/Operation/Truncate.php delete mode 100644 src/PHPUnit/Db/SimpleTester.php delete mode 100644 src/PHPUnit/Exception/ExceptionInterface.php delete mode 100644 src/PHPUnit/Exception/InvalidArgumentException.php delete mode 100644 test/DbAdapterTest.php delete mode 100644 test/DbStatementTest.php delete mode 100644 test/PHPUnit/Db/ConnectionTest.php delete mode 100644 test/PHPUnit/Db/DataSet/DataSetTestCase.php delete mode 100644 test/PHPUnit/Db/DataSet/DbRowsetTest.php delete mode 100644 test/PHPUnit/Db/DataSet/DbTableDataSetTest.php delete mode 100644 test/PHPUnit/Db/DataSet/DbTableTest.php delete mode 100644 test/PHPUnit/Db/DataSet/QueryDataSetTest.php delete mode 100644 test/PHPUnit/Db/DataSet/QueryTableTest.php delete mode 100644 test/PHPUnit/Db/Integration/AbstractTestCase.php delete mode 100644 test/PHPUnit/Db/Integration/MysqlIntegrationTest.php delete mode 100644 test/PHPUnit/Db/Integration/SqLiteIntegrationTest.php delete mode 100644 test/PHPUnit/Db/Integration/_files/sqliteIntegrationFixture.xml delete mode 100644 test/PHPUnit/Db/Metadata/GenericTest.php delete mode 100644 test/PHPUnit/Db/Operation/DeleteAllTest.php delete mode 100644 test/PHPUnit/Db/Operation/InsertTest.php delete mode 100644 test/PHPUnit/Db/Operation/TruncateTest.php delete mode 100644 test/PHPUnit/Db/Operation/_files/insertFixture.xml delete mode 100644 test/PHPUnit/Db/Operation/_files/truncateFixture.xml delete mode 100644 test/PHPUnit/Db/SimpleTesterTest.php delete mode 100644 test/PHPUnit/Db/TestCaseTest.php diff --git a/composer.json b/composer.json index 1d1320e24d..1b62ce2086 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "zendframework/zend-test", - "description": "provides tools to facilitate unit testing of your Zend Framework applications", + "description": "Zend\\Test component", "license": "BSD-3-Clause", "keywords": [ "zf2", @@ -9,11 +9,11 @@ "homepage": "https://github.com/zendframework/zend-test", "autoload": { "psr-4": { - "Zend\\Test": "src/" + "Zend\\Test\\": "src/" } }, "require": { - "php": ">=5.3.3", + "php": ">=5.3.23", "phpunit/PHPUnit": "~4.0", "zendframework/zend-console": "self.version", "zendframework/zend-dom": "self.version", diff --git a/src/DbAdapter.php b/src/DbAdapter.php deleted file mode 100644 index 59d363c4a6..0000000000 --- a/src/DbAdapter.php +++ /dev/null @@ -1,318 +0,0 @@ -setEnabled(true); - $this->setProfiler($profiler); - } - - /** - * Append a new Statement to the SQL Result Stack. - * - * @param \Zend\Test\DbStatement $stmt - * @return \Zend\Test\DbAdapter - */ - public function appendStatementToStack(DbStatement $stmt) - { - array_push($this->_statementStack, $stmt); - return $this; - } - - /** - * Append a new Insert Id to the {@see lastInsertId}. - * - * @param int|string $id - * @return \Zend\Test\DbAdapter - */ - public function appendLastInsertIdToStack($id) - { - array_push($this->_lastInsertIdStack, $id); - return $this; - } - - /** - * @var string - */ - public function setQuoteIdentifierSymbol($symbol) - { - $this->_quoteIdentifierSymbol = $symbol; - } - - /** - * Returns the symbol the adapter uses for delimited identifiers. - * - * @return string - */ - public function getQuoteIdentifierSymbol() - { - return $this->_quoteIdentifierSymbol; - } - - /** - * Set the result from {@see listTables()}. - * - * @param array $listTables - */ - public function setListTables(array $listTables) - { - $this->_listTables = $listTables; - } - - /** - * Returns a list of the tables in the database. - * - * @return array - */ - public function listTables() - { - return $this->_listTables; - } - - /** - * - * @param string $table - * @param array $tableInfo - * @return \Zend\Test\DbAdapter - */ - public function setDescribeTable($table, $tableInfo) - { - $this->_describeTables[$table] = $tableInfo; - return $this; - } - - /** - * Returns the column descriptions for a table. - * - * The return value is an associative array keyed by the column name, - * as returned by the RDBMS. - * - * The value of each array element is an associative array - * with the following keys: - * - * SCHEMA_NAME => string; name of database or schema - * TABLE_NAME => string; - * COLUMN_NAME => string; column name - * COLUMN_POSITION => number; ordinal position of column in table - * DATA_TYPE => string; SQL datatype name of column - * DEFAULT => string; default expression of column, null if none - * NULLABLE => boolean; true if column can have nulls - * LENGTH => number; length of CHAR/VARCHAR - * SCALE => number; scale of NUMERIC/DECIMAL - * PRECISION => number; precision of NUMERIC/DECIMAL - * UNSIGNED => boolean; unsigned property of an integer type - * PRIMARY => boolean; true if column is part of the primary key - * PRIMARY_POSITION => integer; position of column in primary key - * - * @param string $tableName - * @param string $schemaName OPTIONAL - * @return array - */ - public function describeTable($tableName, $schemaName = null) - { - if(isset($this->_describeTables[$tableName])) { - return $this->_describeTables[$tableName]; - } else { - return array(); - } - } - - /** - * Creates a connection to the database. - * - * @return void - */ - protected function _connect() - { - $this->_connected = true; - } - - /** - * Test if a connection is active - * - * @return boolean - */ - public function isConnected() - { - return $this->_connected; - } - - /** - * Force the connection to close. - * - * @return void - */ - public function closeConnection() - { - $this->_connected = false; - } - - /** - * Prepare a statement and return a PDOStatement-like object. - * - * @param string|\Zend\DB\Select $sql SQL query - * @return Zend_Db_Statment|PDOStatement - */ - public function prepare($sql) - { - $queryId = $this->getProfiler()->queryStart($sql); - - if(count($this->_statementStack)) { - $stmt = array_pop($this->_statementStack); - } else { - $stmt = new DbStatement(); - } - - if($this->getProfiler()->getEnabled() == true) { - $qp = $this->getProfiler()->getQueryProfile($queryId); - $stmt->setQueryProfile($qp); - } - - return $stmt; - } - - /** - * Gets the last ID generated automatically by an IDENTITY/AUTOINCREMENT column. - * - * As a convention, on RDBMS brands that support sequences - * (e.g. Oracle, PostgreSQL, DB2), this method forms the name of a sequence - * from the arguments and returns the last id generated by that sequence. - * On RDBMS brands that support IDENTITY/AUTOINCREMENT columns, this method - * returns the last value generated for such a column, and the table name - * argument is disregarded. - * - * @param string $tableName OPTIONAL Name of table. - * @param string $primaryKey OPTIONAL Name of primary key column. - * @return string - */ - public function lastInsertId($tableName = null, $primaryKey = null) - { - if(count($this->_lastInsertIdStack)) { - return array_pop($this->_lastInsertIdStack); - } else { - return false; - } - } - - /** - * Begin a transaction. - */ - protected function _beginTransaction() - { - return; - } - - /** - * Commit a transaction. - */ - protected function _commit() - { - return; - } - - /** - * Roll-back a transaction. - */ - protected function _rollBack() - { - - } - - /** - * Set the fetch mode. - * - * @param integer $mode - * @return void - * @throws \Zend\Db\Adapter\Exception - */ - public function setFetchMode($mode) - { - return; - } - - /** - * Adds an adapter-specific LIMIT clause to the SELECT statement. - * - * @param mixed $sql - * @param integer $count - * @param integer $offset - * @return string - */ - public function limit($sql, $count, $offset = 0) - { - return sprintf('%s LIMIT %d,%d', $sql, $offset, $count); - } - - /** - * Check if the adapter supports real SQL parameters. - * - * @param string $type 'positional' or 'named' - * @return bool - */ - public function supportsParameters($type) - { - return true; - } - - /** - * Retrieve server version in PHP style - * - * @return string - */ - function getServerVersion() - { - return "1.0.0"; - } -} diff --git a/src/DbStatement.php b/src/DbStatement.php deleted file mode 100644 index 76f08864af..0000000000 --- a/src/DbStatement.php +++ /dev/null @@ -1,388 +0,0 @@ -append($row); - } - return $stmt; - } - - /** - * Create an Insert Statement - * - * @param int $affectedRows - * @return \Zend\Test\DbStatement - */ - static public function createInsertStatement($affectedRows=0) - { - return self::_createRowCountStatement($affectedRows); - } - - /** - * Create an Delete Statement - * - * @param int $affectedRows - * @return \Zend\Test\DbStatement - */ - static public function createDeleteStatement($affectedRows=0) - { - return self::_createRowCountStatement($affectedRows); - } - - /** - * Create an Update Statement - * - * @param int $affectedRows - * @return \Zend\Test\DbStatement - */ - static public function createUpdateStatement($affectedRows=0) - { - return self::_createRowCountStatement($affectedRows); - } - - /** - * Create a Row Count Statement - * - * @param int $affectedRows - * @return \Zend\Test\DbStatement - */ - static protected function _createRowCountStatement($affectedRows) - { - $stmt = new self(); - $stmt->setRowCount($affectedRows); - return $stmt; - } - - /** - * @param \Zend\Db\Profiler\Query $qp - */ - public function setQueryProfile(\Zend\Db\Profiler\Query $qp) - { - $this->_queryProfile = $qp; - } - - /** - * @param int $rowCount - */ - public function setRowCount($rowCount) - { - $this->_rowCount = $rowCount; - } - - /** - * Append a new row to the fetch stack. - * - * @param array $row - */ - public function append($row) - { - $this->_columnCount = count($row); - $this->_fetchStack[] = $row; - } - - /** - * Bind a column of the statement result set to a PHP variable. - * - * @param string $column Name the column in the result set, either by - * position or by name. - * @param mixed $param Reference to the PHP variable containing the value. - * @param mixed $type OPTIONAL - * @return bool - * @throws \Zend\Db\Statement\Exception - */ - public function bindColumn($column, &$param, $type = null) - { - return true; - } - - /** - * Binds a parameter to the specified variable name. - * - * @param mixed $parameter Name the parameter, either integer or string. - * @param mixed $variable Reference to PHP variable containing the value. - * @param mixed $type OPTIONAL Datatype of SQL parameter. - * @param mixed $length OPTIONAL Length of SQL parameter. - * @param mixed $options OPTIONAL Other options. - * @return bool - * @throws \Zend\Db\Statement\Exception - */ - public function bindParam($parameter, &$variable, $type = null, $length = null, $options = null) - { - if($this->_queryProfile !== null) { - $this->_queryProfile->bindParam($parameter, $variable); - } - return true; - } - - /** - * Binds a value to a parameter. - * - * @param mixed $parameter Name the parameter, either integer or string. - * @param mixed $value Scalar value to bind to the parameter. - * @param mixed $type OPTIONAL Datatype of the parameter. - * @return bool - * @throws \Zend\Db\Statement\Exception - */ - public function bindValue($parameter, $value, $type = null) - { - return true; - } - - /** - * Closes the cursor, allowing the statement to be executed again. - * - * @return bool - * @throws \Zend\Db\Statement\Exception - */ - public function closeCursor() - { - return true; - } - - /** - * Returns the number of columns in the result set. - * Returns null if the statement has no result set metadata. - * - * @return int The number of columns. - * @throws \Zend\Db\Statement\Exception - */ - public function columnCount() - { - return $this->_columnCount; - } - - /** - * Retrieves the error code, if any, associated with the last operation on - * the statement handle. - * - * @return string error code. - * @throws \Zend\Db\Statement\Exception - */ - public function errorCode() - { - return false; - } - - /** - * Retrieves an array of error information, if any, associated with the - * last operation on the statement handle. - * - * @return array - * @throws \Zend\Db\Statement\Exception - */ - public function errorInfo() - { - return false; - } - - /** - * Executes a prepared statement. - * - * @param array $params OPTIONAL Values to bind to parameter placeholders. - * @return bool - * @throws \Zend\Db\Statement\Exception - */ - public function execute(array $params = array()) - { - if($this->_queryProfile !== null) { - $this->_queryProfile->bindParams($params); - $this->_queryProfile->end(); - } - return true; - } - - /** - * Fetches a row from the result set. - * - * @param int $style OPTIONAL Fetch mode for this fetch operation. - * @param int $cursor OPTIONAL Absolute, relative, or other. - * @param int $offset OPTIONAL Number for absolute or relative cursors. - * @return mixed Array, object, or scalar depending on fetch mode. - * @throws \Zend\Db\Statement\Exception - */ - public function fetch($style = null, $cursor = null, $offset = null) - { - if(count($this->_fetchStack)) { - $row = array_shift($this->_fetchStack); - return $row; - } else { - return false; - } - } - - /** - * Returns an array containing all of the result set rows. - * - * @param int $style OPTIONAL Fetch mode. - * @param int $col OPTIONAL Column number, if fetch mode is by column. - * @return array Collection of rows, each in a format by the fetch mode. - * @throws \Zend\Db\Statement\Exception - */ - public function fetchAll($style = null, $col = null) - { - $rows = $this->_fetchStack; - $this->_fetchStack = array(); - - return $rows; - } - - /** - * Returns a single column from the next row of a result set. - * - * @param int $col OPTIONAL Position of the column to fetch. - * @return string - * @throws \Zend\Db\Statement\Exception - */ - public function fetchColumn($col = 0) - { - $row = $this->fetch(); - - if($row == false) { - return false; - } else { - if(count($row) < $col) { - throw new Statement\Exception( - "Column Position '".$col."' is out of bounds." - ); - } - - $keys = array_keys($row); - return $row[$keys[$col]]; - } - } - - /** - * Fetches the next row and returns it as an object. - * - * @param string $class OPTIONAL Name of the class to create. - * @param array $config OPTIONAL Constructor arguments for the class. - * @return mixed One object instance of the specified class. - * @throws \Zend\Db\Statement\Exception - */ - public function fetchObject($class = 'stdClass', array $config = array()) - { - if(!class_exists($class)) { - throw new Statement\Exception("Class '".$class."' does not exist!"); - } - - $object = new $class(); - $row = $this->fetch(); - foreach($row AS $k => $v) { - $object->$k = $v; - } - - return $object; - } - - /** - * Retrieve a statement attribute. - * - * @param string $key Attribute name. - * @return mixed Attribute value. - * @throws \Zend\Db\Statement\Exception - */ - public function getAttribute($key) - { - return false; - } - - /** - * Retrieves the next rowset (result set) for a SQL statement that has - * multiple result sets. An example is a stored procedure that returns - * the results of multiple queries. - * - * @return bool - * @throws \Zend\Db\Statement\Exception - */ - public function nextRowset() - { - return false; - } - - /** - * Returns the number of rows affected by the execution of the - * last INSERT, DELETE, or UPDATE statement executed by this - * statement object. - * - * @return int The number of rows affected. - * @throws \Zend\Db\Statement\Exception - */ - public function rowCount() - { - return $this->_rowCount; - } - - /** - * Set a statement attribute. - * - * @param string $key Attribute name. - * @param mixed $val Attribute value. - * @return bool - * @throws \Zend\Db\Statement\Exception - */ - public function setAttribute($key, $val) - { - return true; - } - - /** - * Set the default fetch mode for this statement. - * - * @param int $mode The fetch mode. - * @return bool - * @throws \Zend\Db\Statement\Exception - */ - public function setFetchMode($mode) - { - return true; - } -} diff --git a/src/Exception/ExceptionInterface.php b/src/Exception/ExceptionInterface.php deleted file mode 100644 index 881bd13081..0000000000 --- a/src/Exception/ExceptionInterface.php +++ /dev/null @@ -1,15 +0,0 @@ -getConnection()->getConnection(); - } - - /** - * Returns the database operation executed in test setup. - * - * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation - */ - protected function getSetUpOperation() - { - return new \PHPUnit_Extensions_Database_Operation_Composite(array( - new Db\Operation\Truncate(), - new Db\Operation\Insert(), - )); - } - - /** - * Returns the database operation executed in test cleanup. - * - * @return PHPUnit_Extensions_Database_Operation_DatabaseOperation - */ - protected function getTearDownOperation() - { - return \PHPUnit_Extensions_Database_Operation_Factory::NONE(); - } - - /** - * Create a dataset based on multiple Zend_Db_Table instances - * - * @param array $tables - * @return \Zend\Test\PHPUnit\Db\DataSet\DbTableDataSet - */ - protected function createDbTableDataSet(array $tables=array()) - { - $dataSet = new Db\DataSet\DbTableDataSet(); - foreach($tables AS $table) { - $dataSet->addTable($table); - } - return $dataSet; - } - - /** - * Create a table based on one Zend_Db_Table instance - * - * @param \Zend\Db\Table\AbstractTable $table - * @param string $where - * @param string $order - * @param string $count - * @param string $offset - * @return \Zend\Test\PHPUnit\Db\DataSet\DbTable - */ - protected function createDbTable(\Zend\Db\Table\AbstractTable $table, $where=null, $order=null, $count=null, $offset=null) - { - return new Db\DataSet\DbTable($table, $where, $order, $count, $offset); - } - - /** - * Create a data table based on a Zend_Db_Table_Rowset instance - * - * @param \Zend\Db\Table\AbstractRowset $rowset - * @param string - * @return \Zend\Test\PHPUnit\Db\DataSet\DbRowset - */ - protected function createDbRowset(\Zend\Db\Table\AbstractRowset $rowset, $tableName = null) - { - return new Db\DataSet\DbRowset($rowset, $tableName); - } -} diff --git a/src/PHPUnit/Db/Connection.php b/src/PHPUnit/Db/Connection.php deleted file mode 100644 index 673c7a76f2..0000000000 --- a/src/PHPUnit/Db/Connection.php +++ /dev/null @@ -1,120 +0,0 @@ -_connection = $db; - $this->_schema = $schema; - } - - /** - * Close this connection. - * - * @return void - */ - public function close() - { - $this->_connection->closeConnection(); - } - - /** - * Creates a table with the result of the specified SQL statement. - * - * @param string $resultName - * @param string $sql - * @return PHPUnit_Extensions_Database_DataSet_ITable - */ - public function createQueryTable($resultName, $sql) - { - return new DataSet\QueryTable($resultName, $sql, $this); - } - - /** - * Returns a Zend_Db Connection - * - * @return \Zend\Db\Adapter\AbstractAdapter - */ - public function getConnection() - { - return $this->_connection; - } - - /** - * Returns a database metadata object that can be used to retrieve table - * meta data from the database. - * - * @return PHPUnit_Extensions_Database_DB_IMetaData - */ - public function getMetaData() - { - if($this->_metaData === null) { - $this->_metaData = new Metadata\Generic($this->getConnection(), $this->getSchema()); - } - return $this->_metaData; - } - - /** - * Returns the schema for the connection. - * - * @return string - */ - public function getSchema() - { - return $this->_schema; - } - - /** - * Returns the command used to truncate a table. - * - * @return string - */ - public function getTruncateCommand() - { - return "DELETE"; - } -} diff --git a/src/PHPUnit/Db/DataSet/DbRowset.php b/src/PHPUnit/Db/DataSet/DbRowset.php deleted file mode 100644 index 7079dfbee6..0000000000 --- a/src/PHPUnit/Db/DataSet/DbRowset.php +++ /dev/null @@ -1,54 +0,0 @@ -getTable(); - if($table !== null) { - $tableName = $table->info('name'); - } else { - throw new \Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException( - 'No table name was given to Rowset Table and table name cannot be infered from the table, '. - 'because the rowset is disconnected from database.' - ); - } - } - - $this->data = $rowset->toArray(); - - $columns = array(); - if(isset($this->data[0]) > 0) { - $columns = array_keys($this->data[0]); - } else if($rowset->getTable() != null) { - $columns = $rowset->getTable()->info('cols'); - } - - $this->tableName = $tableName; - $this->tableMetaData = new \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($this->tableName, $columns); - } -} diff --git a/src/PHPUnit/Db/DataSet/DbTable.php b/src/PHPUnit/Db/DataSet/DbTable.php deleted file mode 100644 index 484ce1c6e9..0000000000 --- a/src/PHPUnit/Db/DataSet/DbTable.php +++ /dev/null @@ -1,102 +0,0 @@ -tableName = $table->info('name'); - $this->_columns = $table->info('cols'); - - $this->_table = $table; - $this->_where = $where; - $this->_order = $order; - $this->_count = $count; - $this->_offset = $offset; - } - - /** - * Lazy load data via table fetchAll() method. - * - * @return void - */ - protected function loadData() - { - if ($this->data === null) { - $this->data = $this->_table->fetchAll( - $this->_where, $this->_order, $this->_count, $this->_offset - ); - if($this->data instanceof \Zend\Db\Table\AbstractRowset) { - $this->data = $this->data->toArray(); - } - } - } - - /** - * Create Table Metadata object - */ - protected function createTableMetaData() - { - if ($this->tableMetaData === NULL) { - $this->loadData(); - $this->tableMetaData = new \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData($this->tableName, $this->_columns); - } - } -} diff --git a/src/PHPUnit/Db/DataSet/DbTableDataSet.php b/src/PHPUnit/Db/DataSet/DbTableDataSet.php deleted file mode 100644 index 5e29b6030d..0000000000 --- a/src/PHPUnit/Db/DataSet/DbTableDataSet.php +++ /dev/null @@ -1,83 +0,0 @@ -info('name'); - $this->tables[$tableName] = new DbTable($table, $where, $order, $count, $offset); - } - - /** - * Creates an iterator over the tables in the data set. If $reverse is - * true a reverse iterator will be returned. - * - * @param bool $reverse - * @return PHPUnit_Extensions_Database_DB_TableIterator - */ - protected function createIterator($reverse = \FALSE) - { - return new \PHPUnit\Extensions\Database\DataSet\DefaultTableIterator($this->tables, $reverse); - } - - /** - * Returns a table object for the given table. - * - * @param string $tableName - * @return PHPUnit_Extensions_Database_DB_Table - */ - public function getTable($tableName) - { - if (!isset($this->tables[$tableName])) { - throw new \Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException( - "$tableName is not a table in the current database." - ); - } - - return $this->tables[$tableName]; - } - - /** - * Returns a list of table names for the database - * - * @return Array - */ - public function getTableNames() - { - return array_keys($this->tables); - } -} diff --git a/src/PHPUnit/Db/DataSet/QueryDataSet.php b/src/PHPUnit/Db/DataSet/QueryDataSet.php deleted file mode 100644 index b2c98ff270..0000000000 --- a/src/PHPUnit/Db/DataSet/QueryDataSet.php +++ /dev/null @@ -1,60 +0,0 @@ -databaseConnection = $databaseConnection; - } - - /** - * Add a Table dataset representation by specifiying an arbitrary select query. - * - * By default a select * will be done on the given tablename. - * - * @param string $tableName - * @param string|\Zend\Db\Select $query - */ - public function addTable($tableName, $query = \NULL) - { - if ($query === NULL) { - $query = $this->databaseConnection->getConnection()->select(); - $query->from($tableName, Select::SQL_WILDCARD); - } - - if($query instanceof Select) { - $query = $query->__toString(); - } - - $this->tables[$tableName] = new QueryTable($tableName, $query, $this->databaseConnection); - } -} diff --git a/src/PHPUnit/Db/DataSet/QueryTable.php b/src/PHPUnit/Db/DataSet/QueryTable.php deleted file mode 100644 index 80aec58127..0000000000 --- a/src/PHPUnit/Db/DataSet/QueryTable.php +++ /dev/null @@ -1,68 +0,0 @@ -data === null) { - $stmt = $this->databaseConnection->getConnection()->query($this->query); - $this->data = $stmt->fetchAll(\Zend\Db\Db::FETCH_ASSOC); - } - } - - /** - * Create Table Metadata - */ - protected function createTableMetaData() - { - if ($this->tableMetaData === NULL) { - $this->loadData(); - $keys = array(); - if(count($this->data) > 0) { - $keys = array_keys($this->data[0]); - } - $this->tableMetaData = new \PHPUnit_Extensions_Database_DataSet_DefaultTableMetaData( - $this->tableName, $keys - ); - } - } -} diff --git a/src/PHPUnit/Db/Exception.php b/src/PHPUnit/Db/Exception.php deleted file mode 100644 index 366ad209c8..0000000000 --- a/src/PHPUnit/Db/Exception.php +++ /dev/null @@ -1,15 +0,0 @@ -_connection = $db; - $this->_schema = $schema; - } - - /** - * List Tables - * - * @return array - */ - public function getTableNames() - { - return $this->_connection->listTables(); - } - - /** - * Get Table information - * - * @param string $tableName - * @return array - */ - protected function getTableDescription($tableName) - { - if(!isset($this->_tableMetadata[$tableName])) { - $this->_tableMetadata[$tableName] = $this->_connection->describeTable($tableName); - } - return $this->_tableMetadata[$tableName]; - } - - /** - * Returns an array containing the names of all the columns in the - * $tableName table, - * - * @param string $tableName - * @return array - */ - public function getTableColumns($tableName) - { - $tableMeta = $this->getTableDescription($tableName); - $columns = array_keys($tableMeta); - return $columns; - } - - /** - * Returns an array containing the names of all the primary key columns in - * the $tableName table. - * - * @param string $tableName - * @return array - */ - public function getTablePrimaryKeys($tableName) - { - $tableMeta = $this->getTableDescription($tableName); - - $primaryColumnNames = array(); - foreach($tableMeta AS $column) { - if($column['PRIMARY'] == true) { - $primaryColumnNames[] = $column['COLUMN_NAME']; - } - } - return $primaryColumnNames; - } - - /** - * Returns the name of the default schema. - * - * @return string - */ - public function getSchema() - { - return $this->_schema; - } - - /** - * Returns a quoted schema object. (table name, column name, etc) - * - * @param string $object - * @return string - */ - public function quoteSchemaObject($object) - { - return $this->_connection->quoteIdentifier($object); - } - - /** - * Returns true if the rdbms allows cascading - * - * @return bool - */ - public function allowsCascading() - { - return false; - } -} diff --git a/src/PHPUnit/Db/Operation/DeleteAll.php b/src/PHPUnit/Db/Operation/DeleteAll.php deleted file mode 100644 index 19fe23b2aa..0000000000 --- a/src/PHPUnit/Db/Operation/DeleteAll.php +++ /dev/null @@ -1,43 +0,0 @@ -getTableMetaData()->getTableName(); - $connection->getConnection()->delete($tableName); - } catch (\Exception $e) { - throw new \PHPUnit_Extensions_Database_Operation_Exception('DELETEALL', 'DELETE FROM '.$tableName.'', array(), $table, $e->getMessage()); - } - } - } -} diff --git a/src/PHPUnit/Db/Operation/Insert.php b/src/PHPUnit/Db/Operation/Insert.php deleted file mode 100644 index 67ad231987..0000000000 --- a/src/PHPUnit/Db/Operation/Insert.php +++ /dev/null @@ -1,67 +0,0 @@ -createDataSet(); - - $dsIterator = $dataSet->getIterator(); - - foreach($dsIterator as $table) { - $tableName = $table->getTableMetaData()->getTableName(); - - $db = $connection->getConnection(); - for($i = 0; $i < $table->getRowCount(); $i++) { - $values = $this->buildInsertValues($table, $i); - try { - $db->insert($tableName, $values); - } catch (\Exception $e) { - throw new \PHPUnit_Extensions_Database_Operation_Exception("INSERT", "INSERT INTO ".$tableName." [..]", $values, $table, $e->getMessage()); - } - } - } - } - - /** - * - * @param PHPUnit_Extensions_Database_DataSet_ITable $table - * @param int $rowNum - * @return array - */ - protected function buildInsertValues(\PHPUnit_Extensions_Database_DataSet_ITable $table, $rowNum) - { - $values = array(); - foreach($table->getTableMetaData()->getColumns() as $columnName) { - $values[$columnName] = $table->getValue($rowNum, $columnName); - } - return $values; - } -} diff --git a/src/PHPUnit/Db/Operation/Truncate.php b/src/PHPUnit/Db/Operation/Truncate.php deleted file mode 100644 index fd4e9bc9fd..0000000000 --- a/src/PHPUnit/Db/Operation/Truncate.php +++ /dev/null @@ -1,92 +0,0 @@ -getReverseIterator() AS $table) { - try { - $tableName = $table->getTableMetaData()->getTableName(); - $this->_truncate($connection->getConnection(), $tableName); - } catch (\Exception $e) { - throw new \PHPUnit_Extensions_Database_Operation_Exception('TRUNCATE', 'TRUNCATE '.$tableName.'', array(), $table, $e->getMessage()); - } - } - } - - /** - * Truncate a given table. - * - * @param \Zend\Db\Adapter\AbstractAdapter $db - * @param string $tableName - * @return void - */ - protected function _truncate(\Zend\Db\Adapter\AbstractAdapter $db, $tableName) - { - $tableName = $db->quoteIdentifier($tableName); - if($db instanceof \Zend\Db\Adapter\Pdo\Sqlite) { - $db->query('DELETE FROM '.$tableName); - } else if($db instanceof \Zend\Db\Adapter\Db2) { - /*if(strstr(PHP_OS, "WIN")) { - $file = tempnam(sys_get_temp_dir(), "zendtestdbibm_"); - file_put_contents($file, ""); - $db->query('IMPORT FROM '.$file.' OF DEL REPLACE INTO '.$tableName); - unlink($file); - } else { - $db->query('IMPORT FROM /dev/null OF DEL REPLACE INTO '.$tableName); - }*/ - throw \Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException("IBM Db2 TRUNCATE not supported."); - } else if($this->_isMssqlOrOracle($db)) { - $db->query('TRUNCATE TABLE '.$tableName); - } else if($db instanceof \Zend\Db\Adapter\Pdo\PgSql) { - $db->query('TRUNCATE '.$tableName.' CASCADE'); - } else { - $db->query('TRUNCATE '.$tableName); - } - } - - /** - * Detect if an adapter is for Mssql or Oracle Databases. - * - * @param \Zend\DB\Adapter\AbstractAdapter $db - * @return bool - */ - private function _isMssqlOrOracle($db) - { - return ( - $db instanceof \Zend\Db\Adapter\Pdo\Mssql || - $db instanceof \Zend\Db\Adapter\Sqlsrv || - $db instanceof \Zend\Db\Adapter\Pdo\Oci || - $db instanceof \Zend\Db\Adapter\Oracle - ); - } -} diff --git a/src/PHPUnit/Db/SimpleTester.php b/src/PHPUnit/Db/SimpleTester.php deleted file mode 100644 index 185db997c5..0000000000 --- a/src/PHPUnit/Db/SimpleTester.php +++ /dev/null @@ -1,53 +0,0 @@ -connection = $connection; - $this->setUpOperation = new \PHPUnit_Extensions_Database_Operation_Composite(array( - new Operation\Truncate(), - new Operation\Insert(), - )); - $this->tearDownOperation = \PHPUnit_Extensions_Database_Operation_Factory::NONE(); - } - - /** - * Set Up the database using the given Dataset and the SetUp strategy "Truncate, then Insert" - * - * @param PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet - */ - public function setUpDatabase(\PHPUnit_Extensions_Database_DataSet_IDataSet $dataSet) - { - $this->setDataSet($dataSet); - $this->onSetUp(); - } -} diff --git a/src/PHPUnit/Exception/ExceptionInterface.php b/src/PHPUnit/Exception/ExceptionInterface.php deleted file mode 100644 index ea86b0bf38..0000000000 --- a/src/PHPUnit/Exception/ExceptionInterface.php +++ /dev/null @@ -1,17 +0,0 @@ -_adapter = new Test\DbAdapter(); - } - - public function testAppendStatementToStack() - { - $stmt1 = Test\DbStatement::createSelectStatement( array() ); - $this->_adapter->appendStatementToStack($stmt1); - - $stmt2 = Test\DbStatement::createSelectStatement( array() ); - $this->_adapter->appendStatementToStack($stmt2); - - $this->assertSame($stmt2, $this->_adapter->query("foo")); - $this->assertSame($stmt1, $this->_adapter->query("foo")); - } - - public function testAppendLastInsertId() - { - $this->_adapter->appendLastInsertIdToStack(1); - $this->_adapter->appendLastInsertIdToStack(2); - - $this->assertEquals(2, $this->_adapter->lastInsertId()); - $this->assertEquals(1, $this->_adapter->lastInsertId()); - } - - public function testLastInsertIdDefault() - { - $this->assertFalse($this->_adapter->lastInsertId()); - } - - public function testListTablesDefault() - { - $this->assertEquals(array(), $this->_adapter->listTables()); - } - - public function testSetListTables() - { - $this->_adapter->setListTables(array("foo", "bar")); - $this->assertEquals(array("foo", "bar"), $this->_adapter->listTables()); - } - - public function testDescribeTableDefault() - { - $this->assertEquals(array(), $this->_adapter->describeTable("foo")); - } - - public function testDescribeTable() - { - $this->_adapter->setDescribeTable("foo", array("bar")); - $this->assertEquals(array("bar"), $this->_adapter->describeTable("foo")); - } - - public function testConnect() - { - $this->assertFalse($this->_adapter->isConnected()); - $this->_adapter->query("foo"); - $this->assertTrue($this->_adapter->isConnected()); - $this->_adapter->closeConnection(); - $this->assertFalse($this->_adapter->isConnected()); - } - - public function testAppendLimitToSql() - { - $sql = $this->_adapter->limit("foo", 10, 20); - $this->assertEquals( - "foo LIMIT 20,10", $sql - ); - } - - public function testQueryProfiler_EnabledByDefault() - { - $this->assertTrue($this->_adapter->getProfiler()->getEnabled()); - } - - public function testQueryPRofiler_PrepareStartsQueryProfiler() - { - $stmt = $this->_adapter->prepare("SELECT foo"); - - $this->assertEquals(1, $this->_adapter->getProfiler()->getTotalNumQueries()); - - $qp = $this->_adapter->getProfiler()->getLastQueryProfile(); - - /* @var $qp Zend\Db\Profiler\Query */ - $this->assertFalse($qp->hasEnded()); - } - - public function testQueryProfiler_QueryStartEndsQueryProfiler() - { - $stmt = $this->_adapter->query("SELECT foo"); - - $this->assertEquals(1, $this->_adapter->getProfiler()->getTotalNumQueries()); - - $qp = $this->_adapter->getProfiler()->getLastQueryProfile(); - - /* @var $qp Zend\Db\Profiler\Query */ - $this->assertTrue($qp->hasEnded()); - } - - public function testQueryProfiler_QueryBindWithParams() - { - $stmt = $this->_adapter->query("SELECT * FROM foo WHERE bar = ?", array(1234)); - - $qp = $this->_adapter->getProfiler()->getLastQueryProfile(); - - /* @var $qp Zend\Db\Profiler\Query */ - $this->assertEquals(array(1 => 1234), $qp->getQueryParams()); - $this->assertEquals("SELECT * FROM foo WHERE bar = ?", $qp->getQuery()); - } - - public function testQueryProfiler_PrepareBindExecute() - { - $var = 1234; - - $stmt = $this->_adapter->prepare("SELECT * FROM foo WHERE bar = ?"); - $stmt->bindParam(1, $var); - - $qp = $this->_adapter->getProfiler()->getLastQueryProfile(); - - /* @var $qp Zend\Db\Profiler\Query */ - $this->assertEquals(array(1 => 1234), $qp->getQueryParams()); - $this->assertEquals("SELECT * FROM foo WHERE bar = ?", $qp->getQuery()); - } - - public function testGetSetQuoteIdentifierSymbol() - { - $this->assertEquals('', $this->_adapter->getQuoteIdentifierSymbol()); - $this->_adapter->setQuoteIdentifierSymbol('`'); - $this->assertEquals('`', $this->_adapter->getQuoteIdentifierSymbol()); - } -} diff --git a/test/DbStatementTest.php b/test/DbStatementTest.php deleted file mode 100644 index ff84ad4958..0000000000 --- a/test/DbStatementTest.php +++ /dev/null @@ -1,151 +0,0 @@ -assertEquals(0, $stmt->rowCount()); - } - - public function testSetRowCount() - { - $stmt = new Test\DbStatement(); - $stmt->setRowCount(10); - $this->assertEquals(10, $stmt->rowCount()); - } - - public function testCreateSelectStatementWithRows() - { - $rows = array("foo", "bar"); - - $stmt = Test\DbStatement::createSelectStatement($rows); - - $this->assertInstanceOf('Zend\Test\DbStatement', $stmt); - $this->assertEquals($rows, $stmt->fetchAll()); - } - - public function testCreateInsertStatementWithRowCount() - { - $stmt = Test\DbStatement::createInsertStatement(1234); - - $this->assertInstanceOf('Zend\Test\DbStatement', $stmt); - $this->assertEquals(1234, $stmt->rowCount()); - } - - public function testCreateUpdateStatementWithRowCount() - { - $stmt = Test\DbStatement::createUpdateStatement(1234); - - $this->assertInstanceOf('Zend\Test\DbStatement', $stmt); - $this->assertEquals(1234, $stmt->rowCount()); - } - - public function testCreateDeleteStatementWithRowCount() - { - $stmt = Test\DbStatement::createDeleteStatement(1234); - - $this->assertInstanceOf('Zend\Test\DbStatement', $stmt); - $this->assertEquals(1234, $stmt->rowCount()); - } - - public function testSetFetchRow() - { - $row = array("foo"); - - $stmt = new Test\DbStatement(); - $stmt->append($row); - - $this->assertEquals($row, $stmt->fetch()); - } - - public function testFetchDefault() - { - $stmt = new Test\DbStatement(); - $this->assertFalse($stmt->fetch()); - } - - public function testFetchResult_FromEmptyResultStack() - { - $row = array("foo"); - - $stmt = new Test\DbStatement(); - $stmt->append($row); - $stmt->append($row); - - $this->assertTrue($stmt->fetch() !== false); - $this->assertTrue($stmt->fetch() !== false); - $this->assertFalse($stmt->fetch()); - } - - public function testFetchColumnDefault() - { - $stmt = new Test\DbStatement(); - $this->assertFalse($stmt->fetchColumn()); - } - - public function testFetchColumn() - { - $row = array("foo" => "bar", "bar" => "baz"); - - $stmt = new Test\DbStatement(); - $stmt->append($row); - - $this->assertEquals("baz", $stmt->fetchColumn(1)); - } - - public function testFetchColumn_OutOfBounds() - { - $this->setExpectedException("Zend\Db\Statement\Exception"); - - $row = array("foo" => "bar", "bar" => "baz"); - - $stmt = new Test\DbStatement(); - $stmt->append($row); - - $stmt->fetchColumn(1234); - } - - public function testFetchObject() - { - $row = array("foo" => "bar", "bar" => "baz"); - - $stmt = new Test\DbStatement(); - $stmt->append($row); - - $object = $stmt->fetchObject(); - $this->assertInternalType('object', $object); - $this->assertEquals('bar', $object->foo); - $this->assertEquals('baz', $object->bar); - } - - public function testFetchObject_ClassNotExists_ThrowsException() - { - $this->setExpectedException("Zend\Db\Statement\Exception"); - - $row = array("foo" => "bar", "bar" => "baz"); - - $stmt = new Test\DbStatement(); - $stmt->append($row); - - $object = $stmt->fetchObject("anInvalidClassName"); - } -} diff --git a/test/PHPUnit/Db/ConnectionTest.php b/test/PHPUnit/Db/ConnectionTest.php deleted file mode 100644 index 5c4ef06b08..0000000000 --- a/test/PHPUnit/Db/ConnectionTest.php +++ /dev/null @@ -1,78 +0,0 @@ -adapterMock = $this->getMock('Zend\Test\DbAdapter'); - } - - /** - * @return Zend_Test_PHPUnit_Db_Connection - */ - public function createConnection() - { - $connection = new Db\Connection($this->adapterMock, "schema"); - return $connection; - } - - public function testCloseConnection() - { - $this->adapterMock->expects($this->once()) - ->method('closeConnection'); - - $connection = $this->createConnection(); - $connection->close(); - } - - public function testCreateQueryTable() - { - $connection = $this->createConnection(); - $ret = $connection->createQueryTable("foo", "foo"); - - $this->assertInstanceOf('Zend\Test\PHPUnit\Db\DataSet\QueryTable', $ret); - } - - public function testGetSchema() - { - $fixtureSchema = "schema"; - $connection = new Db\Connection($this->adapterMock, $fixtureSchema); - - $this->assertEquals($fixtureSchema, $connection->getSchema()); - } - - public function testGetMetaData() - { - $connection = $this->createConnection(); - $metadata = $connection->getMetaData(); - - $this->assertInstanceOf('Zend\Test\PHPUnit\Db\Metadata\Generic', $metadata); - } - - public function testGetTruncateCommand() - { - $connection = $this->createConnection(); - - $this->assertEquals("DELETE", $connection->getTruncateCommand()); - } -} diff --git a/test/PHPUnit/Db/DataSet/DataSetTestCase.php b/test/PHPUnit/Db/DataSet/DataSetTestCase.php deleted file mode 100644 index 9941c0d210..0000000000 --- a/test/PHPUnit/Db/DataSet/DataSetTestCase.php +++ /dev/null @@ -1,42 +0,0 @@ -connectionMock = $this->getMock('Zend\Test\PHPUnit\Db\Connection', array(), array(), '', false); - } - - public function decorateConnectionMockWithZendAdapter() - { - $this->decorateConnectionGetConnectionWith(new \Zend\Test\DbAdapter()); - } - - public function decorateConnectionGetConnectionWith($returnValue) - { - $this->connectionMock->expects($this->any()) - ->method('getConnection') - ->will($this->returnValue($returnValue)); - } -} diff --git a/test/PHPUnit/Db/DataSet/DbRowsetTest.php b/test/PHPUnit/Db/DataSet/DbRowsetTest.php deleted file mode 100644 index 9da8d67644..0000000000 --- a/test/PHPUnit/Db/DataSet/DbRowsetTest.php +++ /dev/null @@ -1,83 +0,0 @@ - 'stdClass', - 'data' => array(array('foo' => 'bar'), array('foo' => 'baz')), - ); - $rowset = new \Zend\Db\Table\Rowset($config); - return $rowset; - } - - public function testRowsetCountInITableRepresentation() - { - $rowsetTable = new DataSet\DbRowset($this->getRowSet(), "fooTable"); - $this->assertEquals(2, $rowsetTable->getRowCount()); - } - - public function testRowsetGetSpecificValue() - { - $rowsetTable = new DataSet\DbRowset($this->getRowSet(), "fooTable"); - $this->assertEquals("bar", $rowsetTable->getValue(0, "foo")); - } - - public function testRowsetGetSpecificRow() - { - $rowsetTable = new DataSet\DbRowset($this->getRowSet(), "fooTable"); - $this->assertEquals(array("foo" => "baz"), $rowsetTable->getRow(1)); - } - - public function testRowset_ConstructWithDisconnectedRowset_NoTableName_ThrowsException() - { - $this->setExpectedException("Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException"); - - $rowset = $this->getMock('Zend\Db\Table\AbstractRowset', array(), array(), '', false); - $rowset->expects($this->once()) - ->method('getTable') - ->will($this->returnValue(null)); - - $rowsetTable = new DataSet\DbRowset($rowset); - } - - public function testRowset_WithNoRows_GetColumnsFromTable() - { - $columns = array("foo", "bar"); - - $tableMock = $this->getMock('Zend\Db\Table\AbstractTable', array(), array(), '', false); - $tableMock->expects($this->once()) - ->method('info') - ->with($this->equalTo('cols')) - ->will($this->returnValue($columns)); - - $rowset = $this->getMock('Zend\Db\Table\AbstractRowset', array(), array(), '', false); - $rowset->expects($this->exactly(2)) - ->method('getTable') - ->will($this->returnValue($tableMock)); - $rowset->expects($this->once()) - ->method('toArray') - ->will($this->returnValue( array() )); - - $rowsetTable = new DataSet\DbRowset($rowset, "tableName"); - } -} diff --git a/test/PHPUnit/Db/DataSet/DbTableDataSetTest.php b/test/PHPUnit/Db/DataSet/DbTableDataSetTest.php deleted file mode 100644 index 327f06d0e5..0000000000 --- a/test/PHPUnit/Db/DataSet/DbTableDataSetTest.php +++ /dev/null @@ -1,59 +0,0 @@ -getMock('Zend\Db\Table\Table', array(), array(), '', false); - $table->expects($this->at(0))->method('info')->with('name')->will($this->returnValue($fixtureTable)); - $table->expects($this->at(1))->method('info')->with('name')->will($this->returnValue($fixtureTable)); - $table->expects($this->at(2))->method('info')->with('cols')->will($this->returnValue(array())); - - $dataSet = new DataSet\DbTableDataSet(); - $dataSet->addTable($table); - - $this->assertEquals(array($fixtureTable), $dataSet->getTableNames()); - } - - public function testAddTableCreatesDbTableInstance() - { - $fixtureTable = "foo"; - - $table = $this->getMock('Zend\Db\Table\Table', array(), array(), '', false); - $table->expects($this->at(0))->method('info')->with('name')->will($this->returnValue($fixtureTable)); - $table->expects($this->at(1))->method('info')->with('name')->will($this->returnValue($fixtureTable)); - $table->expects($this->at(2))->method('info')->with('cols')->will($this->returnValue(array())); - - $dataSet = new DataSet\DbTableDataSet(); - $dataSet->addTable($table); - - $this->assertInstanceOf('Zend\Test\PHPUnit\Db\DataSet\DbTable', $dataSet->getTable($fixtureTable)); - } - - public function testGetUnknownTableThrowsException() - { - $this->setExpectedException('\Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException'); - $dataSet = new DataSet\DbTableDataSet(); - $dataSet->getTable('unknown'); - } -} diff --git a/test/PHPUnit/Db/DataSet/DbTableTest.php b/test/PHPUnit/Db/DataSet/DbTableTest.php deleted file mode 100644 index 27b7a4eb34..0000000000 --- a/test/PHPUnit/Db/DataSet/DbTableTest.php +++ /dev/null @@ -1,74 +0,0 @@ -getMock('Zend\Db\Table\Table', array(), array(), '', false); - $table->expects($this->once()) - ->method('fetchAll') - ->with($fixtureWhere, $fixtureOrderBy, $fixtureLimit, $fixtureOffset) - ->will($this->returnValue(array())); - - $dataSet = new DataSet\DbTable($table, $fixtureWhere, $fixtureOrderBy, $fixtureLimit, $fixtureOffset); - $count = $dataSet->getRowCount(); - } - - public function testGetTableMetadata() - { - $fixtureTableName = "foo"; - - $table = $this->getMock('Zend\Db\Table\Table', array(), array(), '', false); - $table->expects($this->at(0)) - ->method('info') - ->with($this->equalTo('name')) - ->will($this->returnValue($fixtureTableName)); - $table->expects($this->at(1)) - ->method('info') - ->with($this->equalTo('cols')) - ->will($this->returnValue( array("foo", "bar") )); - $table->expects($this->once()) - ->method('fetchAll') - ->will($this->returnValue(array( array("foo" => 1, "bar" => 2) ))); - - $dataSet = new DataSet\DbTable($table); - - $this->assertEquals($fixtureTableName, $dataSet->getTableMetaData()->getTableName()); - $this->assertEquals(array("foo", "bar"), $dataSet->getTableMetaData()->getColumns()); - } - - public function testLoadDataOnlyCalledOnce() - { - $table = $this->getMock('Zend\Db\Table\Table', array(), array(), '', false); - $table->expects($this->once()) - ->method('fetchAll') - ->will($this->returnValue(array( array("foo" => 1, "bar" => 2) ))); - - $dataSet = new DataSet\DbTable($table); - $dataSet->getRow(0); - $dataSet->getRow(0); - } -} diff --git a/test/PHPUnit/Db/DataSet/QueryDataSetTest.php b/test/PHPUnit/Db/DataSet/QueryDataSetTest.php deleted file mode 100644 index b91df7e2c7..0000000000 --- a/test/PHPUnit/Db/DataSet/QueryDataSetTest.php +++ /dev/null @@ -1,58 +0,0 @@ -getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection'); - $this->setExpectedException('Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException'); - $queryDataSet = new DataSet\QueryDataSet($connectionMock); - } - - public function testCreateQueryDataSetWithZendDbAdapter() - { - $this->decorateConnectionMockWithZendAdapter(); - $queryDataSet = new DataSet\QueryDataSet($this->connectionMock); - } - - public function testAddTableWithoutQueryParameterCreatesSelectWildcardAll() - { - $fixtureTableName = "foo"; - - $adapterMock = $this->getMock('Zend\Test\DbAdapter'); - $selectMock = $this->getMock('Zend\Db\Select', array(), array($adapterMock)); - - $adapterMock->expects($this->once()) - ->method('select') - ->will($this->returnValue($selectMock)); - $this->decorateConnectionGetConnectionWith($adapterMock); - - $selectMock->expects($this->once()) - ->method('from') - ->with($fixtureTableName, \Zend\Db\Select::SQL_WILDCARD); - $selectMock->expects($this->once()) - ->method('__toString') - ->will($this->returnValue('SELECT * FOM foo')); - - $queryDataSet = new DataSet\QueryDataSet($this->connectionMock); - $queryDataSet->addTable('foo'); - } -} diff --git a/test/PHPUnit/Db/DataSet/QueryTableTest.php b/test/PHPUnit/Db/DataSet/QueryTableTest.php deleted file mode 100644 index eef8868053..0000000000 --- a/test/PHPUnit/Db/DataSet/QueryTableTest.php +++ /dev/null @@ -1,106 +0,0 @@ -getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection'); - - $this->setExpectedException('Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException'); - $queryTable = new DataSet\QueryTable("foo", "SELECT * FROM foo", $connectionMock); - } - - public function testCreateQueryTableWithZendDbConnection() - { - $this->decorateConnectionMockWithZendAdapter(); - $queryTable = new DataSet\QueryTable("foo", "SELECT * FROM foo", $this->connectionMock); - } - - public function testLoadDataExecutesQueryOnZendAdapter() - { - $statementMock = new Test\DbStatement(); - $statementMock->append(array('foo' => 'bar')); - $adapterMock = new Test\DbAdapter(); - $adapterMock->appendStatementToStack($statementMock); - - $this->decorateConnectionGetConnectionWith($adapterMock); - - $queryTable = new DataSet\QueryTable("foo", "SELECT * FROM foo", $this->connectionMock); - $data = $queryTable->getRow(0); - - $this->assertEquals( - array("foo" => "bar"), $data - ); - } - - public function testGetRowCountLoadsData() - { - $statementMock = new Test\DbStatement(); - $statementMock->append(array('foo' => 'bar')); - $adapterMock = new Test\DbAdapter(); - $adapterMock->appendStatementToStack($statementMock); - - $this->decorateConnectionGetConnectionWith($adapterMock); - - $queryTable = new DataSet\QueryTable("foo", "SELECT * FROM foo", $this->connectionMock); - $count = $queryTable->getRowCount(); - - $this->assertEquals(1, $count); - } - - public function testDataIsLoadedOnlyOnce() - { - $fixtureSql = "SELECT * FROM foo"; - - $statementMock = new Test\DbStatement(); - $statementMock->append(array('foo' => 'bar')); - $adapterMock = $this->getMock('Zend\Test\DbAdapter'); - $adapterMock->expects($this->once()) - ->method('query') - ->with($fixtureSql) - ->will($this->returnValue($statementMock)); - - $this->decorateConnectionGetConnectionWith($adapterMock); - - $queryTable = new DataSet\QueryTable("foo", $fixtureSql, $this->connectionMock); - $this->assertEquals(1, $queryTable->getRowCount()); - $this->assertEquals(1, $queryTable->getRowCount()); - $row = $queryTable->getRow(0); - $this->assertEquals(array('foo' => 'bar'), $row); - } - - public function testQueryTableWithoutRows() - { - $statementMock = new Test\DbStatement(); - $adapterMock = new Test\DbAdapter(); - $adapterMock->appendStatementToStack($statementMock); - - $this->decorateConnectionGetConnectionWith($adapterMock); - $queryTable = new DataSet\QueryTable("foo", null, $this->connectionMock); - - $metadata = $queryTable->getTableMetaData(); - $this->assertInstanceOf('PHPUnit_Extensions_Database_DataSet_ITableMetaData', $metadata); - $this->assertEquals(array(), $metadata->getColumns()); - $this->assertEquals(array(), $metadata->getPrimaryKeys()); - $this->assertEquals("foo", $metadata->getTableName()); - } -} diff --git a/test/PHPUnit/Db/Integration/AbstractTestCase.php b/test/PHPUnit/Db/Integration/AbstractTestCase.php deleted file mode 100644 index e0db661991..0000000000 --- a/test/PHPUnit/Db/Integration/AbstractTestCase.php +++ /dev/null @@ -1,119 +0,0 @@ -addTable($this->createFooTable()); - $dataSet->addTable($this->createBarTable()); - - $this->assertEquals( - "foo", $dataSet->getTableMetaData('foo')->getTableName() - ); - $this->assertEquals( - "bar", $dataSet->getTableMetaData("bar")->getTableName() - ); - - $this->assertEquals(array("foo", "bar"), $dataSet->getTableNames()); - } - - public function testZendDbTableEqualsXmlDataSet() - { - $fooTable = $this->createFooTable(); - $fooTable->insert(array("id" => null, "foo" => "foo", "bar" => "bar", "baz" => "baz")); - $fooTable->insert(array("id" => null, "foo" => "bar", "bar" => "bar", "baz" => "bar")); - $fooTable->insert(array("id" => null, "foo" => "baz", "bar" => "baz", "baz" => "baz")); - - $dataSet = new DataSet\DbTableDataSet(); - $dataSet->addTable($fooTable); - - $xmlDataSet = new \PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet( - __DIR__."/_files/sqliteIntegrationFixture.xml" - ); - $this->assertTrue($xmlDataSet->assertEquals($dataSet)); - } - - /** - * @return Zend_Test_PHPUnit_Db_Connection - */ - public function getConnection() - { - return new \Zend\Test\PHPUnit\Db\Connection($this->dbAdapter, 'foo'); - } - - public function testSimpleTesterSetupAndRowsetEquals() - { - $dataSet = new \PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet( - __DIR__."/_files/sqliteIntegrationFixture.xml" - ); - $fooDataTable = $dataSet->getTable("foo"); - - $tester = new \Zend\Test\PHPUnit\Db\SimpleTester($this->getConnection()); - $tester->setUpDatabase($dataSet); - - $fooTable = $this->createFooTable(); - $rows = $fooTable->fetchAll(); - - $this->assertEquals(3, count($rows)); - - $rowsetTable = new DataSet\DbRowset($rows); - $rowsetTable->assertEquals($fooDataTable); - } - - /** - * @return Zend_Test_PHPUnit_Db_TableFoo - */ - public function createFooTable() - { - $table = new TableFoo(array('db' => $this->dbAdapter)); - return $table; - } - - /** - * @return Zend_Test_PHPUnit_Db_TableBar - */ - public function createBarTable() - { - $table = new TableBar(array('db' => $this->dbAdapter)); - return $table; - } -} - -class TableFoo extends Table\AbstractTable -{ - protected $_name = "foo"; - - protected $_primary = "id"; -} - -class TableBar extends Table\AbstractTable -{ - protected $_name = "bar"; - - protected $_primary = "id"; -} diff --git a/test/PHPUnit/Db/Integration/MysqlIntegrationTest.php b/test/PHPUnit/Db/Integration/MysqlIntegrationTest.php deleted file mode 100644 index 9e1f6e6f6b..0000000000 --- a/test/PHPUnit/Db/Integration/MysqlIntegrationTest.php +++ /dev/null @@ -1,55 +0,0 @@ -markTestSkipped('Database tests are not enabled.'); - return; - } - - if (!extension_loaded('pdo')) { - $this->markTestSkipped('PDO is required for this test.'); - return; - } - - if (!in_array('mysql', \PDO::getAvailableDrivers())) { - $this->markTestSkipped('Mysql is not included in PDO in this PHP installation.'); - return; - } - - $params = array( - 'host' => TESTS_ZEND_DB_ADAPTER_MYSQL_HOSTNAME, - 'username' => TESTS_ZEND_DB_ADAPTER_MYSQL_USERNAME, - 'password' => TESTS_ZEND_DB_ADAPTER_MYSQL_PASSWORD, - 'dbname' => TESTS_ZEND_DB_ADAPTER_MYSQL_DATABASE, - ); - - $this->dbAdapter = \Zend\Db\Db::factory('PdoMysql', $params); - $this->dbAdapter->query("DROP TABLE IF EXISTS foo"); - $this->dbAdapter->query("DROP TABLE IF EXISTS bar"); - $this->dbAdapter->query( - 'CREATE TABLE foo (id INT(10) AUTO_INCREMENT PRIMARY KEY, foo VARCHAR(255), bar VARCHAR(255), baz VARCHAR(255)) AUTO_INCREMENT=1' - ); - $this->dbAdapter->query( - 'CREATE TABLE bar (id INT(10) AUTO_INCREMENT PRIMARY KEY, foo VARCHAR(255), bar VARCHAR(255), baz VARCHAR(255)) AUTO_INCREMENT=1' - ); - } -} diff --git a/test/PHPUnit/Db/Integration/SqLiteIntegrationTest.php b/test/PHPUnit/Db/Integration/SqLiteIntegrationTest.php deleted file mode 100644 index 9aa985778b..0000000000 --- a/test/PHPUnit/Db/Integration/SqLiteIntegrationTest.php +++ /dev/null @@ -1,39 +0,0 @@ -markTestSkipped('PDO is required for this test.'); - } - - if(!in_array('sqlite', \PDO::getAvailableDrivers())) { - $this->markTestSkipped('SqLite is not included in PDO in this PHP installation.'); - } - - $this->dbAdapter = \Zend\Db\Db::factory('Pdo\Sqlite', array('dbname' => ':memory:')); - $this->dbAdapter->query( - 'CREATE TABLE "foo" (id INTEGER PRIMARY KEY AUTOINCREMENT, foo VARCHAR, bar VARCHAR, baz VARCHAR)' - ); - $this->dbAdapter->query( - 'CREATE TABLE "bar" (id INTEGER PRIMARY KEY AUTOINCREMENT, foo VARCHAR, bar VARCHAR, baz VARCHAR)' - ); - } -} diff --git a/test/PHPUnit/Db/Integration/_files/sqliteIntegrationFixture.xml b/test/PHPUnit/Db/Integration/_files/sqliteIntegrationFixture.xml deleted file mode 100644 index b8a64f21a8..0000000000 --- a/test/PHPUnit/Db/Integration/_files/sqliteIntegrationFixture.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/test/PHPUnit/Db/Metadata/GenericTest.php b/test/PHPUnit/Db/Metadata/GenericTest.php deleted file mode 100644 index ed4daa739b..0000000000 --- a/test/PHPUnit/Db/Metadata/GenericTest.php +++ /dev/null @@ -1,96 +0,0 @@ -adapterMock = $this->getMock('Zend\Test\DbAdapter'); - $this->metadata = new \Zend\Test\PHPUnit\Db\Metadata\Generic($this->adapterMock, "schema"); - } - - public function testGetSchema() - { - $this->assertEquals("schema", $this->metadata->getSchema()); - } - - public function testGetColumnNames() - { - $fixtureTableName = "foo"; - - $this->adapterMock->expects($this->once()) - ->method('describeTable') - ->with($fixtureTableName) - ->will($this->returnValue(array("foo" => 1, "bar" => 2))); - $data = $this->metadata->getTableColumns($fixtureTableName); - - $this->assertEquals(array("foo", "bar"), $data); - } - - public function testGetTableNames() - { - $this->adapterMock->expects($this->once()) - ->method('listTables') - ->will($this->returnValue(array("foo"))); - $tables = $this->metadata->getTableNames(); - - $this->assertEquals(array("foo"), $tables); - } - - public function testGetTablePrimaryKey() - { - $fixtureTableName = "foo"; - - $tableMeta = array( - array('PRIMARY' => false, 'COLUMN_NAME' => 'foo'), - array('PRIMARY' => true, 'COLUMN_NAME' => 'bar'), - array('PRIMARY' => true, 'COLUMN_NAME' => 'baz'), - ); - - $this->adapterMock->expects($this->once()) - ->method('describeTable') - ->with($fixtureTableName) - ->will($this->returnValue($tableMeta)); - - $primaryKey = $this->metadata->getTablePrimaryKeys($fixtureTableName); - $this->assertEquals(array("bar", "baz"), $primaryKey); - } - - public function testGetAllowCascading() - { - $this->assertFalse($this->metadata->allowsCascading()); - } - - public function testQuoteIdentifierIsDelegated() - { - $fixtureValue = "foo"; - - $this->adapterMock->expects($this->once()) - ->method('quoteIdentifier') - ->with($fixtureValue) - ->will($this->returnValue($fixtureValue)); - - $actualValue = $this->metadata->quoteSchemaObject($fixtureValue); - - $this->assertEquals($fixtureValue, $actualValue); - } -} diff --git a/test/PHPUnit/Db/Operation/DeleteAllTest.php b/test/PHPUnit/Db/Operation/DeleteAllTest.php deleted file mode 100644 index 3daca8714f..0000000000 --- a/test/PHPUnit/Db/Operation/DeleteAllTest.php +++ /dev/null @@ -1,72 +0,0 @@ -operation = new \Zend\Test\PHPUnit\Db\Operation\DeleteAll(); - } - - public function testDeleteAll() - { - $dataSet = new \PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(__DIR__."/_files/truncateFixture.xml"); - - $testAdapter = $this->getMock('Zend\Test\DbAdapter'); - $testAdapter->expects($this->at(0)) - ->method('delete') - ->with('foo'); - $testAdapter->expects($this->at(1)) - ->method('delete') - ->with('bar'); - - $connection = new Db\Connection($testAdapter, "schema"); - - $this->operation->execute($connection, $dataSet); - } - - public function testDeleteQueryErrorTransformsException() - { - $this->setExpectedException('PHPUnit_Extensions_Database_Operation_Exception'); - - $dataSet = new \PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(__DIR__."/_files/truncateFixture.xml"); - - $testAdapter = $this->getMock('Zend\Test\DbAdapter'); - $testAdapter->expects($this->any()) - ->method('delete') - ->will($this->throwException(new \Exception)); - - $connection = new Db\Connection($testAdapter, "schema"); - - $this->operation->execute($connection, $dataSet); - } - - public function testInvalidConnectionGivenThrowsException() - { - $this->setExpectedException("Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException"); - - $dataSet = $this->getMock('PHPUnit_Extensions_Database_DataSet_IDataSet'); - $connection = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection'); - - $this->operation->execute($connection, $dataSet); - } -} diff --git a/test/PHPUnit/Db/Operation/InsertTest.php b/test/PHPUnit/Db/Operation/InsertTest.php deleted file mode 100644 index 1127a58f18..0000000000 --- a/test/PHPUnit/Db/Operation/InsertTest.php +++ /dev/null @@ -1,72 +0,0 @@ -operation = new \Zend\Test\PHPUnit\Db\Operation\Insert(); - } - - public function testInsertDataSetUsingAdapterInsert() - { - $dataSet = new \PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(__DIR__."/_files/insertFixture.xml"); - - $testAdapter = $this->getMock('Zend\Test\DbAdapter'); - $testAdapter->expects($this->at(0)) - ->method('insert') - ->with('foo', array('foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz')); - $testAdapter->expects($this->at(1)) - ->method('insert') - ->with('foo', array('foo' => 'bar', 'bar' => 'bar', 'baz' => 'bar')); - $testAdapter->expects($this->at(2)) - ->method('insert') - ->with('foo', array('foo' => 'baz', 'bar' => 'baz', 'baz' => 'baz')); - - $connection = new Db\Connection($testAdapter, "schema"); - - $this->operation->execute($connection, $dataSet); - } - - public function testInsertExceptionIsTransformed() - { - $this->setExpectedException('PHPUnit_Extensions_Database_Operation_Exception'); - - $dataSet = new \PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(__DIR__."/_files/insertFixture.xml"); - - $testAdapter = $this->getMock('Zend\Test\DbAdapter'); - $testAdapter->expects($this->any())->method('insert')->will($this->throwException(new \Exception())); - - $connection = new Db\Connection($testAdapter, "schema"); - $this->operation->execute($connection, $dataSet); - } - - public function testInvalidConnectionGivenThrowsException() - { - $this->setExpectedException("Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException"); - - $dataSet = $this->getMock('PHPUnit_Extensions_Database_DataSet_IDataSet'); - $connection = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection'); - - $this->operation->execute($connection, $dataSet); - } -} diff --git a/test/PHPUnit/Db/Operation/TruncateTest.php b/test/PHPUnit/Db/Operation/TruncateTest.php deleted file mode 100644 index 640a86b1be..0000000000 --- a/test/PHPUnit/Db/Operation/TruncateTest.php +++ /dev/null @@ -1,96 +0,0 @@ -operation = new \Zend\Test\PHPUnit\Db\Operation\Truncate(); - } - - public function testTruncateTablesExecutesAdapterQuery() - { - $dataSet = new \PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(__DIR__."/_files/truncateFixture.xml"); - - $testAdapter = $this->getMock('Zend\Test\DbAdapter'); - $testAdapter->expects($this->at(0)) - ->method('quoteIdentifier') - ->with('bar')->will($this->returnValue('bar')); - $testAdapter->expects($this->at(1)) - ->method('query') - ->with('TRUNCATE bar'); - $testAdapter->expects($this->at(2)) - ->method('quoteIdentifier') - ->with('foo')->will($this->returnValue('foo')); - $testAdapter->expects($this->at(3)) - ->method('query') - ->with('TRUNCATE foo'); - - $connection = new Db\Connection($testAdapter, "schema"); - - $this->operation->execute($connection, $dataSet); - } - - public function testTruncateTableInvalidQueryTransformsException() - { - $this->setExpectedException('PHPUnit_Extensions_Database_Operation_Exception'); - - $dataSet = new \PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(__DIR__."/_files/insertFixture.xml"); - - $testAdapter = $this->getMock('Zend\Test\DbAdapter'); - $testAdapter->expects($this->any())->method('query')->will($this->throwException(new \Exception())); - - $connection = new Db\Connection($testAdapter, "schema"); - - $this->operation->execute($connection, $dataSet); - } - - public function testInvalidConnectionGivenThrowsException() - { - $this->setExpectedException("Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException"); - - $dataSet = $this->getMock('PHPUnit_Extensions_Database_DataSet_IDataSet'); - $connection = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection'); - - $this->operation->execute($connection, $dataSet); - } - - /** - * @group ZF-7936 - */ - public function testTruncateAppliedToTablesInReverseOrder() - { - $testAdapter = new \Zend\Test\DbAdapter(); - $connection = new Db\Connection($testAdapter, "schema"); - - $dataSet = new \PHPUnit_Extensions_Database_DataSet_FlatXmlDataSet(__DIR__."/_files/truncateFixture.xml"); - - $this->operation->execute($connection, $dataSet); - - $profiler = $testAdapter->getProfiler(); - $queries = $profiler->getQueryProfiles(); - - $this->assertEquals(2, count($queries)); - $this->assertContains('bar', $queries[0]->getQuery()); - $this->assertContains('foo', $queries[1]->getQuery()); - } -} diff --git a/test/PHPUnit/Db/Operation/_files/insertFixture.xml b/test/PHPUnit/Db/Operation/_files/insertFixture.xml deleted file mode 100644 index a5029f6fb7..0000000000 --- a/test/PHPUnit/Db/Operation/_files/insertFixture.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/test/PHPUnit/Db/Operation/_files/truncateFixture.xml b/test/PHPUnit/Db/Operation/_files/truncateFixture.xml deleted file mode 100644 index a0a57a2e14..0000000000 --- a/test/PHPUnit/Db/Operation/_files/truncateFixture.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/test/PHPUnit/Db/SimpleTesterTest.php b/test/PHPUnit/Db/SimpleTesterTest.php deleted file mode 100644 index 2a6f4839fd..0000000000 --- a/test/PHPUnit/Db/SimpleTesterTest.php +++ /dev/null @@ -1,66 +0,0 @@ -getMock('Zend\Test\DbAdapter'); - $testAdapter->expects($this->any()) - ->method('delete') - ->will($this->throwException(new \Exception)); - - $connection = new Db\Connection($testAdapter, "schema"); - - $databaseTester = new Db\SimpleTester($connection); - - $this->assertSame($connection, $databaseTester->getConnection()); - } - - public function testSetupDatabase() - { - $testAdapter = $this->getMock('Zend\Test\DbAdapter'); - $testAdapter->expects($this->any()) - ->method('delete') - ->will($this->throwException(new \Exception)); - - $connection = new Db\Connection($testAdapter, "schema"); - - $databaseTester = new Db\SimpleTester($connection); - - $dataSet = $this->getMock('PHPUnit_Extensions_Database_DataSet_IDataSet'); - $dataSet->expects($this->any()) - ->method('getIterator') - ->will($this->returnValue($this->getMock('Iterator'))); - $dataSet->expects($this->any()) - ->method('getReverseIterator') - ->will($this->returnValue($this->getMock('Iterator'))); - $databaseTester->setUpDatabase($dataSet); - } - - public function testInvalidConnectionGivenThrowsException() - { - $this->setExpectedException('Zend\Test\PHPUnit\Db\Exception\InvalidArgumentException'); - - $connection = $this->getMock('PHPUnit_Extensions_Database_DB_IDatabaseConnection'); - - $databaseTester = new Db\SimpleTester($connection); - } -} diff --git a/test/PHPUnit/Db/TestCaseTest.php b/test/PHPUnit/Db/TestCaseTest.php deleted file mode 100644 index f211070fc0..0000000000 --- a/test/PHPUnit/Db/TestCaseTest.php +++ /dev/null @@ -1,99 +0,0 @@ -_connectionMock == null) { - $this->_connectionMock = $this->getMock( - 'Zend\Test\PHPUnit\Db\Connection', array(), array(new \Zend\Test\DbAdapter(), "schema") - ); - } - return $this->_connectionMock; - } - - /** - * Returns the test dataset. - * - * @return PHPUnit_Extensions_Database_DataSet_IDataSet - */ - protected function getDataSet() - { - return new \PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array()); - } - - public function testDatabaseTesterIsInitialized() - { - $this->assertTrue($this->databaseTester instanceof \PHPUnit_Extensions_Database_ITester); - } - - public function testDatabaseTesterNestsDefaultConnection() - { - $this->assertTrue($this->databaseTester->getConnection() instanceof \PHPUnit_Extensions_Database_DB_IDatabaseConnection); - } - - public function testCheckZendDbConnectionConvenienceMethodReturnType() - { - $mock = $this->getMock('\Zend\Db\Adapter\Pdo\Sqlite', array('delete'), array(), 'Zend_DB_Adapter_Mock', false); - $this->assertTrue($this->createZendDbConnection($mock, "test") instanceof \Zend\Test\PHPUnit\Db\Connection); - } - - public function testCreateDbTableDataSetConvenienceMethodReturnType() - { - $tableMock = $this->getMock('\Zend\Db\Table\Table', array(), array(), "", false); - $tableDataSet = $this->createDbTableDataSet(array($tableMock)); - $this->assertTrue($tableDataSet instanceof \Zend\Test\PHPUnit\Db\DataSet\DbTableDataSet); - } - - public function testCreateDbTableConvenienceMethodReturnType() - { - $mock = $this->getMock('Zend\Db\Table\Table', array(), array(), "", false); - $table = $this->createDbTable($mock); - $this->assertTrue($table instanceof \Zend\Test\PHPUnit\Db\DataSet\DbTable); - } - - public function testCreateDbRowsetConvenienceMethodReturnType() - { - $mock = $this->getMock('Zend\Db\Table\Rowset', array(), array(array())); - $mock->expects($this->once())->method('toArray')->will($this->returnValue(array("foo" => 1, "bar" => 1))); - - $rowset = $this->createDbRowset($mock, "fooTable"); - - $this->assertTrue($rowset instanceof \Zend\Test\PHPUnit\Db\DataSet\DbRowset); - } - - public function testGetAdapterConvenienceMethod() - { - $this->_connectionMock->expects($this->once()) - ->method('getConnection'); - $this->getAdapter(); - } -}