Allows for creating datasets from multiple sources (csv, query, xml, etc.)
Author: Mike Lively (m@digitalsandwich.com)
Inheritance: extends PHPUnit_Extensions_Database_DataSet_AbstractDataSet
 public function testCompatibleTablesInDifferentDataSetsNonDuplicateRows()
 {
     $compatibleTable = new PHPUnit_Extensions_Database_DataSet_DefaultTable($this->expectedDataSet3->getTable("table3")->getTableMetaData());
     $compatibleTable->addRow(array('table3_id' => 4, 'column9' => 'asdasd', 'column10' => 17, 'column11' => 42.57, 'column12' => 'askldja'));
     $compositeDataSet = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array(new PHPUnit_Extensions_Database_DataSet_DefaultDataSet(array($compatibleTable)), $this->expectedDataSet2));
     $this->assertEquals(4, $compositeDataSet->getTable("table3")->getRowCount());
 }
 public function getDataSet($fixtures = array())
 {
     $db = Database::get();
     if (count($this->tables)) {
         $partial = new SimpleXMLElement('<schema></schema>');
         $partial->addAttribute('version', '0.3');
         $xml = simplexml_load_file(DIR_BASE_CORE . '/config/db.xml');
         foreach ($xml->table as $t) {
             $name = (string) $t['name'];
             if (in_array($name, $this->tables)) {
                 $this->appendXML($partial, $t);
             }
         }
         $schema = \Concrete\Core\Database\Schema\Schema::loadFromXMLElement($partial, $db);
         $platform = $db->getDatabasePlatform();
         $queries = $schema->toSql($platform);
         foreach ($queries as $query) {
             $db->query($query);
         }
     }
     if (empty($fixtures)) {
         $fixtures = $this->fixtures;
     }
     $reflectionClass = new ReflectionClass(get_called_class());
     $fixturePath = dirname($reflectionClass->getFilename()) . DIRECTORY_SEPARATOR . 'fixtures';
     $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
     foreach ((array) $fixtures as $fixture) {
         $path = $fixturePath . DIRECTORY_SEPARATOR . "{$fixture}.xml";
         $ds = $this->createMySQLXMLDataSet($path);
         $compositeDs->addDataSet($ds);
     }
     return $compositeDs;
 }
 public function getCompositeDataSet()
 {
     $compositeDataset = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet();
     $dataset = $this->createXMLDataSet(dirname(__FILE__) . '/../_files/XmlDataSets/TruncateCompositeTest.xml');
     $compositeDataset->addDataSet($dataset);
     return $compositeDataset;
 }
 public function getDataSet()
 {
     $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
     $fixturePath = dirname(__FILE__) . DIRECTORY_SEPARATOR;
     $path = $fixturePath . DIRECTORY_SEPARATOR . "statsfixtures.xml";
     $ds = $this->createMySQLXMLDataSet($path);
     $compositeDs->addDataSet($ds);
     return $compositeDs;
 }
 /**
  * @return PHPUnit_Extensions_Database_DataSet_IDataSet
  */
 public function getDataSet()
 {
     $ds1 = $this->createXMLDataSet(TESTS_PATH . '/_files/user.xml');
     $ds2 = $this->createXMLDataSet(TESTS_PATH . '/_files/location.xml');
     $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet();
     $compositeDs->addDataSet($ds1);
     $compositeDs->addDataSet($ds2);
     return $compositeDs;
 }
Example #6
0
 /**
  * Return a composite dataset with all the fixtures files loaded
  *
  * @see PHPUnit_Extensions_Database_TestCase::getDataSet()
  *
  * @return  PHPUnit_Extensions_Database_DataSet_IDataSet
  */
 protected function getDataSet()
 {
     $dataSet = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
     // fill dataset with provided fixture files
     foreach ($this->_fixtures as $filename) {
         $dataSet->addDataSet($this->createXMLDataSet($this->getFixtureFile($filename)));
     }
     return $dataSet;
 }
Example #7
0
 /**
  * @return PHPUnit_Extensions_Database_DataSet_IDataSet
  */
 public function getDataSet()
 {
     $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
     foreach ($this->datasets as $dataset) {
         $file = Kohana::find_file('tests', 'test-data/' . $dataset, 'xml');
         $ds = $this->createFlatXmlDataSet($file);
         $compositeDs->addDataSet($ds);
     }
     return $compositeDs;
 }
 /**
  * Returns test data set.
  * Populates table feedback_bvl_type.
  *
  * @return PHPUnit_Extensions_Database_DataSet_IDataSet
  */
 protected function getDataSet()
 {
     $ds1 = $this->createMySQLXMLDataSet(TABLE_FIXTURES_PATH . 'feedback_bvl_type.xml');
     $ds2 = $this->createMySQLXMLDataSet(TABLE_FIXTURES_PATH . 'psc.xml');
     $ds3 = $this->createMySQLXMLDataSet(TABLE_FIXTURES_PATH . 'NDB_BVL_FeedbackTest.xml');
     $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet();
     $compositeDs->addDataSet($ds1);
     $compositeDs->addDataSet($ds2);
     $compositeDs->addDataSet($ds3);
     return $compositeDs;
 }
