Skip to content
Permalink
Browse files

Migrating ModelBehaviorTest to phpunit

  • Loading branch information...
lorenzo committed Jun 5, 2010
1 parent d573be1 commit 94dd8a2543282e256eb912032da142a0e413fa51
Showing with 13 additions and 14 deletions.
  1. +13 −14 cake/tests/cases/libs/model/model_behavior.test.php
@@ -22,8 +22,6 @@
App::import('Model', 'AppModel');
require_once dirname(__FILE__) . DS . 'models.php';
Mock::generatePartial('BehaviorCollection', 'MockModelBehaviorCollection', array('cakeError', '_stop'));
/**
* TestBehavior class
*
@@ -213,7 +211,7 @@ function beforeValidate(&$model) {
* @return void
*/
function beforeDelete(&$model, $cascade = true) {
$settings =& $this->settings[$model->alias];
$settings = $this->settings[$model->alias];
if (!isset($settings['beforeDelete']) || $settings['beforeDelete'] == 'off') {
return parent::beforeDelete($model, $cascade);
}
@@ -241,7 +239,7 @@ function beforeDelete(&$model, $cascade = true) {
* @return void
*/
function afterDelete(&$model) {
$settings =& $this->settings[$model->alias];
$settings = $this->settings[$model->alias];
if (!isset($settings['afterDelete']) || $settings['afterDelete'] == 'off') {
return parent::afterDelete($model);
}
@@ -286,7 +284,7 @@ function beforeTest(&$model) {
* @access public
* @return void
*/
function testMethod(&$model, $param = true) {
function testMethod(Model $model, $param = true) {
if ($param === true) {
return 'working';
}
@@ -299,7 +297,7 @@ function testMethod(&$model, $param = true) {
* @access public
* @return void
*/
function testData(&$model) {
function testData(Model $model) {
if (!isset($model->data['Apple']['field'])) {
return false;
}
@@ -315,7 +313,7 @@ function testData(&$model) {
* @access public
* @return void
*/
function validateField(&$model, $field) {
function validateField(Model $model, $field) {
return current($field) === 'Orange';
}
@@ -328,7 +326,7 @@ function validateField(&$model, $field) {
* @access public
* @return void
*/
function speakEnglish(&$model, $method, $query) {
function speakEnglish(Model $model, $method, $query) {
$method = preg_replace('/look for\s+/', 'Item.name = \'', $method);
$query = preg_replace('/^in\s+/', 'Location.name = \'', $query);
return $method . '\' AND ' . $query . '\'';
@@ -532,10 +530,11 @@ function testDetachWithPluginNames() {
* @return void
*/
function testInvalidBehaviorCausingCakeError() {
$Apple =& new Apple();
$Apple->Behaviors =& new MockModelBehaviorCollection();
$Apple->Behaviors->expectOnce('cakeError');
$Apple->Behaviors->expectAt(0, 'cakeError', array('missingBehaviorFile', '*'));
$Apple = new Apple();
$Apple->Behaviors = $this->getMock('BehaviorCollection', array('cakeError'));
$Apple->Behaviors->expects($this->once())
->method('cakeError')
->with('missingBehaviorFile');
$this->assertFalse($Apple->Behaviors->attach('NoSuchBehavior'));
}
@@ -1051,7 +1050,7 @@ function testBehaviorMethodDispatchingWithData() {
* @return void
*/
function testBehaviorTrigger() {
$Apple =& new Apple();
$Apple = new Apple();
$Apple->Behaviors->attach('Test');
$Apple->Behaviors->attach('Test2');
$Apple->Behaviors->attach('Test3');
@@ -1126,7 +1125,7 @@ public function testBindModelCallsInBehaviors() {
* @return void
*/
function testBehaviorAttachAndDetach() {
$Sample =& new Sample();
$Sample = new Sample();
$Sample->actsAs = array('Test3' => array('bar'), 'Test2' => array('foo', 'bar'));
$Sample->Behaviors->init($Sample->alias, $Sample->actsAs);
$Sample->Behaviors->attach('Test2');

0 comments on commit 94dd8a2

Please sign in to comment.
You can’t perform that action at this time.