Skip to content
This repository has been archived by the owner on Jun 2, 2020. It is now read-only.

Commit

Permalink
Fix BC break with Symfony 2.3 and 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierstoval committed Mar 16, 2015
1 parent 9b4ef7e commit 69271db
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Listeners/FlushTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function flushTranslations()
public static function getSubscribedEvents()
{
return array(
KernelEvents::FINISH_REQUEST => array('flushTranslations'),
'kernel.finish_request' => array('flushTranslations'),
KernelEvents::TERMINATE => array('flushTranslations'),
KernelEvents::EXCEPTION => array('flushTranslations')
);
Expand Down
3 changes: 2 additions & 1 deletion Listeners/LocaleListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;

class LocaleListener implements EventSubscriberInterface
Expand All @@ -26,7 +27,7 @@ public function __construct($defaultLocale = 'en')
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if (!$request->hasPreviousSession()) {
if (!$request->hasPreviousSession() || $event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
return;
}

Expand Down
9 changes: 6 additions & 3 deletions Tests/Controller/TranslationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ public function testAdminAndExport()
$exportLink = $crawler->filter('div.container > h1 + a');
$translationsContainer = $crawler->filter('div.container .row > div.alert');

$this->assertContains('alert-danger', $translationsContainer->attr('class'));
$this->assertContains('/admin/translations/export', $exportLink->attr('href'));
$this->assertGreaterThan(0, $exportLink->count());
$this->assertGreaterThan(0, count($translationsContainer));
if (count($translationsContainer)) {
$this->assertContains('alert-danger', $translationsContainer->attr('class'));
$this->assertContains('/admin/translations/export', $exportLink->attr('href'));
$this->assertGreaterThan(0, $exportLink->count());
}

$crawler->clear();
$crawler = $client->click($exportLink->link('GET'));
Expand Down
13 changes: 9 additions & 4 deletions Tests/Fixtures/AbstractTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,18 @@ class AbstractTestCase extends WebTestCase
*/
protected function getKernel(array $options = array())
{
if (!static::$kernel) {
static::bootKernel($options);
}

return static::$kernel;
}

public function setUp()
{
if (static::$kernel) {
static::$kernel->shutdown();
}
static::$kernel = static::createKernel(array());
static::$kernel->boot();
}

/**
* Generates tokens according to normally Translator behavior
* @param $source
Expand Down
4 changes: 2 additions & 2 deletions Tests/Fixtures/App/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ public function registerContainerConfiguration(LoaderInterface $loader)
*/
public function getCacheDir()
{
return sys_get_temp_dir().'/OrbitaleTranslationBundle/cache';
return __DIR__.'/../../../build/cache/';
}

/**
* @return string
*/
public function getLogDir()
{
return sys_get_temp_dir().'/OrbitaleTranslationBundle/logs';
return __DIR__.'/../../../kernel_logs/';
}
}
33 changes: 19 additions & 14 deletions Tests/Translator/ExtractionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,26 @@
use Orbitale\Bundle\TranslationBundle\Tests\Fixtures\AbstractTestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Yaml\Yaml;

class ExtractionTest extends AbstractTestCase
{

/**
* @var EntityManager
*/
protected $em;

public function __construct($name = null, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
$this->em = $this->getKernel()->getContainer()->get('doctrine')->getManager();
}

/**
* {@inheritdoc}
*/
protected function setUp()
public function setUp()
{
parent::setUp();
$this->em = static::$kernel->getContainer()->get('doctrine')->getManager();

// Ensure the table is empty
$connection = $this->em->getConnection();
$connection->query($connection->getDatabasePlatform()->getTruncateTableSQL('orbitale_translations', true));
Expand Down Expand Up @@ -77,8 +74,6 @@ private function processDummyDatas()

public function testSuccessfulExtractionCommand()
{
static::bootKernel();

$dummyDatas = $this->processDummyDatas();

$outputDirectory = $this->getKernel()->getContainer()->getParameter('kernel.root_dir').'/../../../vendor/_translations/';
Expand All @@ -100,7 +95,7 @@ public function testSuccessfulExtractionCommand()
'--output-directory' => $outputDirectory,
'--dirty' => true,
));
$output = new BufferedOutput(OutputInterface::VERBOSITY_DEBUG);
$output = new NullOutput(OutputInterface::VERBOSITY_QUIET);
$command->run($arrayInput, $output);

$shouldBeThereFiles = array(
Expand Down Expand Up @@ -165,9 +160,19 @@ public function testSuccessfulExtractionCommand()
'--output-directory' => $outputDirectory,
'--dirty' => true,
));
$output = new BufferedOutput(OutputInterface::VERBOSITY_DEBUG);
$commandOutput = $command->run($arrayInput, $output);
$output = $output->fetch();

if (class_exists('Symfony\Component\Console\Output\BufferedOutput')) {
$output = new BufferedOutput(OutputInterface::VERBOSITY_DEBUG);
$commandOutput = $command->run($arrayInput, $output);
$output = $output->fetch();
} else {
$fileName = $this->getKernel()->getRootDir().'/../../../build/_console.test.output.log';
$f = fopen($fileName, 'w');
$output = new StreamOutput($f, OutputInterface::VERBOSITY_DEBUG);
$commandOutput = $command->run($arrayInput, $output);
fclose($f);
$output = file_get_contents($fileName);
}
$this->assertGreaterThan(0, $commandOutput);
$this->assertContains('Wrong output format', $output);
$this->assertContains('An unknown error has occurred, please check your configuration and datas.', $output);
Expand Down
23 changes: 9 additions & 14 deletions Tests/Translator/TranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,28 @@

class TranslatorTest extends AbstractTestCase
{
/**
* @var EntityManager
*/
protected $em;

/**
* @var Translator
*/
protected $translator;

/**
* @var EntityManager
* {@inheritdoc}
*/
protected $em;

public function __construct($name = null, array $data = array(), $dataName = '')
public function setUp()
{
parent::__construct($name, $data, $dataName);
parent::setUp();
$this->em = $this->getKernel()->getContainer()->get('doctrine')->getManager();

$this->translator = $this->getKernel()->getContainer()->get('orbitale_translator');
$this->translator->setFlushStrategy(Translator::FLUSH_RUNTIME);
$this->translator->setFallbackLocales(array($this->getKernel()->getContainer()->getParameter('locale')));
$this->em = $this->getKernel()->getContainer()->get('doctrine')->getManager();
}

/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->translator->emptyCatalogue();

// Ensure the table is empty
Expand All @@ -58,7 +55,6 @@ public function testManualConstruct()
{
$exception = '';
try {
$this->bootKernel();
$translator = new Translator($this->getKernel()->getContainer(), new MessageSelector());
$translator->__construct($this->getKernel()->getContainer(), new MessageSelector());
} catch (\Exception $e) {
Expand Down Expand Up @@ -406,7 +402,6 @@ public function testTranslationsLikeDomain()

public function testDestructFlush()
{
$this->bootKernel();
$translator = new Translator($this->getKernel()->getContainer(), new MessageSelector());
$translator->emptyCatalogue();
$translator->setFlushStrategy(Translator::FLUSH_TERMINATE);
Expand Down
4 changes: 4 additions & 0 deletions Tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
unlink($dbFile);
}

if (!is_dir(__DIR__.'/../build')) {
mkdir(__DIR__.'/../build');
}

include __DIR__.'/Fixtures/App/AppKernel.php';

$application = new Application(new AppKernel('test', true));
Expand Down

0 comments on commit 69271db

Please sign in to comment.