1

I'm running PHPUnit 5, with DBUnit 2.0.3, and Phinx 0.8.2. I'm trying to set up a test with a SQLite in memory database:

abstract class ApiTest extends PHPUnit_Extensions_Database_TestCase
{
    protected $pdo;

    public function getConnection()
    {
        return $this->createDefaultDBConnection($this->pdo, ':memory:');
    }

    public function getDataSet()
    {
        return $this->createFlatXMLDataSet(dirname(__FILE__) . '/DataSets/TestDataSet.xml');
    }

    protected function setUp()
    {
        $this->pdo = new PDO('sqlite::memory:', null, null, [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
        ]);

        $configArray = require('phinx.php');

        $configArray['environments']['test'] = [
            'adapter'    => 'sqlite',
            'connection' => $this->pdo
        ];

        $config = new Config($configArray);

        $manager = new Manager($config, new StringInput(' '), new NullOutput());

        $manager->migrate('test');

        $this->getDataSet();
    }
}

This is my test:

class DatabaseTest extends ApiTest
{
    public function testCodes()
    {
        $count = $this->getConnection()->getRowCount('user');

        dd($count);
    }
} 

This is my data:

<?xml version="1.0" ?>
<dataset>
    <user id="1" username="johnsmith" password="pwdpwd" token="tokenhere" token_validity="1" deleted="0" />
</dataset>

When I run the test I get a row count of 0. I'm expecting a row count of 1. I know the migration is working because if I enter a dummy table name it errors with "row not found".

GluePear
  • 7,244
  • 20
  • 67
  • 120

0 Answers0