Example #9
0
 /**
  * @return PHPUnit_Extensions_Database_DataSet_IDataSet
  */
 public function getDataSet()
 {
     $fixtures = glob(realpath(rtrim(CENTREON_PATH, '/') . '/core/tests/fixtures/*.xml'));
     $fixtures = array_merge($fixtures, glob(realpath(rtrim(CENTREON_PATH, '/') . '/modules') . '/*Module/tests/fixtures/*.xml'));
     $compositeDs = new \PHPUnit_Extensions_Database_DataSet_CompositeDataSet();
     foreach ($fixtures as $fixture) {
         $ds = $this->createFlatXmlDataSet($fixture);
         $compositeDs->addDataset($ds);
     }
     return $compositeDs;
 }
 public function getDataSet()
 {
     $messages = $this->createFlatXmlDataSet('_files/messages.xml');
     $attachments = $this->createFlatXmlDataSet('_files/attachments.xml');
     $likes = $this->createFlatXmlDataSet('_files/likes.xml');
     $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet();
     $compositeDs->addDataSet($messages);
     $compositeDs->addDataSet($attachments);
     $compositeDs->addDataSet($likes);
     return $compositeDs;
 }
 public function loadFixturesByClass(CompositeDataSet $dataSets, $name, AbstractDbTestCase $class)
 {
     $getFixtureMethod = [$class, 'getFixtures'];
     if (!is_callable($getFixtureMethod)) {
         return;
     }
     $fixtures = call_user_func($getFixtureMethod);
     if (empty($fixtures[$name])) {
         return;
     }
     $dataSets->addDataSet(new \PHPUnit_Extensions_Database_DataSet_ArrayDataSet($fixtures[$name]));
 }
Example #12
0
 public function getDataSet($fixtures = array())
 {
     if (empty($fixtures)) {
         $fixtures = $this->fixtures;
     }
     $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
     $fixturePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fixtures';
     foreach ($fixtures as $fixture) {
         $path = $fixturePath . DIRECTORY_SEPARATOR . "{$fixture}.xml";
         $ds = $this->createMySQLXMLDataSet($path);
         $compositeDs->addDataSet($ds);
     }
     return $compositeDs;
 }
Example #13
0
 /**
  * 设置测试的数据集
  *
  * @access protected
  * @return \PHPUnit_Extensions_Database_DataSet_IDataSet
  */
 protected function getDataSet()
 {
     $xml_data = $this->get_data_set();
     if (!isset($xml_data)) {
         throw new sw_exception("must defined data xml.");
     }
     if (is_array($xml_data)) {
         $composite_ds = new \PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
         foreach ($xml_data as $file_path) {
             $ds = $this->createXMLDataSet($file_path);
             $composite_ds->addDataSet($ds);
         }
         return $composite_ds;
     } else {
         return $this->createXMLDataSet($xml_data);
     }
 }
Example #14
0
 /**
  * Override to create the test dataset
  *
  * @return PHPUnit_Extensions_Database_DataSet_IDataSet
  * @author Ronan Chilvers <*****@*****.**>
  */
 public function getDataSet()
 {
     if (false === $this->fixturePath) {
         throw new \RuntimeException('Fixture path not provided in TestCase class');
     }
     $composite = new \PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
     $fixturePath = rtrim($this->fixturePath, DIRECTORY_SEPARATOR);
     foreach ($this->fixtures as $fixture) {
         $path = implode(DIRECTORY_SEPARATOR, array($fixturePath, $fixture));
         $extension = substr($path, -3);
         switch (strtolower($extension)) {
             case 'yml':
                 $dataset = $this->createYamlDataSet($path);
                 break;
             case 'php':
                 $dataset = $this->createArrayDataSet(include $path);
                 break;
             default:
                 throw new \RuntimeException('Unknown data set type ' . $fixture);
         }
         $composite->addDataSet($dataset);
     }
     return $composite;
 }
Example #15
0
 /**
  * Retrieve the data to load.
  *
  * @since 1.0.0
  * @access public
  *
  * @param array $fixtures
  * @return PHPUnit_Extensions_Database_DataSet_CompositeDataSet
  */
 public function getDataSet($fixtures = array())
 {
     if (empty($fixtures)) {
         $fixtures = $this->fixtures;
     }
     $composite_ds = new \PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
     $fixture_path = dirname(__FILE__) . '/fixtures';
     foreach ($fixtures as $fixture) {
         $path = $fixture_path . "/{$fixture}.yml";
         $ds = new \PHPUnit_Extensions_Database_DataSet_YamlDataSet($path);
         $composite_ds->addDataSet($ds);
     }
     return $composite_ds;
 }
Example #16
0
 private function getCompositeDataset()
 {
     $ds1 = $this->getFilterDataset();
     $ds2 = $this->createFlatXmlDataSet(D_DIR . "myFlatXml1.xml");
     #Combine them
     /**
      * It seems there is some change in the API lately
      * now the contructor PHPUnit_Extensions_Database_DataSet_CompositeDataSet
      * takes a array as input.
      * and you cannot combine two datasets having common tables.
      * This is not fair :-/
      */
     $compositeDs = new PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
     $compositeDs->addDataSet($ds1);
     $compositeDs->addDataSet($ds2);
     return $compositeDs;
 }
 /**
  * Returns the test dataset.
  *
  * @return PHPUnit_Extensions_Database_DataSet_IDataSet
  */
 protected function getDataSet()
 {
     $compositeDs = new \PHPUnit_Extensions_Database_DataSet_CompositeDataSet(array());
     foreach ($this->fixtures as $fixture) {
         $file = self::getFixturesPath() . "/{$fixture}.xml";
         $ds = $this->createMySQLXMLDataSet($file);
         $compositeDs->addDataSet($ds);
     }
     return $compositeDs;
 }