Commit f017ba35 by Carsten Brandt

refactored unit tests. put common AR tests in trait

parent 983b2286
......@@ -1169,7 +1169,7 @@ class ActiveRecord extends Model
return false;
}
foreach ($this->attributes() as $name) {
$this->_attributes[$name] = $record->_attributes[$name];
$this->_attributes[$name] = isset($record->_attributes[$name]) ? $record->_attributes[$name] : null;
}
$this->_oldAttributes = $this->_attributes;
$this->_related = [];
......
......@@ -39,11 +39,7 @@ class ActiveRelation extends ActiveQuery implements ActiveRelationInterface
{
if ($this->primaryModel !== null) {
// lazy loading
if ($this->via instanceof ActiveRelationInterface) {
// via pivot table
$viaModels = $this->via->findPivotRows([$this->primaryModel]);
$this->filterByModels($viaModels);
} elseif (is_array($this->via)) {
if (is_array($this->via)) {
// via relation
/** @var ActiveRelation $viaQuery */
list($viaName, $viaQuery) = $this->via;
......
......@@ -73,13 +73,16 @@ class QueryBuilder extends \yii\base\Object
$parts['query'] = ["match_all" => (object)[]];
}
$options = [];
if ($query->timeout !== null) {
$options['timeout'] = $query->timeout;
}
return [
'queryParts' => $parts,
'index' => $query->index,
'type' => $query->type,
'options' => [
'timeout' => $query->timeout
],
'options' => $options,
];
}
......
<?php
namespace yiiunit\data\ar;
use yiiunit\framework\db\ActiveRecordTest;
/**
* Class Customer
*
......@@ -17,9 +19,6 @@ class Customer extends ActiveRecord
public $status2;
public static $afterSaveInsert = null;
public static $afterSaveNewRecord = null;
public static function tableName()
{
return 'tbl_customer';
......@@ -37,8 +36,8 @@ class Customer extends ActiveRecord
public function afterSave($insert)
{
static::$afterSaveInsert = $insert;
static::$afterSaveNewRecord = $this->isNewRecord;
ActiveRecordTest::$afterSaveInsert = $insert;
ActiveRecordTest::$afterSaveNewRecord = $this->isNewRecord;
parent::afterSave($insert);
}
}
<?php
namespace yiiunit\data\ar\elasticsearch;
use yiiunit\framework\elasticsearch\ActiveRecordTest;
/**
* Class Customer
*
......@@ -31,4 +33,11 @@ class Customer extends ActiveRecord
{
$query->andWhere(array('status' => 1));
}
public function afterSave($insert)
{
ActiveRecordTest::$afterSaveInsert = $insert;
ActiveRecordTest::$afterSaveNewRecord = $this->isNewRecord;
parent::afterSave($insert);
}
}
......@@ -2,6 +2,8 @@
namespace yiiunit\data\ar\redis;
use yiiunit\framework\redis\ActiveRecordTest;
class Customer extends ActiveRecord
{
const STATUS_ACTIVE = 1;
......@@ -26,4 +28,11 @@ class Customer extends ActiveRecord
{
$query->andWhere(['status' => 1]);
}
public function afterSave($insert)
{
ActiveRecordTest::$afterSaveInsert = $insert;
ActiveRecordTest::$afterSaveNewRecord = $this->isNewRecord;
parent::afterSave($insert);
}
}
\ No newline at end of file
......@@ -23,7 +23,7 @@ CREATE TABLE `tbl_constraints`
CREATE TABLE `tbl_customer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(128) NOT NULL,
`name` varchar(128) NOT NULL,
`name` varchar(128),
`address` string,
`status` int (11) DEFAULT 0,
PRIMARY KEY (`id`)
......
......@@ -9,7 +9,7 @@ IF OBJECT_ID('[dbo].[tbl_null_values]', 'U') IS NOT NULL DROP TABLE [dbo].[tbl_n
CREATE TABLE [dbo].[tbl_customer] (
[id] [int] IDENTITY(1,1) NOT NULL,
[email] [varchar](128) NOT NULL,
[name] [varchar](128) NOT NULL,
[name] [varchar](128),
[address] [text],
[status] [int] DEFAULT 0,
CONSTRAINT [PK_customer] PRIMARY KEY CLUSTERED (
......
......@@ -23,7 +23,7 @@ CREATE TABLE `tbl_constraints`
CREATE TABLE `tbl_customer` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(128) NOT NULL,
`name` varchar(128) NOT NULL,
`name` varchar(128),
`address` text,
`status` int (11) DEFAULT 0,
PRIMARY KEY (`id`)
......
......@@ -22,7 +22,7 @@ CREATE TABLE tbl_constraints
CREATE TABLE tbl_customer (
id serial not null primary key,
email varchar(128) NOT NULL,
name varchar(128) NOT NULL,
name varchar(128),
address text,
status integer DEFAULT 0
);
......
......@@ -15,7 +15,7 @@ DROP TABLE IF EXISTS tbl_null_values;
CREATE TABLE tbl_customer (
id INTEGER NOT NULL,
email varchar(128) NOT NULL,
name varchar(128) NOT NULL,
name varchar(128),
address text,
status INTEGER DEFAULT 0,
PRIMARY KEY (id)
......
......@@ -146,6 +146,9 @@ class QueryTest extends ElasticSearchTestCase
}
// TODO test facets
// TODO test complex where() every edge of QueryBuilder
public function testOrder()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment