Commit 5f49c655 by Alexander Makarov

Added tests that are making sure Gii isn't failing with errors

parent 09fc0c3c
<?php
namespace yiiunit\extensions\gii;
use yii\gii\generators\controller\Generator as ControllerGenerator;
use yii\gii\generators\crud\Generator as CRUDGenerator;
use yii\gii\generators\extension\Generator as ExtensionGenerator;
use yii\gii\generators\form\Generator as FormGenerator;
use yii\gii\generators\model\Generator as ModelGenerator;
use yii\gii\generators\module\Generator as ModuleGenerator;
/**
* GeneratorsTest checks that Gii generators aren't throwing any errors during generation
*/
class GeneratorsTest extends GiiTestCase
{
public function testControllerGenerator()
{
$generator = new ControllerGenerator();
$generator->template = 'default';
$generator->controller = 'test';
if ($generator->validate()) {
$generator->generate();
} else {
print_r($generator->getErrors());
}
}
public function testExtensionGenerator()
{
$generator = new ExtensionGenerator();
$generator->template = 'default';
$generator->vendorName = 'samdark';
$generator->namespace = 'samdark\\';
$generator->license = 'BSD';
$generator->title = 'Sample extension';
$generator->description = 'This is sample description.';
$generator->authorName = 'Alexander Makarov';
$generator->authorEmail = 'sam@rmcreative.ru';
if ($generator->validate()) {
$generator->generate();
} else {
print_r($generator->getErrors());
}
}
public function testModelGenerator()
{
$generator = new ModelGenerator();
$generator->template = 'default';
$generator->tableName = 'profile';
$generator->modelClass = 'Profile';
if ($generator->validate()) {
$generator->generate();
} else {
print_r($generator->getErrors());
}
}
public function testModuleGenerator()
{
$generator = new ModuleGenerator();
$generator->template = 'default';
$generator->moduleID = 'test';
$generator->moduleClass = 'app\modules\test\Module';
if ($generator->validate()) {
$generator->generate();
} else {
print_r($generator->getErrors());
}
}
public function testFormGenerator()
{
$generator = new FormGenerator();
$generator->template = 'default';
$generator->modelClass = 'yiiunit\extensions\gii\Profile';
$generator->viewName = 'profile';
$generator->viewPath = '@yiiunit/runtime';
if ($generator->validate()) {
$generator->generate();
} else {
print_r($generator->getErrors());
}
}
public function testCRUDGenerator()
{
$generator = new CRUDGenerator();
$generator->template = 'default';
$generator->modelClass = 'yiiunit\extensions\gii\Profile';
$generator->controllerClass = 'app\TestController';
if ($generator->validate()) {
$generator->generate();
} else {
print_r($generator->getErrors());
}
}
}
\ No newline at end of file
<?php
namespace yiiunit\extensions\gii;
use Yii;
use yiiunit\TestCase;
Yii::setAlias('@yii/gii', __DIR__ . '/../../../../extensions/gii');
/**
* GiiTestCase is the base class for all gii related test cases
*/
class GiiTestCase extends TestCase
{
protected $driverName = 'sqlite';
public function setUp()
{
$databases = self::getParam('databases');
$config = $databases[$this->driverName];
$pdo_database = 'pdo_'.$this->driverName;
if (!extension_loaded('pdo') || !extension_loaded($pdo_database)) {
$this->markTestSkipped('pdo and '.$pdo_database.' extension are required.');
}
$this->mockApplication([
'components' => [
'db' => [
'class' => isset($config['class']) ? $config['class'] : 'yii\db\Connection',
'dsn' => $config['dsn'],
'username' => isset($config['username']) ? $config['username'] : null,
'password' => isset($config['password']) ? $config['password'] : null,
],
],
]);
if(isset($config['fixture'])) {
Yii::$app->db->open();
$lines = explode(';', file_get_contents($config['fixture']));
foreach ($lines as $line) {
if (trim($line) !== '') {
Yii::$app->db->pdo->exec($line);
}
}
}
}
}
\ No newline at end of file
<?php
namespace yiiunit\extensions\gii;
use yii\db\ActiveRecord;
class Profile extends ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'profile';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['description'], 'required'],
[['description'], 'string', 'max' => 128]
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'description' => 'Description',
];
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment