Configuring Gii and test CRUD
2012-05-02 16:28
281 查看
2012.5.3
>>>Configuring Gii and test CRUD<<<
1. Edit protected/config/main.php,去掉下列语句的注释
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'[add_your_password_here]',
),
2. visit: http://localhost/yii/power/index.php?r=gii
3. select "Model Generator"
enter:
pwr_ for Table Prefix
pwr_user for Table Name
and others are created automatically.
click "Preview" button to view the source code of Usr.php
click "Generate" to create the real file.
4. Creating the unit test file protected/tests/unit/UserTest.php
<?php
class UserTest extends CDbTestCase
{
public function testCRUD()
{
//Create a new User
$newUser=new User;
$newUserName = 'tuser1';
$newUser->setAttributes(
array(
'user_id' => $newUserName,
'user_pwd' => 'tuser1',
)
);
//insert new user record to database
$this->assertTrue($newUser->save(false));
//READ back the newly created project
$retrievedUser=User::model()->findByPk($newUser->user_id);
$this->assertTrue($retrievedUser instanceof User);
$this->assertEquals($newUserName,$retrievedUser->user_id);
//UPDATE the newly created user
$updatedUserName = 'utser1';
$newUser->user_id = $updatedUserName;
$this->assertTrue($newUser->save(false));
//read back the record again to ensure the update worked
$updatedUser=User::model()->findByPk($newUser->user_id);
$this->assertTrue($updatedUser instanceof User);
$this->assertEquals($updatedUserName,$updatedUser->user_id);
//DELETE the user
//$newUserId = $newUser->user_id;
//$this->assertTrue($newUser->delete());
//$deletedUser=User::model()->findByPk($newUserId);
//$this->assertEquals(NULL,$deletedUser);
}
}
5. 执行
C:\xampp\yii\power\protected\tests> phpunit unit/UserTest.php
>>>Configuring Gii and test CRUD<<<
1. Edit protected/config/main.php,去掉下列语句的注释
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'[add_your_password_here]',
),
2. visit: http://localhost/yii/power/index.php?r=gii
3. select "Model Generator"
enter:
pwr_ for Table Prefix
pwr_user for Table Name
and others are created automatically.
click "Preview" button to view the source code of Usr.php
click "Generate" to create the real file.
4. Creating the unit test file protected/tests/unit/UserTest.php
<?php
class UserTest extends CDbTestCase
{
public function testCRUD()
{
//Create a new User
$newUser=new User;
$newUserName = 'tuser1';
$newUser->setAttributes(
array(
'user_id' => $newUserName,
'user_pwd' => 'tuser1',
)
);
//insert new user record to database
$this->assertTrue($newUser->save(false));
//READ back the newly created project
$retrievedUser=User::model()->findByPk($newUser->user_id);
$this->assertTrue($retrievedUser instanceof User);
$this->assertEquals($newUserName,$retrievedUser->user_id);
//UPDATE the newly created user
$updatedUserName = 'utser1';
$newUser->user_id = $updatedUserName;
$this->assertTrue($newUser->save(false));
//read back the record again to ensure the update worked
$updatedUser=User::model()->findByPk($newUser->user_id);
$this->assertTrue($updatedUser instanceof User);
$this->assertEquals($updatedUserName,$updatedUser->user_id);
//DELETE the user
//$newUserId = $newUser->user_id;
//$this->assertTrue($newUser->delete());
//$deletedUser=User::model()->findByPk($newUserId);
//$this->assertEquals(NULL,$deletedUser);
}
}
5. 执行
C:\xampp\yii\power\protected\tests> phpunit unit/UserTest.php
相关文章推荐
- Configuring and Controlling the Management Server
- Yii2用Gii自动生成Module+Model+CRUD
- Junit and android test
- C# - test and cast with reference type or value...
- How to set up and test a simple OLEDB Linked Server in Microsoft® SQL Server to allow retrieval of d
- Yii 通过Gii实现CRUD与生成module
- Install and test nginx on Ubuntu 14.04
- Codeforces Round #419 (Div. 2) D - Karen and Test(规律 杨辉三角)
- Yii Framework 配置 MySql并通过GII实现CRUD
- Test-Driven C# Improve the Design and Flexibility of Your Project with Extreme Programming Techniques
- Cocos2d-x2.0 之 ClickAndMoveTest “谈不上深入”的分析.
- Installing and Configuring Workflow Manager 1.0
- What is the purpose of @SmallTest, @MediumTest, and @LargeTest annotations in Android?
- Battle test(Locust and Apache Bench)
- Obtaining, Configuring and Building unixODBC
- Active MQ non-persistent Message Performance and Reliability Test
- What is the difference between test, [ and [[ ?
- Problem C. Watson and Intervals Google APAC 2017 University Test Round B
- Installing and Configuring a MySQL Database
- Installing and Configuring Fedora KVM Virtualization