Adds asArray() method to the base Model that's used as proxy for

Idiorm's as_array()
This commit is contained in:
Vlad
2017-07-15 14:25:50 -04:00
parent 74cb8d9735
commit a4dad46fb7
2 changed files with 25 additions and 3 deletions

View File

@ -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
*/ */

View File

@ -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);
} }
} }