private function _createTestMerchant() { $merchant = new Merchant(); $merchant->setId(1)->setName('Test Merchant')->save(); return $merchant; }
} $db->exec(file_get_contents($schemaPath)); /* * Parse data from CSV and insert into the database. */ if (!file_exists($config->testData->filepath)) { throw new Exception('Test data file "' . $config->testData->filepath . '" does not exist.'); } $testCsvData = array_slice(array_map('str_getcsv', file($config->testData->filepath)), 1); $currencyConverter = new CurrencyConverter(); foreach ($testCsvData as $testCsvDataRow) { if (empty($testCsvDataRow[0])) { continue; } $testDataRow = explode(';', $testCsvDataRow[0]); if (empty($testDataRow[0]) || empty($testDataRow[1]) || empty($testDataRow[2])) { continue; } preg_match('/(\\p{Sc})([\\d\\.,]+)/u', str_replace('"', '', $testDataRow[2]), $matches); $merchant = new Merchant(); if (!$merchant->findPk($testDataRow[0])) { $merchant->setId($testDataRow[0])->setName('Test Name ' . $testDataRow[0])->save(); } $currency = CurrencyConverter::DEFAULT_SYSTEM_CURRENCY; if (!isset(CurrencyConverter::$currencySymbolMap[$matches[1]]) || !($amount = $currencyConverter->convert(CurrencyConverter::$currencySymbolMap[$matches[1]], $currency, $matches[2]))) { // TODO: Notify about unsupported / unconverted currency. $currency = $matches[1]; $amount = $matches[2]; } (new Transaction())->setDate(str_replace('"', '', $testDataRow[1]))->setAmount($amount)->setCurrency($currency)->setMerchant($merchant)->save(); }