public function testFindCurrencyByIso() { $data = [['name' => 'US Dollar', 'iso_code' => 'USD', 'convert_nominal' => 1, 'convert_rate' => 80, 'sort_order' => 1, 'format_string' => '$ #', 'thousands_sep' => '.', 'dec_point' => ',', 'is_main' => 0, 'intl_formatting' => 1], 'Euro' => ['name' => 'Euro', 'iso_code' => 'EUR', 'convert_rate' => 90, 'format_string' => '€ #', 'is_main' => 1]]; $storage = (new Currency())->getStorage(); FunctionalHelper::flushStorage($storage); $this->assertFileNotExists($storage); CurrencyStorageHelper::generateStorage($data, $storage, Currency::className()); $c = CurrencyHelper::findCurrencyByIso('USD'); $this->assertEquals('US Dollar', $c->name); return $c; }
/** * Using PHPUnit with static variables are painfully. Because of it this single test executes in different Class then others. */ public function testGetMainCurrencyNotExists() { $data = [['name' => 'US Dollar', 'iso_code' => 'USD', 'convert_nominal' => 1, 'convert_rate' => 62.83, 'sort_order' => 1, 'format_string' => '$ #', 'thousands_sep' => '.', 'dec_point' => ',', 'is_main' => 0], 'Euro' => ['name' => 'Euro', 'iso_code' => 'EUR', 'convert_rate' => 71.31999999999999, 'format_string' => '€ #', 'is_main' => 0]]; $storage = (new Currency())->getStorage(); FunctionalHelper::flushStorage($storage); $this->assertFileNotExists($storage); CurrencyStorageHelper::generateStorage($data, $storage, Currency::className()); $this->assertFileExists($storage); $c = CurrencyHelper::getMainCurrency(); $this->assertNull($c); FunctionalHelper::flushCurrencyStorage(); }
public function testGenerateWithReformat() { $data = [['name' => 'Ruble', 'iso_code' => 'RUB', 'is_main' => 1, 'format_string' => '# ΡΡΠ±.', 'intl_formatting' => 0], ['name' => 'US Dollar', 'iso_code' => 'USD', 'convert_nominal' => 1, 'convert_rate' => 62.8353, 'sort_order' => 1, 'format_string' => '$ #', 'thousands_sep' => '.', 'dec_point' => ','], 'Euro' => ['name' => 'Euro', 'iso_code' => 'EUR', 'convert_rate' => 71.32429999999999, 'format_string' => '€ #']]; $storage = (new Currency())->getStorage(); FunctionalHelper::flushStorage($storage); CurrencyStorageHelper::generateStorage($data, $storage, Currency::className()); $this->assertFileExists($storage); $a = []; if (true === file_exists($storage)) { $a = (include $storage); } $this->assertCount(3, $a); FunctionalHelper::flushStorage($storage); }