Chris@0: ':memory:']; Chris@0: $pdo = Connection::open($connection_options); Chris@0: $connection = new Connection($pdo, $connection_options); Chris@0: Chris@0: // Create the tables and fill them with data. Chris@0: foreach ($source_data as $table => $rows) { Chris@0: // Use the biggest row to build the table schema. Chris@0: $counts = array_map('count', $rows); Chris@0: asort($counts); Chris@0: end($counts); Chris@0: $pilot = $rows[key($counts)]; Chris@0: Chris@0: $connection->schema() Chris@0: ->createTable($table, [ Chris@0: // SQLite uses loose affinity typing, so it's OK for every field to Chris@0: // be a text field. Chris@0: 'fields' => array_map(function () { Chris@0: return ['type' => 'text']; Chris@0: }, $pilot), Chris@0: ]); Chris@0: Chris@0: $fields = array_keys($pilot); Chris@0: $insert = $connection->insert($table)->fields($fields); Chris@0: array_walk($rows, [$insert, 'values']); Chris@0: $insert->execute(); Chris@0: } Chris@0: Chris@0: return $connection; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the source plugin against a particular data set. Chris@0: * Chris@0: * @param array $source_data Chris@0: * The source data that the plugin will read. See getDatabase() for the Chris@0: * expected format. Chris@0: * @param array $expected_data Chris@0: * The result rows the plugin is expected to return. Chris@0: * @param int $expected_count Chris@0: * (optional) How many rows the source plugin is expected to return. Chris@0: * @param array $configuration Chris@0: * (optional) Configuration for the source plugin. Chris@0: * @param mixed $high_water Chris@0: * (optional) The value of the high water field. Chris@0: * Chris@0: * @dataProvider providerSource Chris@0: * Chris@0: * @requires extension pdo_sqlite Chris@0: */ Chris@0: public function testSource(array $source_data, array $expected_data, $expected_count = NULL, array $configuration = [], $high_water = NULL) { Chris@0: $plugin = $this->getPlugin($configuration); Chris@0: Chris@0: // Since we don't yet inject the database connection, we need to use a Chris@0: // reflection hack to set it in the plugin instance. Chris@0: $reflector = new \ReflectionObject($plugin); Chris@0: $property = $reflector->getProperty('database'); Chris@0: $property->setAccessible(TRUE); Chris@0: $property->setValue($plugin, $this->getDatabase($source_data)); Chris@0: Chris@0: parent::testSource($source_data, $expected_data, $expected_count, $configuration, $high_water); Chris@0: } Chris@0: Chris@0: }