-
Notifications
You must be signed in to change notification settings - Fork 397
/
AggregateColumnBehaviorWithSchemaTest.php
93 lines (77 loc) · 3.39 KB
/
AggregateColumnBehaviorWithSchemaTest.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* This file is part of the Propel package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/
namespace Propel\Tests\Generator\Behavior\AggregateColumn;
use Propel\Tests\BookstoreSchemas\Bookstore;
use Propel\Tests\BookstoreSchemas\BookstoreContest;
use Propel\Tests\BookstoreSchemas\BookstoreContestEntry;
use Propel\Tests\BookstoreSchemas\BookstoreContestEntryQuery;
use Propel\Tests\BookstoreSchemas\BookstoreContestQuery;
use Propel\Tests\BookstoreSchemas\BookstoreQuery;
use Propel\Tests\BookstoreSchemas\BookstorePeer;
use Propel\Tests\BookstoreSchemas\Customer;
use Propel\Tests\BookstoreSchemas\CustomerQuery;
use Propel\Tests\Helpers\Schemas\SchemasTestBase;
use Propel\Runtime\Propel;
/**
* Tests for AggregateColumnBehavior class
*
* @author François Zaninotto
*/
class AggregateColumnBehaviorWithSchemaTest extends SchemasTestBase
{
protected function setUp()
{
parent::setUp();
$this->con = Propel::getServiceContainer()->getConnection(BookstorePeer::DATABASE_NAME);
$this->con->beginTransaction();
}
protected function tearDown()
{
$this->con->commit();
parent::tearDown();
}
public function testParametersWithSchema()
{
$storeTable = BookstorePeer::getTableMap();
$this->assertEquals(count($storeTable->getColumns()), 8, 'AggregateColumn adds one column by default');
$this->assertTrue(method_exists('Propel\Tests\BookstoreSchemas\Bookstore', 'getTotalContestEntries'));
}
public function testComputeWithSchema()
{
BookstoreContestEntryQuery::create()->deleteAll($this->con);
BookstoreQuery::create()->deleteAll($this->con);
CustomerQuery::create()->deleteAll($this->con);
BookstoreContestQuery::create()->deleteAll($this->con);
$store = new Bookstore();
$store->setStoreName('FreeAgent Bookstore');
$store->save($this->con);
$this->assertEquals(0, $store->computeTotalContestEntries($this->con), 'The compute method returns 0 for objects with no related objects');
$contest = new BookstoreContest();
$contest->setBookstore($store);
$contest->save($this->con);
$customer1 = new Customer();
$customer1->save($this->con);
$entry1 = new BookstoreContestEntry();
$entry1->setBookstore($store);
$entry1->setBookstoreContest($contest);
$entry1->setCustomer($customer1);
$entry1->save($this->con, true); // skip reload to avoid #1151 for now
$this->assertEquals(1, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects');
$customer2 = new Customer();
$customer2->save($this->con);
$entry2 = new BookstoreContestEntry();
$entry2->setBookstore($store);
$entry2->setBookstoreContest($contest);
$entry2->setCustomer($customer2);
$entry2->save($this->con, true); // skip reload to avoid #1151 for now
$this->assertEquals(2, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects');
$entry1->delete($this->con);
$this->assertEquals(1, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects');
}
}