public function setUp() { /** @var SocketInterface $socket */ $socket = $this->getMock('JLaso\\TradukojConnector\\Socket\\SocketInterface'); $socket->method('write')->will($this->returnCallback(function ($msg, $len) { return $len; })); $socket->method('read')->will($this->returnCallback(function ($len, $type) { switch ($len) { case 10: return ClientSocketApi::ACK . PHP_EOL; case 2048: return "Welcome!"; default: $val = '{"result":false,"reason":"test"}' . PHP_EOL; $val = function_exists('lzf_compress') ? lzf_compress($val) : gzcompress($val); return sprintf("%06d:001:001:%s", strlen($val), $val); } })); $loader = new ArrayLoader(); $config = $loader->load($this->getConfigArray()); $postClient = $this->getMock('JLaso\\TradukojConnector\\PostClient\\PostClientInterface'); $postClient->method('call')->will($this->returnCallback(function ($url, $data) { return ClientSocketApiTest::postClientCallMock($url, $data); })); $nullOutput = new NullOutput(); $this->clientSocketApi = new ClientSocketApi($config, $socket, $postClient, $nullOutput); }
/** * Execute the console command. * * @return void */ public function fire() { $config = ArrayLoader::load(config('tradukoj')); $this->debugStatus = $this->option('debug'); $output = $this->getOutput(); $clientSocketApi = new ClientSocketApi($config, new Socket(), new PostCurl(), new ConsoleOutput(), $this->debugStatus); $this->info("Connecting with Tradukoj ..."); $clientSocketApi->init(); if ($this->option('upload-first')) { $catalogs = $this->manager->getCatalogs(); foreach ($catalogs as $catalog) { $output->writeln(PHP_EOL . sprintf('<info>Uploading catalog %s ...</info>', $catalog)); $data = $this->manager->getTranslations($catalog); $this->output->writeln('uploadKeys("' . $catalog . '", $data)'); $clientSocketApi->uploadKeys($catalog, $data); } $this->info('Done!'); $clientSocketApi->shutdown(); return; } // normal synchronization (not upload-first) $catalogs = $clientSocketApi->getCatalogIndex(); foreach ($catalogs as $catalog) { $output->writeln(PHP_EOL . sprintf('Downloading catalog "%s" ...', $catalog)); $translations = $clientSocketApi->downloadKeys($catalog); var_dump($translations); //$data = $this->manager->getTranslations($catalog); //$this->output->writeln('uploadKeys("' . $catalog . '", $data)'); //$clientSocketApi->uploadKeys($catalog, $data); } $clientSocketApi->shutdown(); $this->info('Done!'); }
public function setUp() { /** @var SocketInterface $socket */ $socket = $this->getMock('JLaso\\TradukojConnector\\Socket\\SocketInterface'); $socket->expects($this->atLeastOnce())->method('read')->will($this->returnCallback(function ($length) { return ClientReadSocketTest::readSocketMock($length); })); $loader = new ArrayLoader(); $config = $loader->load($this->getConfigArray()); $postClient = $this->getMock('JLaso\\TradukojConnector\\PostClient\\PostClientInterface'); $nullOutput = new NullOutput(); $this->clientSocketApi = new ClientSocketApi($config, $socket, $postClient, $nullOutput); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use JLaso\TradukojConnector\Model\Loader\ArrayLoader; use JLaso\TradukojConnector\ClientSocketApi; use JLaso\TradukojConnector\Socket\Socket; use JLaso\TradukojConnector\PostClient\PostCurl; use JLaso\TradukojConnector\Output\ConsoleOutput; $loader = new ArrayLoader(); $config = $loader->load(array('project_id' => 1, 'key' => 'key', 'secret' => 'secret', 'url' => 'https://localhost/api/')); $socketClient = new Socket(); $postClient = new PostCurl(); $consoleOutput = new ConsoleOutput(); $clientSocketApi = new ClientSocketApi($config, $socketClient, $postClient, $consoleOutput, true); // initialize client $clientSocketApi->init(); // getters // fetch the list of bundles of the project $bundles = $clientSocketApi->getBundleIndex(); // get the list of catalogs of the project $catalogs = $clientSocketApi->getCatalogIndex(); $keys = $clientSocketApi->getKeyIndex($bundles[0]); $messages = $clientSocketApi->getMessages($bundles[0], $keys[0]);
/** * @expectedException \JLaso\TradukojConnector\Exception\InvalidConfigException */ public function testInvalidConfigException() { $loader = new ArrayLoader(); $config = $loader->load(array()); }