Get model attribute after save

Dear Experts,

I am writing yii application with test driven development.

Somehow I save an account. The account model has encrypt password implementation which I encrypt the password and save to encrypted_password attribute.

Now, I need to test the encrypted_password attribute after save. How can I do that?

Below is my test methods:

public function testEncryptedPasswordAttributeExist(){

    	$account = new Account;



    	return $account;




     * @depends testEncryptedPasswordAttributeExist


    public function testEncryptedPasswordShouldNotBeBlank(Account $account){


    	echo $account->encrypted_password;

    	$this->assertTrue($account->getAttribute('encrypted_password') != '');


Below is my model implementation in which I think is correct:

	public function onBeforeSave(){





	public function validatePassword($password)


        return $this->hashPassword($password, $this->salt)===$this->password;



    public function hashPassword($password,$salt)


        return md5($salt.$password);



    private function encrypt_password($password){

    	$this->encrypted_password = encrpyt_password($password);



    private function encrpyt_password($password){

    	return $password;





Hi Cato,

this doesn’t look right to me?

Can you explain?


Problem solved.