PageRenderTime 63ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/test/testsuite/generator/behavior/aggregate_column/AggregateColumnBehaviorWithSchemaTest.php

https://github.com/mattleff/propel
PHP | 81 lines | 53 code | 13 blank | 15 comment | 0 complexity | 4c08979c948584f6c586a2af0a3c393d MD5 | raw file
  1. <?php
  2. /*
  3. * $Id: SoftDeleteBehaviorTest.php 1612 2010-03-16 22:56:21Z francois $
  4. * This file is part of the Propel package.
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. *
  8. * @license MIT License
  9. */
  10. require_once dirname(__FILE__) . '/../../../../tools/helpers/schemas/SchemasTestBase.php';
  11. /**
  12. * Tests for AggregateColumnBehavior class
  13. *
  14. * @author François Zaninotto
  15. * @version $Revision: 2092 $
  16. * @package generator.behavior.aggregate_column
  17. */
  18. class AggregateColumnBehaviorWithSchemaTest extends SchemasTestBase
  19. {
  20. protected function setUp()
  21. {
  22. parent::setUp();
  23. $this->con = Propel::getConnection(BookstoreSchemasBookstorePeer::DATABASE_NAME);
  24. $this->con->beginTransaction();
  25. }
  26. protected function tearDown()
  27. {
  28. $this->con->commit();
  29. parent::tearDown();
  30. }
  31. public function testParametersWithSchema()
  32. {
  33. $storeTable = BookstoreSchemasBookstorePeer::getTableMap();
  34. $this->assertEquals(count($storeTable->getColumns()), 8, 'AggregateColumn adds one column by default');
  35. $this->assertTrue(method_exists('BookstoreSchemasBookstore', 'getTotalContestEntries'));
  36. }
  37. public function testComputeWithSchema()
  38. {
  39. ContestBookstoreContestEntryQuery::create()->deleteAll($this->con);
  40. BookstoreSchemasBookstoreQuery::create()->deleteAll($this->con);
  41. BookstoreSchemasCustomerQuery::create()->deleteAll($this->con);
  42. ContestBookstoreContestQuery::create()->deleteAll($this->con);
  43. $store = new BookstoreSchemasBookstore();
  44. $store->save($this->con);
  45. $this->assertEquals(0, $store->computeTotalContestEntries($this->con), 'The compute method returns 0 for objects with no related objects');
  46. $contest = new ContestBookstoreContest();
  47. $contest->setBookstoreSchemasBookstore($store);
  48. $contest->save($this->con);
  49. $customer1 = new BookstoreSchemasCustomer();
  50. $customer1->save($this->con);
  51. $entry1 = new ContestBookstoreContestEntry();
  52. $entry1->setBookstoreSchemasBookstore($store);
  53. $entry1->setContestBookstoreContest($contest);
  54. $entry1->setBookstoreSchemasCustomer($customer1);
  55. $entry1->save($this->con, true); // skip reload to avoid #1151 for now
  56. $this->assertEquals(1, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects');
  57. $customer2 = new BookstoreSchemasCustomer();
  58. $customer2->save($this->con);
  59. $entry2 = new ContestBookstoreContestEntry();
  60. $entry2->setBookstoreSchemasBookstore($store);
  61. $entry2->setContestBookstoreContest($contest);
  62. $entry2->setBookstoreSchemasCustomer($customer2);
  63. $entry2->save($this->con, true); // skip reload to avoid #1151 for now
  64. $this->assertEquals(2, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects');
  65. $entry1->delete($this->con);
  66. $this->assertEquals(1, $store->computeTotalContestEntries($this->con), 'The compute method computes the aggregate function on related objects');
  67. }
  68. }