Commit 9ff9cab6 by Carsten Brandt

ensure gii tests fail on error and not just print_r

parent 6f889e12
...@@ -11,6 +11,7 @@ use yii\gii\generators\module\Generator as ModuleGenerator; ...@@ -11,6 +11,7 @@ use yii\gii\generators\module\Generator as ModuleGenerator;
/** /**
* GeneratorsTest checks that Gii generators aren't throwing any errors during generation * GeneratorsTest checks that Gii generators aren't throwing any errors during generation
* @group gii
*/ */
class GeneratorsTest extends GiiTestCase class GeneratorsTest extends GiiTestCase
{ {
...@@ -18,13 +19,12 @@ class GeneratorsTest extends GiiTestCase ...@@ -18,13 +19,12 @@ class GeneratorsTest extends GiiTestCase
{ {
$generator = new ControllerGenerator(); $generator = new ControllerGenerator();
$generator->template = 'default'; $generator->template = 'default';
$generator->controllerClass = 'test'; $generator->controllerClass = 'app\runtime\TestController';
if ($generator->validate()) { $valid = $generator->validate();
$generator->generate(); $this->assertTrue($valid, 'Validation failed: ' . print_r($generator->getErrors(), true));
} else {
print_r($generator->getErrors()); $this->assertNotEmpty($generator->generate());
}
} }
public function testExtensionGenerator() public function testExtensionGenerator()
...@@ -39,11 +39,10 @@ class GeneratorsTest extends GiiTestCase ...@@ -39,11 +39,10 @@ class GeneratorsTest extends GiiTestCase
$generator->authorName = 'Alexander Makarov'; $generator->authorName = 'Alexander Makarov';
$generator->authorEmail = 'sam@rmcreative.ru'; $generator->authorEmail = 'sam@rmcreative.ru';
if ($generator->validate()) { $valid = $generator->validate();
$generator->generate(); $this->assertTrue($valid, 'Validation failed: ' . print_r($generator->getErrors(), true));
} else {
print_r($generator->getErrors()); $this->assertNotEmpty($generator->generate());
}
} }
public function testModelGenerator() public function testModelGenerator()
...@@ -53,15 +52,14 @@ class GeneratorsTest extends GiiTestCase ...@@ -53,15 +52,14 @@ class GeneratorsTest extends GiiTestCase
$generator->tableName = 'profile'; $generator->tableName = 'profile';
$generator->modelClass = 'Profile'; $generator->modelClass = 'Profile';
if ($generator->validate()) { $valid = $generator->validate();
$files = $generator->generate(); $this->assertTrue($valid, 'Validation failed: ' . print_r($generator->getErrors(), true));
$modelCode = $files[0]->content;
$files = $generator->generate();
$modelCode = $files[0]->content;
$this->assertTrue(strpos($modelCode, "'id' => 'ID'") !== false, "ID label should be there:\n" . $modelCode); $this->assertTrue(strpos($modelCode, "'id' => 'ID'") !== false, "ID label should be there:\n" . $modelCode);
$this->assertTrue(strpos($modelCode, "'description' => 'Description',") !== false, "Description label should be there:\n" . $modelCode); $this->assertTrue(strpos($modelCode, "'description' => 'Description',") !== false, "Description label should be there:\n" . $modelCode);
} else {
print_r($generator->getErrors());
}
} }
public function testModuleGenerator() public function testModuleGenerator()
...@@ -71,11 +69,10 @@ class GeneratorsTest extends GiiTestCase ...@@ -71,11 +69,10 @@ class GeneratorsTest extends GiiTestCase
$generator->moduleID = 'test'; $generator->moduleID = 'test';
$generator->moduleClass = 'app\modules\test\Module'; $generator->moduleClass = 'app\modules\test\Module';
if ($generator->validate()) { $valid = $generator->validate();
$generator->generate(); $this->assertTrue($valid, 'Validation failed: ' . print_r($generator->getErrors(), true));
} else {
print_r($generator->getErrors()); $this->assertNotEmpty($generator->generate());
}
} }
...@@ -87,11 +84,10 @@ class GeneratorsTest extends GiiTestCase ...@@ -87,11 +84,10 @@ class GeneratorsTest extends GiiTestCase
$generator->viewName = 'profile'; $generator->viewName = 'profile';
$generator->viewPath = '@yiiunit/runtime'; $generator->viewPath = '@yiiunit/runtime';
if ($generator->validate()) { $valid = $generator->validate();
$generator->generate(); $this->assertTrue($valid, 'Validation failed: ' . print_r($generator->getErrors(), true));
} else {
print_r($generator->getErrors()); $this->assertNotEmpty($generator->generate());
}
} }
public function testCRUDGenerator() public function testCRUDGenerator()
...@@ -101,10 +97,9 @@ class GeneratorsTest extends GiiTestCase ...@@ -101,10 +97,9 @@ class GeneratorsTest extends GiiTestCase
$generator->modelClass = 'yiiunit\extensions\gii\Profile'; $generator->modelClass = 'yiiunit\extensions\gii\Profile';
$generator->controllerClass = 'app\TestController'; $generator->controllerClass = 'app\TestController';
if ($generator->validate()) { $valid = $generator->validate();
$generator->generate(); $this->assertTrue($valid, 'Validation failed: ' . print_r($generator->getErrors(), true));
} else {
print_r($generator->getErrors()); $this->assertNotEmpty($generator->generate());
}
} }
} }
...@@ -9,6 +9,7 @@ Yii::setAlias('@yii/gii', __DIR__ . '/../../../../extensions/gii'); ...@@ -9,6 +9,7 @@ Yii::setAlias('@yii/gii', __DIR__ . '/../../../../extensions/gii');
/** /**
* GiiTestCase is the base class for all gii related test cases * GiiTestCase is the base class for all gii related test cases
* @group gii
*/ */
class GiiTestCase extends TestCase class GiiTestCase extends TestCase
{ {
......
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