propel /test/testsuite/generator/builder/om/GeneratedObjectEnumColumnTypeTest.php

Language PHP Lines 118
MD5 Hash 1e4b9ec99fdec622ba81477173ac4c0c
Repository https://github.com/mattleff/propel.git View Raw File View Project SPDX
  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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?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
 */

require_once 'PHPUnit/Framework.php';
require_once dirname(__FILE__) . '/../../../../../generator/lib/util/PropelQuickBuilder.php';
require_once dirname(__FILE__) . '/../../../../../runtime/lib/Propel.php';

/**
 * Tests the generated objects for enum column types accessor & mutator
 *
 * @author     Francois Zaninotto
 * @package    generator.builder.om
 */
class GeneratedObjectEnumColumnTypeTest extends PHPUnit_Framework_TestCase
{
	public function setUp()
	{
		if (!class_exists('ComplexColumnTypeEntity3')) {
			$schema = <<<EOF
<database name="generated_object_complex_type_test_3">
	<table name="complex_column_type_entity_3">
		<column name="id" primaryKey="true" type="INTEGER" autoIncrement="true" />
		<column name="bar" type="ENUM" valueSet="foo, bar, baz, 1, 4,(, foo bar " />
		<column name="bar2" type="ENUM" valueSet="foo, bar" defaultValue="bar" />
	</table>
</database>
EOF;
			PropelQuickBuilder::buildSchema($schema);
			// ok this is hackish but it makes testing of getter and setter independent of each other
			$publicAccessorCode = <<<EOF
class PublicComplexColumnTypeEntity3 extends ComplexColumnTypeEntity3
{
	public \$bar;
}
EOF;
			eval($publicAccessorCode);
		}
	}
	
	public function testGetter()
	{
		$this->assertTrue(method_exists('ComplexColumnTypeEntity3', 'getBar'));
		$e = new ComplexColumnTypeEntity3();
		$this->assertNull($e->getBar());
		$e = new PublicComplexColumnTypeEntity3();
		$e->bar = 0;
		$this->assertEquals('foo', $e->getBar());
		$e->bar = 3;
		$this->assertEquals('1', $e->getBar());
		$e->bar = 6;
		$this->assertEquals('foo bar', $e->getBar());
	}

	/**
	 * @expectedException PropelException
	 */
	public function testGetterThrowsExceptionOnUnknownKey()
	{
		$e = new PublicComplexColumnTypeEntity3();
		$e->bar = 156;
		$e->getBar();
	}
	
	public function testGetterDefaultValue()
	{
		$e = new PublicComplexColumnTypeEntity3();
		$this->assertEquals('bar', $e->getBar2());
	}

	public function testSetter()
	{
		$this->assertTrue(method_exists('ComplexColumnTypeEntity3', 'setBar'));
		$e = new PublicComplexColumnTypeEntity3();
		$e->setBar('foo');
		$this->assertEquals(0, $e->bar);
		$e->setBar(1);
		$this->assertEquals(3, $e->bar);
		$e->setBar('1');
		$this->assertEquals(3, $e->bar);
		$e->setBar('foo bar');
		$this->assertEquals(6, $e->bar);
	}
	
	/**
	 * @expectedException PropelException
	 */
	public function testSetterThrowsExceptionOnUnknownValue()
	{
		$e = new ComplexColumnTypeEntity3();
		$e->setBar('bazz');
	}
	
	public function testValueIsPersisted()
	{
		$e = new ComplexColumnTypeEntity3();
		$e->setBar('baz');
		$e->save();
		ComplexColumnTypeEntity3Peer::clearInstancePool();
		$e = ComplexColumnTypeEntity3Query::create()->findOne();
		$this->assertEquals('baz', $e->getBar());
	}
	
	public function testValueIsCopied()
	{
		$e1 = new ComplexColumnTypeEntity3();
		$e1->setBar('baz');
		$e2 = new ComplexColumnTypeEntity3();
		$e1->copyInto($e2);
		$this->assertEquals('baz', $e2->getBar());
	}
}
Back to Top