0

I am trying to run very simple PHPUnit testing class with Database simulation. I am trying to create dataset with some values. I am using MySQL XML object.

My MySQL XML Object is:

<?xml version="1.0"?>
    <mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <database name="some_test_db">
        <table_data name="some_test_table">
        <row>
            <field name="id">1</field>
            <field name="content_time">1382774967</field>
            <field name="ip">10.0.0.10</field>
            <field name="content">test message</field>
        </row>
        </table_data>
    </database>
    </mysqldump>

My PHP code in the testing class is:

<?php 

class TestOfDatabase extends PHPUnit_Extensions_Database_TestCase {
    protected $pdo;

    public function __construct() {
        $this->pdo = new PDO('sqlite::memory:');
    }   
      protected function setUp() {
        $this->getConnection()->createDataSet();
    }

     /**
     * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
     */
    public function getConnection() {
        return $this->createDefaultDBConnection($this->pdo, 'sqlite');
    }

    /**
     * @return PHPUnit_Extensions_Database_DataSet_IDataSet
     */
    public function getDataSet() {
        return $this->createMySQLXMLDataSet(dirname(__FILE__).'/dataset.xml');
    }

    public function testGetInstance() {
      $this->assertGreaterThan(0, $this->getConnection()->getRowCount('some_test_table'));
    }
}

When I am running TestofDatabase I get "General error 1: no such table: some_test_table".

I can't understand why the mock DB is not being populated with the data that I inserted to dataset.xml.

I already checked that the path is OK.

11
  • Have you selected the database first? Commented Nov 29, 2013 at 13:28
  • 1
    No, Should I do it? When to do it? In the setup? or in the test function? Commented Nov 29, 2013 at 13:31
  • You could try getRowCount('some_test_db.some_test_table') Commented Nov 29, 2013 at 13:36
  • Tried it. but it doesn't work... :-( Commented Nov 29, 2013 at 13:40
  • Sorry, I knew it was a shot in the dark but thought it might be worth exploring. Commented Nov 29, 2013 at 13:41

1 Answer 1

1

You are using an XML file generated by MySQL's utility program. This can probably only be reloaded into a MySQL database. Since you are using SQLite for your testing, try using the simpler XML style as your data source: http://phpunit.de/manual/3.7/en/database.html#database.xml-dataset

<?xml version="1.0" ?>
<dataset>
    <table name="some_test_table">
        <column>id</column>
        <column>content_time</column>
        <column>ip</column>
        <column>content</column>
        <row>
            <value>1</value>
            <value>1382774967</value>
            <value>10.0.0.10</value>
            <value>test message</value>
        </row>
    </table>
</dataset>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.