Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
64359373
Commit
64359373
authored
Nov 24, 2013
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added test case for #1310
parent
f017ba35
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
116 additions
and
4 deletions
+116
-4
Order.php
tests/unit/data/ar/Order.php
+16
-0
Order.php
tests/unit/data/ar/elasticsearch/Order.php
+16
-0
Order.php
tests/unit/data/ar/redis/Order.php
+16
-0
ActiveRecordTestTrait.php
tests/unit/framework/ar/ActiveRecordTestTrait.php
+68
-3
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+0
-1
No files found.
tests/unit/data/ar/Order.php
View file @
64359373
...
@@ -35,6 +35,22 @@ class Order extends ActiveRecord
...
@@ -35,6 +35,22 @@ class Order extends ActiveRecord
})
->
orderBy
(
'id'
);
})
->
orderBy
(
'id'
);
}
}
public
function
getItemsInOrder1
()
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
->
via
(
'orderItems'
,
function
(
$q
)
{
$q
->
orderBy
([
'subtotal'
=>
SORT_ASC
]);
})
->
orderBy
(
'name'
);
}
public
function
getItemsInOrder2
()
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
->
via
(
'orderItems'
,
function
(
$q
)
{
$q
->
orderBy
([
'subtotal'
=>
SORT_DESC
]);
})
->
orderBy
(
'name'
);
}
public
function
getBooks
()
public
function
getBooks
()
{
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
...
...
tests/unit/data/ar/elasticsearch/Order.php
View file @
64359373
...
@@ -33,6 +33,22 @@ class Order extends ActiveRecord
...
@@ -33,6 +33,22 @@ class Order extends ActiveRecord
->
via
(
'orderItems'
)
->
orderBy
(
'name'
);
->
via
(
'orderItems'
)
->
orderBy
(
'name'
);
}
}
public
function
getItemsInOrder1
()
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
->
via
(
'orderItems'
,
function
(
$q
)
{
$q
->
orderBy
([
'subtotal'
=>
SORT_ASC
]);
})
->
orderBy
(
'name'
);
}
public
function
getItemsInOrder2
()
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
->
via
(
'orderItems'
,
function
(
$q
)
{
$q
->
orderBy
([
'subtotal'
=>
SORT_DESC
]);
})
->
orderBy
(
'name'
);
}
// public function getBooks()
// public function getBooks()
// {
// {
// return $this->hasMany('Item', ['primaryKey' => 'item_id'])
// return $this->hasMany('Item', ['primaryKey' => 'item_id'])
...
...
tests/unit/data/ar/redis/Order.php
View file @
64359373
...
@@ -27,6 +27,22 @@ class Order extends ActiveRecord
...
@@ -27,6 +27,22 @@ class Order extends ActiveRecord
});
});
}
}
public
function
getItemsInOrder1
()
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
->
via
(
'orderItems'
,
function
(
$q
)
{
$q
->
orderBy
([
'subtotal'
=>
SORT_ASC
]);
})
->
orderBy
(
'name'
);
}
public
function
getItemsInOrder2
()
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
->
via
(
'orderItems'
,
function
(
$q
)
{
$q
->
orderBy
([
'subtotal'
=>
SORT_DESC
]);
})
->
orderBy
(
'name'
);
}
public
function
getBooks
()
public
function
getBooks
()
{
{
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
return
$this
->
hasMany
(
Item
::
className
(),
[
'id'
=>
'item_id'
])
...
...
tests/unit/framework/ar/ActiveRecordTestTrait.php
View file @
64359373
...
@@ -165,8 +165,8 @@ trait ActiveRecordTestTrait
...
@@ -165,8 +165,8 @@ trait ActiveRecordTestTrait
public
function
testFindColumn
()
public
function
testFindColumn
()
{
{
/** @var TestCase|ActiveRecordTestTrait $this */
/** @var TestCase|ActiveRecordTestTrait $this */
$this
->
assertEquals
([
'user1'
,
'user2'
,
'user3'
],
Customer
::
f
ind
()
->
column
(
'name'
));
$this
->
assertEquals
([
'user1'
,
'user2'
,
'user3'
],
$this
->
callCustomerF
ind
()
->
column
(
'name'
));
$this
->
assertEquals
([
'user3'
,
'user2'
,
'user1'
],
Customer
::
f
ind
()
->
orderBy
([
'name'
=>
SORT_DESC
])
->
column
(
'name'
));
$this
->
assertEquals
([
'user3'
,
'user2'
,
'user1'
],
$this
->
callCustomerF
ind
()
->
orderBy
([
'name'
=>
SORT_DESC
])
->
column
(
'name'
));
}
}
public
function
testfindIndexBy
()
public
function
testfindIndexBy
()
...
@@ -378,6 +378,7 @@ trait ActiveRecordTestTrait
...
@@ -378,6 +378,7 @@ trait ActiveRecordTestTrait
$this
->
assertEquals
(
3
,
count
(
$orders
));
$this
->
assertEquals
(
3
,
count
(
$orders
));
$order
=
$orders
[
0
];
$order
=
$orders
[
0
];
$this
->
assertEquals
(
1
,
$order
->
id
);
$this
->
assertEquals
(
1
,
$order
->
id
);
$this
->
assertTrue
(
$order
->
isRelationPopulated
(
'items'
));
$this
->
assertEquals
(
2
,
count
(
$order
->
items
));
$this
->
assertEquals
(
2
,
count
(
$order
->
items
));
$this
->
assertEquals
(
1
,
$order
->
items
[
0
]
->
id
);
$this
->
assertEquals
(
1
,
$order
->
items
[
0
]
->
id
);
$this
->
assertEquals
(
2
,
$order
->
items
[
1
]
->
id
);
$this
->
assertEquals
(
2
,
$order
->
items
[
1
]
->
id
);
...
@@ -388,14 +389,78 @@ trait ActiveRecordTestTrait
...
@@ -388,14 +389,78 @@ trait ActiveRecordTestTrait
/** @var TestCase|ActiveRecordTestTrait $this */
/** @var TestCase|ActiveRecordTestTrait $this */
$customers
=
$this
->
callCustomerFind
()
->
with
(
'orders'
,
'orders.items'
)
->
all
();
$customers
=
$this
->
callCustomerFind
()
->
with
(
'orders'
,
'orders.items'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$customers
));
$this
->
assertEquals
(
3
,
count
(
$customers
));
$this
->
assertTrue
(
$customers
[
0
]
->
isRelationPopulated
(
'orders'
));
$this
->
assertTrue
(
$customers
[
1
]
->
isRelationPopulated
(
'orders'
));
$this
->
assertTrue
(
$customers
[
2
]
->
isRelationPopulated
(
'orders'
));
$this
->
assertEquals
(
1
,
count
(
$customers
[
0
]
->
orders
));
$this
->
assertEquals
(
1
,
count
(
$customers
[
0
]
->
orders
));
$this
->
assertEquals
(
2
,
count
(
$customers
[
1
]
->
orders
));
// TODO check is populated
$this
->
assertEquals
(
2
,
count
(
$customers
[
1
]
->
orders
));
$this
->
assertEquals
(
0
,
count
(
$customers
[
2
]
->
orders
));
$this
->
assertEquals
(
0
,
count
(
$customers
[
2
]
->
orders
));
$this
->
assertTrue
(
$customers
[
0
]
->
orders
[
0
]
->
isRelationPopulated
(
'items'
));
$this
->
assertTrue
(
$customers
[
1
]
->
orders
[
0
]
->
isRelationPopulated
(
'items'
));
$this
->
assertTrue
(
$customers
[
1
]
->
orders
[
1
]
->
isRelationPopulated
(
'items'
));
$this
->
assertEquals
(
2
,
count
(
$customers
[
0
]
->
orders
[
0
]
->
items
));
$this
->
assertEquals
(
2
,
count
(
$customers
[
0
]
->
orders
[
0
]
->
items
));
$this
->
assertEquals
(
3
,
count
(
$customers
[
1
]
->
orders
[
0
]
->
items
));
$this
->
assertEquals
(
3
,
count
(
$customers
[
1
]
->
orders
[
0
]
->
items
));
$this
->
assertEquals
(
1
,
count
(
$customers
[
1
]
->
orders
[
1
]
->
items
));
$this
->
assertEquals
(
1
,
count
(
$customers
[
1
]
->
orders
[
1
]
->
items
));
}
}
/**
* Ensure ActiveRelation does preserve order of items on find via()
* https://github.com/yiisoft/yii2/issues/1310
*/
public
function
testFindEagerViaRelationPreserveOrder
()
{
/** @var TestCase|ActiveRecordTestTrait $this */
$orders
=
$this
->
callOrderFind
()
->
with
(
'itemsInOrder1'
)
->
orderBy
(
'create_time'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$order
=
$orders
[
0
];
$this
->
assertEquals
(
1
,
$order
->
id
);
$this
->
assertTrue
(
$order
->
isRelationPopulated
(
'itemsInOrder1'
));
$this
->
assertEquals
(
2
,
count
(
$order
->
itemsInOrder1
));
$this
->
assertEquals
(
1
,
$order
->
itemsInOrder1
[
0
]
->
id
);
$this
->
assertEquals
(
2
,
$order
->
itemsInOrder1
[
1
]
->
id
);
$order
=
$orders
[
1
];
$this
->
assertEquals
(
2
,
$order
->
id
);
$this
->
assertTrue
(
$order
->
isRelationPopulated
(
'itemsInOrder1'
));
$this
->
assertEquals
(
3
,
count
(
$order
->
itemsInOrder1
));
$this
->
assertEquals
(
5
,
$order
->
itemsInOrder1
[
0
]
->
id
);
$this
->
assertEquals
(
3
,
$order
->
itemsInOrder1
[
1
]
->
id
);
$this
->
assertEquals
(
4
,
$order
->
itemsInOrder1
[
2
]
->
id
);
$order
=
$orders
[
3
];
$this
->
assertEquals
(
3
,
$order
->
id
);
$this
->
assertTrue
(
$order
->
isRelationPopulated
(
'itemsInOrder1'
));
$this
->
assertEquals
(
0
,
count
(
$order
->
itemsInOrder1
));
}
// different order in via table
public
function
testFindEagerViaRelationPreserveOrderB
()
{
$orders
=
$this
->
callOrderFind
()
->
with
(
'itemsInOrder2'
)
->
orderBy
(
'create_time'
)
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
$order
=
$orders
[
0
];
$this
->
assertEquals
(
1
,
$order
->
id
);
$this
->
assertTrue
(
$order
->
isRelationPopulated
(
'itemsInOrder2'
));
$this
->
assertEquals
(
2
,
count
(
$order
->
itemsInOrder2
));
$this
->
assertEquals
(
1
,
$order
->
itemsInOrder2
[
0
]
->
id
);
$this
->
assertEquals
(
2
,
$order
->
itemsInOrder2
[
1
]
->
id
);
$order
=
$orders
[
1
];
$this
->
assertEquals
(
2
,
$order
->
id
);
$this
->
assertTrue
(
$order
->
isRelationPopulated
(
'itemsInOrder2'
));
$this
->
assertEquals
(
3
,
count
(
$order
->
itemsInOrder2
));
$this
->
assertEquals
(
5
,
$order
->
itemsInOrder2
[
0
]
->
id
);
$this
->
assertEquals
(
3
,
$order
->
itemsInOrder2
[
1
]
->
id
);
$this
->
assertEquals
(
4
,
$order
->
itemsInOrder2
[
2
]
->
id
);
$order
=
$orders
[
3
];
$this
->
assertEquals
(
3
,
$order
->
id
);
$this
->
assertTrue
(
$order
->
isRelationPopulated
(
'itemsInOrder2'
));
$this
->
assertEquals
(
0
,
count
(
$order
->
itemsInOrder2
));
}
public
function
testLink
()
public
function
testLink
()
{
{
$orderClass
=
$this
->
getOrderClass
();
$orderClass
=
$this
->
getOrderClass
();
...
...
tests/unit/framework/db/ActiveRecordTest.php
View file @
64359373
...
@@ -121,7 +121,6 @@ class ActiveRecordTest extends DatabaseTestCase
...
@@ -121,7 +121,6 @@ class ActiveRecordTest extends DatabaseTestCase
$this
->
assertEquals
(
2
,
$order
->
books
[
0
]
->
id
);
$this
->
assertEquals
(
2
,
$order
->
books
[
0
]
->
id
);
}
}
public
function
testStoreNull
()
public
function
testStoreNull
()
{
{
$record
=
new
NullValues
();
$record
=
new
NullValues
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment