public function test_squeezed_file_should_have_same_contents() { if (!defined('DS')) { define('DS', '/'); } $dir = dirname(__FILE__) . DS . 'UtilsSqueezeRealLifeTest'; $originalFile = $dir . DS . '10-config.php'; $squeezedFile = $dir . DS . '10-config.squeezed.php'; $original = (require $originalFile); $utils = new Utils(); file_put_contents($squeezedFile, $utils->squeeze($original)); $unsqueezed = (require $squeezedFile); unlink($squeezedFile); $cmp_function = function ($a, $b) { if ($a[0] == $b[0]) { // sort by key if scope/blabla is equal return strcmp($a['parameters']['key'], $b['parameters']['key']); } return strcmp($a[0], $b[0]); // sort by scope/blabla }; usort($original, $cmp_function); usort($unsqueezed, $cmp_function); $this->assertEquals($original, $unsqueezed, "Original and unsqueezed configs differ"); }
/** * @param string $path */ protected function _squeezeFile($path) { try { $configuration = $this->_readFile($path); $output = $this->helper->squeeze($configuration); file_put_contents($path, $output); $this->_output->writeln('<info>Config Squeezed!</info>'); } catch (\UnexpectedValueException $e) { $this->_output->writeln('<error>File doesn\'t contains valid config!</error>'); } catch (\Exception $e) { $this->_output->writeln('<error>' . $e->getMessage() . '</error>'); } }
/** * @test * @covers ::generateRandomOrderPrefix */ public function generateRandomOrderPrefix() { $utils = new Utils(); $generated = $utils->generateRandomOrderPrefix(); $counter1 = time() - Utils::TEST_ORDER_PREFIX_DATE; $counter2 = $counter1 - 1; // also check a second ago in case the clock has ticked $counter1Base36 = strtoupper(base_convert($counter1, 10, 36)); $counter2Base36 = strtoupper(base_convert($counter2, 10, 36)); $match1 = 0 === strpos($generated, $counter1Base36); $match2 = 0 === strpos($generated, $counter2Base36); $this->assertTrue($match1 xor $match2); $this->assertEquals(Utils::TEST_ORDER_PREFIX_LENGTH, strlen($generated)); }
public function test_updateProductForStore_with_multiple_storeviews_should_expand_to_valid_conf() { $utils = new Utils(); $conf = $utils->updateProductForStore(['store:code/ch_fr#id', 'store:code/at_de#id'], 'backup-dvd', ['description' => 'Backup DVD', 'short_description' => 'Backup DVD']); $this->assertEquals([['product/update', 'parameters' => ['data' => ['description' => 'Backup DVD', 'short_description' => 'Backup DVD', 'sku' => 'backup-dvd', 'store_id' => 'store:code/ch_fr#id']]], ['product/update', 'parameters' => ['data' => ['description' => 'Backup DVD', 'short_description' => 'Backup DVD', 'sku' => 'backup-dvd', 'store_id' => 'store:code/at_de#id']]]], $conf); }
/** * @expectedException UnexpectedValueException * @expectedExceptionMessage squeeze can only operate on config entries */ public function test_should_throw_when_not_config_entries_present() { // $this->markTestSkipped("I'll be back..."); $this->utils->squeeze([['store/createconfig', 'parameters' => ['key' => 'storeConfpath_1', 'value' => 'storeConfVal_1', 'store' => 'storeSelector']], ['taxclas/create', 'parameters' => ['key' => 'storeConfpath_2', 'value' => 'storeConfVal_2', 'store' => 'storeSelector']]]); }
public function test_createConfigForWebsite_should_expand_to_valid_conf() { $utils = new Utils(); $conf = $utils->createConfigForWebsite('website:code/avast#id', ['abandonment/alert_identity/email_identity' => 'general']); $this->assertEquals([['website/createconfig', 'parameters' => ['key' => 'abandonment/alert_identity/email_identity', 'value' => 'general', 'store' => 'website:code/avast#id']]], $conf); }