You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.2 KiB
87 lines
2.2 KiB
10 years ago
|
<?php
|
||
|
namespace yiiunit\framework\console\controllers;
|
||
|
|
||
|
|
||
|
use Yii;
|
||
|
use yii\helpers\FileHelper;
|
||
|
use yii\helpers\VarDumper;
|
||
|
|
||
|
/**
|
||
|
* Tests that [[\yii\console\controllers\MessageController]] works as expected with PHP message format.
|
||
|
*/
|
||
|
class PHPMessageControllerTest extends BaseMessageControllerTest
|
||
|
{
|
||
|
protected $messagePath;
|
||
|
|
||
|
public function setUp()
|
||
|
{
|
||
|
parent::setUp();
|
||
|
$this->messagePath = Yii::getAlias('@yiiunit/runtime/test_messages');
|
||
|
FileHelper::createDirectory($this->messagePath, 0777);
|
||
|
}
|
||
|
|
||
|
public function tearDown()
|
||
|
{
|
||
|
parent::tearDown();
|
||
|
FileHelper::removeDirectory($this->messagePath);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @inheritdoc
|
||
|
*/
|
||
|
protected function getDefaultConfig()
|
||
|
{
|
||
|
return [
|
||
|
'format' => 'php',
|
||
|
'languages' => [$this->language],
|
||
|
'sourcePath' => $this->sourcePath,
|
||
|
'messagePath' => $this->messagePath,
|
||
|
'overwrite' => true,
|
||
|
];
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param string $category
|
||
|
* @return string message file path
|
||
|
*/
|
||
|
protected function getMessageFilePath($category)
|
||
|
{
|
||
|
return $this->messagePath . '/' . $this->language . '/' . $category . '.php';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @inheritdoc
|
||
|
*/
|
||
|
protected function saveMessages($messages, $category)
|
||
|
{
|
||
|
$fileName = $this->getMessageFilePath($category);
|
||
|
if (file_exists($fileName)) {
|
||
|
unlink($fileName);
|
||
|
} else {
|
||
|
$dirName = dirname($fileName);
|
||
|
if (!file_exists($dirName)) {
|
||
|
mkdir($dirName, 0777, true);
|
||
|
}
|
||
|
}
|
||
|
$fileContent = '<?php return ' . VarDumper::export($messages) . ';';
|
||
|
file_put_contents($fileName, $fileContent);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @inheritdoc
|
||
|
*/
|
||
10 years ago
|
protected function loadMessages($category)
|
||
10 years ago
|
{
|
||
|
if (defined('HHVM_VERSION')) {
|
||
|
// https://github.com/facebook/hhvm/issues/1447
|
||
10 years ago
|
static::markTestSkipped('Can not test on HHVM because require is cached.');
|
||
10 years ago
|
}
|
||
|
|
||
|
$messageFilePath = $this->getMessageFilePath($category);
|
||
10 years ago
|
|
||
10 years ago
|
if (!file_exists($messageFilePath)) {
|
||
10 years ago
|
return [];
|
||
|
}
|
||
10 years ago
|
return require $messageFilePath;
|
||
|
}
|
||
|
}
|