/test/testsuite/runtime/formatter/PropelFormatterTest.php

http://github.com/propelorm/Propel · PHP · 65 lines · 37 code · 13 blank · 15 comment · 0 complexity · ba7ca853568a5fec691e31f5e6f7c75b MD5 · raw file

  1. <?php
  2. /**
  3. * This file is part of the Propel package.
  4. * For the full copyright and license information, please view the LICENSE
  5. * file that was distributed with this source code.
  6. *
  7. * @license MIT License
  8. */
  9. require_once dirname(__FILE__) . '/../../../tools/helpers/bookstore/BookstoreEmptyTestBase.php';
  10. /**
  11. * Test class for PropelObjectFormatter.
  12. *
  13. * @author Francois Zaninotto
  14. * @version $Id$
  15. * @package runtime.formatter
  16. */
  17. class PropelFormatterTest extends BookstoreEmptyTestBase
  18. {
  19. protected function setUp()
  20. {
  21. parent::setUp();
  22. BookstoreDataPopulator::populate();
  23. }
  24. public function testGetWorkerObjectReturnsRightClass()
  25. {
  26. $formatter = $this->getMockForAbstractClass('PropelFormatter');
  27. $method = new ReflectionMethod('PropelFormatter', 'getWorkerObject');
  28. $method->setAccessible(true);
  29. $classNames = array(
  30. 'Bookstore',
  31. 'BookReader',
  32. 'BookClubList',
  33. );
  34. $col = 0;
  35. foreach ($classNames as $className) {
  36. // getWorkerObject() should always return an instance of the requested class, regardless of the value of $col
  37. $result = $method->invoke($formatter, $col, $className);
  38. $this->assertEquals($className, get_class($result), 'getWorkerObject did not return an instance of the requested class');
  39. }
  40. }
  41. public function testGetWorkerObjectCachedInstance()
  42. {
  43. $formatter = $this->getMockForAbstractClass('PropelFormatter');
  44. $method = new ReflectionMethod('PropelFormatter', 'getWorkerObject');
  45. $method->setAccessible(true);
  46. $className = 'Bookstore';
  47. $col = 0;
  48. $result1 = $method->invoke($formatter, $col, $className);
  49. $result2 = $method->invoke($formatter, $col, $className);
  50. $this->assertEquals(spl_object_hash($result1), spl_object_hash($result2), 'getWorkerObject should return a cached instance of a class at the same col index');
  51. }
  52. }