Adds asArray() method to the base Model that's used as proxy for
Idiorm's as_array()
This commit is contained in:
@ -170,6 +170,10 @@ class Model extends \Sudzy\ValidModel {
|
|||||||
return static::whereNotNull('deleted_at');
|
return static::whereNotNull('deleted_at');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function asArray() {
|
||||||
|
return call_user_func_array('parent::as_array', func_get_args());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rethrow PDOExceptions to prevent exposing sensitive data in stack traces
|
* Rethrow PDOExceptions to prevent exposing sensitive data in stack traces
|
||||||
*/
|
*/
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Codeception\Util\Stub;
|
use Codeception\Util\Stub;
|
||||||
use MailPoet\Models\Model;
|
|
||||||
|
|
||||||
class ModelTest extends MailPoetTest {
|
class ModelTest extends MailPoetTest {
|
||||||
function testItRethrowsPDOExceptions() {
|
function testItRethrowsPDOExceptions() {
|
||||||
@ -23,7 +22,26 @@ class ModelTest extends MailPoetTest {
|
|||||||
expect($e instanceof \PDOException)->false();
|
expect($e instanceof \PDOException)->false();
|
||||||
expect($e->getMessage())->equals($message);
|
expect($e->getMessage())->equals($message);
|
||||||
}
|
}
|
||||||
// Remove the DB stub
|
}
|
||||||
|
|
||||||
|
function testItConvertsModelObjectToArray() {
|
||||||
|
$model = Model::create();
|
||||||
|
$model->first = 'first';
|
||||||
|
$model->last = 'last';
|
||||||
|
expect($model->asArray('first'))->equals(
|
||||||
|
array(
|
||||||
|
'first' => 'first'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
expect($model->asArray('last', 'first'))->equals(
|
||||||
|
array(
|
||||||
|
'last' => 'last',
|
||||||
|
'first' => 'first'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
\ORM::setDb(null);
|
\ORM::setDb(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user