Skip to content

Commit

Permalink
Improve messages test on HHVM. (yiisoft#13520)
Browse files Browse the repository at this point in the history
  • Loading branch information
rob006 authored and cebe committed Feb 6, 2017
1 parent 97c43c2 commit 4c46c6a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 17 deletions.
25 changes: 20 additions & 5 deletions tests/framework/console/controllers/BaseMessageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@ public function setUp()
if (!file_exists($this->sourcePath)) {
$this->markTestIncomplete('Unit tests runtime directory should have writable permissions!');
}
$this->configFileName = Yii::getAlias('@yiiunit/runtime') . DIRECTORY_SEPARATOR . 'message_controller_test_config.php';
$this->configFileName = $this->generateConfigFileName();
}

/**
* Generate random config name.
*
* @return string
*/
protected function generateConfigFileName()
{
$this->configFileName = Yii::getAlias('@yiiunit/runtime')
. DIRECTORY_SEPARATOR . 'message_controller_test_config-' . md5(uniqid()) . '.php';

return $this->configFileName;
}

public function tearDown()
Expand Down Expand Up @@ -72,7 +85,9 @@ protected function saveConfigFile(array $config)
unlink($this->configFileName);
}
$fileContent = '<?php return ' . VarDumper::export($config) . ';';
file_put_contents($this->configFileName, $fileContent);
// save new config on random name to bypass HHVM cache
// https://github.com/facebook/hhvm/issues/1447
file_put_contents($this->generateConfigFileName(), $fileContent);
}

/**
Expand Down Expand Up @@ -402,7 +417,7 @@ public function testCreateTranslationFromNested()
$this->assertArrayHasKey($mainMessage, $messages, "\"$mainMessage\" is missing in translation file. Command output:\n\n" . $out);
$this->assertArrayHasKey($nestedMessage, $messages, "\"$nestedMessage\" is missing in translation file. Command output:\n\n" . $out);
}

/**
* @depends testCreateTranslation
*
Expand All @@ -417,7 +432,7 @@ public function testMissingLanguage()

$this->saveConfigFile($this->getConfig());
$out = $this->runMessageControllerAction('extract', [$this->configFileName]);

$secondLanguage = 'pl';
$this->saveConfigFile($this->getConfig(['languages' => [$this->language, $secondLanguage]]));
$out .= $this->runMessageControllerAction('extract', [$this->configFileName]);
Expand All @@ -433,4 +448,4 @@ public function testMissingLanguage()
class MessageControllerMock extends MessageController
{
use StdOutBufferControllerTrait;
}
}
17 changes: 10 additions & 7 deletions tests/framework/console/controllers/PHPMessageControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,19 @@ protected function saveMessages($messages, $category)
*/
protected function loadMessages($category)
{
if (defined('HHVM_VERSION')) {
// https://github.com/facebook/hhvm/issues/1447
static::markTestSkipped('Can not test on HHVM because require is cached.');
}

$messageFilePath = $this->getMessageFilePath($category);

if (!file_exists($messageFilePath)) {
return [];
}
return require $messageFilePath;

if (defined('HHVM_VERSION')) {
// use eval() to bypass HHVM content cache
// https://github.com/facebook/hhvm/issues/1447
$content = file_get_contents($messageFilePath);
return eval(substr($content, strpos($content, 'return ')));
} else {
return require $messageFilePath;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ public function setUp()
{
parent::setUp();

if (defined('HHVM_VERSION')) {
$this->markTestSkipped('POMessageControllerTest can not run on HHVM because it relies on saving and re-including PHP files which is not supported by HHVM.');
}

$this->messagePath = Yii::getAlias('@yiiunit/runtime/test_messages');
FileHelper::createDirectory($this->messagePath, 0777);
}
Expand Down Expand Up @@ -84,4 +80,4 @@ protected function loadMessages($category)
$gettext = new GettextPoFile();
return $gettext->load($messageFilePath, $category);
}
}
}

0 comments on commit 4c46c6a

Please sign in to comment.