Allowed Memory Size Exhausted


I have a database table and created a model for it using gii:


 * This is the model class for table "Subscriptions".


 * The followings are the available columns in table 'Subscriptions':

 * @property integer $ID

 * @property integer $ModuleID

 * @property integer $AfdelingID

 * @property string $SignUpDate

 * @property string $StartDate

 * @property string $CancelDate

 * @property string $EndDate

 * @property integer $State


 * The followings are the available model relations:

 * @property Afdelingen $afdeling

 * @property Detectoren $module


class TestSubscription extends CActiveRecord



	 * @return string the associated database table name


	public function tableName()


		return 'Subscriptions';



	 * @return array validation rules for model attributes.


	public function rules()


		// NOTE: you should only define rules for those attributes that

		// will receive user inputs.

		return array(

			array('AfdelingID, SignUpDate, State', 'required'),

			array('ModuleID, AfdelingID, State', 'numerical', 'integerOnly'=>true),

			array('StartDate, CancelDate, EndDate', 'safe'),

			// The following rule is used by search().

			// @todo Please remove those attributes that should not be searched.

			array('ID, ModuleID, AfdelingID, SignUpDate, StartDate, CancelDate, EndDate, State', 'safe', 'on'=>'search'),




	 * @return array relational rules.


	public function relations()


		// NOTE: you may need to adjust the relation name and the related

		// class name for the relations automatically generated below.

		return array(

			'afdeling' => array(self::BELONGS_TO, 'Afdelingen', 'AfdelingID'),

			'module' => array(self::BELONGS_TO, 'Detectoren', 'ModuleID'),




	 * @return array customized attribute labels (name=>label)


	public function attributeLabels()


		return array(

			'ID' => 'ID',

			'ModuleID' => 'Module',

			'AfdelingID' => 'Afdeling',

			'SignUpDate' => 'Sign Up Date',

			'StartDate' => 'Start Date',

			'CancelDate' => 'Cancel Date',

			'EndDate' => 'End Date',

			'State' => 'State',




	 * Retrieves a list of models based on the current search/filter conditions.


	 * Typical usecase:

	 * - Initialize the model fields with values from filter form.

	 * - Execute this method to get CActiveDataProvider instance which will filter

	 * models according to data in model fields.

	 * - Pass data provider to CGridView, CListView or any similar widget.


	 * @return CActiveDataProvider the data provider that can return the models

	 * based on the search/filter conditions.


	public function search()


		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;









		return new CActiveDataProvider($this, array(





	 * Returns the static model of the specified AR class.

	 * Please note that you should have this exact method in all your CActiveRecord descendants!

	 * @param string $className active record class name.

	 * @return TestSubscription the static model class


	public static function model($className=__CLASS__)


		return parent::model($className);



I build a super basic unit test:

class SubscriptionTest extends CTestCase


    function testCreate()


        echo "This is a test\n";

        $subscription= new TestSubscription();

        echo "Done\n";

        $this->assertTrue( true );



but when i run it in cmd using "PHPUnit ./unit/SubscriptionTest.php" i get the following result:

PHPUnit 3.7.21 by Sebastian Bergmann.

Configuration read from C:\xampp\htdocs\\protected\tests\phpunit.xml

This is a test

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes) in C:\xampp\htdocs\\framework\caching\CMemCache.php on line 116

I did not change anything in the model, it is straight from gii.

When i use any other model i created this way i have no problem at all, only with this model.

Anyone got an idea what this could be?


can you post the admin grid code?

may be this issue some data will be more then in filed (memory size of 134217728 by) so it’s display not so in admin grid view just remove the filter field on AfdelingID

I’m sorry i do not understand what you mean, but here is the admin grid code (It is straight from gii)

$this->widget('zii.widgets.grid.CGridView', array(




















On the web page it just works all fine, but i cannot create test for it.

Hey sorry can you post the _form.php code ?

In _form.php find

<label><?php echo GxHtml::encode($model->getRelationLabel

just commnet the line it’s solved

But i did not have the _form form file. I created it becasue you asked for the code, I have a problem during testing of my model. not on the actual web page itself

ok please see it.



i hope it’s some help.

Hmm… actually i already saw those pages and tried what they said… no luck. And they have problems with their complete site. I only have this problem with one model.

I removed CActiveRecord and now it does not crash…

class TestSubscription //extends CActiveRecord

does this mean this is a yii bug?

Is there maybe way to see memory usage?

Found it! :D

I use 2 version of the database. A test version and a released version.

I choose wich one to use by checking YII_DEBUG.

In my test i use the same config as the main, but apperently the YII_DEBUG is set to false during a test, so i was talking to the wrong datase.

I checked index-test.php and the YII_DEBUG was set to true, so i do not really get that yet.

But the error occured because the table did not exist in the released database and all the other tables did.

PHPUinit does not show this so i went to investigate and came to this part:


wich is in is part of the CDBCommand. this generated the error. I placed a try catch around it and echoed the exeption. this gave me the exact error : could not find table in database X. and database X was the wrong database.

I changed my config/test.php to use the right database and … voila! succesfull test…

So, one last question. Does anyone know why YII_DEBUG is false when using PHPUnit?