|
5 | 5 | use Illuminate\Database\Eloquent\Builder; |
6 | 6 | use Illuminate\Support\Collection; |
7 | 7 | use Illuminate\Support\Facades\DB; |
| 8 | +use InvalidArgumentException; |
8 | 9 | use MongoDB\Laravel\Tests\Eloquent\Models\EloquentWithAggregateModel1; |
9 | 10 | use MongoDB\Laravel\Tests\Eloquent\Models\EloquentWithAggregateModel2; |
10 | 11 | use MongoDB\Laravel\Tests\Eloquent\Models\EloquentWithAggregateModel3; |
@@ -116,36 +117,16 @@ public function testWithAggregateFiltered() |
116 | 117 |
|
117 | 118 | public function testWithAggregateEmbedFiltered() |
118 | 119 | { |
119 | | - self::markTestSkipped('EmbedsMany does not support filtering. $filter requires an expression but the Query Builder generates query predicates.'); |
120 | | - |
121 | | - EloquentWithAggregateModel1::create(['id' => 1]); |
122 | | - $one = EloquentWithAggregateModel1::create(['id' => 2]); |
123 | | - $one->embeddeds()->create(['value' => 4]); |
124 | | - $one->embeddeds()->create(['value' => 6]); |
125 | | - $one->embeddeds()->create(['value' => 8]); |
| 120 | + EloquentWithAggregateModel1::create(['id' => 2]); |
126 | 121 | $filter = static function (Builder $query) { |
127 | 122 | $query->where('value', '<=', 6); |
128 | 123 | }; |
129 | 124 |
|
130 | | - $results = EloquentWithAggregateModel1::withCount(['embeddeds' => $filter])->where('id', 2); |
131 | | - self::assertSameResults([ |
132 | | - ['id' => 2, 'embeddeds_count' => 2], |
133 | | - ], $results->get()); |
134 | | - |
135 | | - $results = EloquentWithAggregateModel1::withMax(['embeddeds' => $filter], 'value')->where('id', 2); |
136 | | - self::assertSameResults([ |
137 | | - ['id' => 2, 'embeddeds_max' => 6], |
138 | | - ], $results->get()); |
139 | | - |
140 | | - $results = EloquentWithAggregateModel1::withMin(['embeddeds' => $filter], 'value')->where('id', 2); |
141 | | - self::assertSameResults([ |
142 | | - ['id' => 2, 'embeddeds_min' => 4], |
143 | | - ], $results->get()); |
| 125 | + // @see https://jira.mongodb.org/browse/PHPORM-292 |
| 126 | + self::expectException(InvalidArgumentException::class); |
| 127 | + self::expectExceptionMessage('Constraints are not supported for embedded relations'); |
144 | 128 |
|
145 | | - $results = EloquentWithAggregateModel1::withAvg(['embeddeds' => $filter], 'value')->where('id', 2); |
146 | | - self::assertSameResults([ |
147 | | - ['id' => 2, 'embeddeds_avg' => 5.0], |
148 | | - ], $results->get()); |
| 129 | + EloquentWithAggregateModel1::withCount(['embeddeds' => $filter])->where('id', 2)->get(); |
149 | 130 | } |
150 | 131 |
|
151 | 132 | public function testWithAggregateMultipleResults() |
@@ -248,6 +229,17 @@ public function testGlobalScopes() |
248 | 229 | self::assertSame(1, $result->all_fours_count); |
249 | 230 | } |
250 | 231 |
|
| 232 | + public function testHybridNotSupported() |
| 233 | + { |
| 234 | + EloquentWithAggregateModel1::create(['id' => 2]); |
| 235 | + |
| 236 | + // @see https://jira.mongodb.org/browse/PHPORM-292 |
| 237 | + self::expectException(InvalidArgumentException::class); |
| 238 | + self::expectExceptionMessage('WithAggregate does not support hybrid relations'); |
| 239 | + |
| 240 | + EloquentWithAggregateModel1::withCount('hybrids')->where('id', 2)->get(); |
| 241 | + } |
| 242 | + |
251 | 243 | private static function assertSameResults(array $expected, Collection $collection) |
252 | 244 | { |
253 | 245 | $actual = $collection->toArray(); |
|
0 commit comments