PageRenderTime 19ms CodeModel.GetById 17ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

/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/**
 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
11require_once dirname(__FILE__) . '/../../../tools/helpers/bookstore/BookstoreEmptyTestBase.php';
12
13/**
14 * Test class for PropelObjectFormatter.
15 *
16 * @author     Francois Zaninotto
17 * @version    $Id$
18 * @package    runtime.formatter
19 */
20class PropelFormatterTest extends BookstoreEmptyTestBase
21{
22    protected function setUp()
23    {
24        parent::setUp();
25        BookstoreDataPopulator::populate();
26    }
27
28    public function testGetWorkerObjectReturnsRightClass()
29    {
30        $formatter = $this->getMockForAbstractClass('PropelFormatter');
31
32        $method = new ReflectionMethod('PropelFormatter', 'getWorkerObject');
33        $method->setAccessible(true);
34
35        $classNames = array(
36            'Bookstore',
37            'BookReader',
38            'BookClubList',
39        );
40
41        $col = 0;
42        foreach ($classNames as $className) {
43            // getWorkerObject() should always return an instance of the requested class, regardless of the value of $col
44            $result = $method->invoke($formatter, $col, $className);
45
46            $this->assertEquals($className, get_class($result), 'getWorkerObject did not return an instance of the requested class');
47        }
48    }
49
50    public function testGetWorkerObjectCachedInstance()
51    {
52        $formatter = $this->getMockForAbstractClass('PropelFormatter');
53
54        $method = new ReflectionMethod('PropelFormatter', 'getWorkerObject');
55        $method->setAccessible(true);
56
57        $className = 'Bookstore';
58        $col = 0;
59
60        $result1 = $method->invoke($formatter, $col, $className);
61        $result2 = $method->invoke($formatter, $col, $className);
62
63        $this->assertEquals(spl_object_hash($result1), spl_object_hash($result2), 'getWorkerObject should return a cached instance of a class at the same col index');
64    }
65}