This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
/
AggregateSchemaTest.php
70 lines (59 loc) · 2.34 KB
/
AggregateSchemaTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* Spiral, Core Components
*
* @author Wolfy-J
*/
namespace Spiral\Tests\ODM;
use Mockery as m;
use Spiral\ODM\Document;
use Spiral\ODM\Schemas\Definitions\AggregationDefinition;
use Spiral\Tests\ODM\Fixtures\BadAggregates;
use Spiral\Tests\ODM\Fixtures\DataPiece;
use Spiral\Tests\ODM\Fixtures\GoodAggregates;
use Spiral\Tests\ODM\Fixtures\User;
use Spiral\Tests\ODM\Traits\ODMTrait;
class AggregateSchemaTest extends \PHPUnit_Framework_TestCase
{
use ODMTrait;
/**
* @expectedException \Spiral\ODM\Exceptions\SchemaException
* @expectedExceptionMessage Aggregation Spiral\Tests\ODM\Fixtures\BadAggregates.'pieces'
* refers to undefined document 'Spiral\Tests\ODM\Fixtures\DataPiece'
*/
public function testBadAggregation()
{
$builder = $this->makeBuilder();
$builder->addSchema($this->makeSchema(BadAggregates::class));
$builder->packSchema();
}
/**
* @expectedException \Spiral\ODM\Exceptions\SchemaException
* @expectedExceptionMessage Aggregation Spiral\Tests\ODM\Fixtures\BadAggregates.'pieces'
* refers to non storable document
* 'Spiral\Tests\ODM\Fixtures\DataPiece'
*/
public function testAggregationToEmbedded()
{
$builder = $this->makeBuilder();
$builder->addSchema($this->makeSchema(BadAggregates::class));
$builder->addSchema($this->makeSchema(DataPiece::class));
$builder->packSchema();
}
public function testGoodAggregation()
{
$builder = $this->makeBuilder();
$builder->addSchema($aggregates = $this->makeSchema(GoodAggregates::class));
$builder->addSchema($this->makeSchema(User::class));
$this->assertCount(2, $aggregates->getAggregations());
$this->assertEquals([
'user' => new AggregationDefinition(Document::ONE, User::class,
['_id' => 'self::userId']),
'users' => new AggregationDefinition(Document::MANY, User::class, []),
], $aggregates->getAggregations());
$aggregation = $aggregates->getAggregations()['user'];
$this->assertSame(Document::ONE, $aggregation->getType());
$this->assertSame(User::class, $aggregation->getClass());
$this->assertSame(['_id' => 'self::userId'], $aggregation->getQuery());
}
}