[Propel1] Added tests for the PropelTypeGuesser
This commit is contained in:
parent
cffcdc933f
commit
897a389ffe
59
src/Symfony/Bridge/Propel1/Tests/Fixtures/Column.php
Normal file
59
src/Symfony/Bridge/Propel1/Tests/Fixtures/Column.php
Normal file
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Propel1\Tests\Fixtures;
|
||||
|
||||
class Column
|
||||
{
|
||||
private $name;
|
||||
|
||||
private $type;
|
||||
|
||||
public function __construct($name, $type)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function isText()
|
||||
{
|
||||
if (!$this->type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($this->type) {
|
||||
case \PropelColumnTypes::CHAR:
|
||||
case \PropelColumnTypes::VARCHAR:
|
||||
case \PropelColumnTypes::LONGVARCHAR:
|
||||
case \PropelColumnTypes::BLOB:
|
||||
case \PropelColumnTypes::CLOB:
|
||||
case \PropelColumnTypes::CLOB_EMU:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
return $this->isText() ? 255 : 0;
|
||||
}
|
||||
|
||||
public function isNotNull()
|
||||
{
|
||||
return ('id' === $this->name);
|
||||
}
|
||||
}
|
@ -21,11 +21,14 @@ class Item implements \Persistent
|
||||
|
||||
private $groupName;
|
||||
|
||||
public function __construct($id = null, $value = null, $groupName = null)
|
||||
private $price;
|
||||
|
||||
public function __construct($id = null, $value = null, $groupName = null, $price = null)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->value = $value;
|
||||
$this->groupName = $groupName;
|
||||
$this->price = $price;
|
||||
}
|
||||
|
||||
public function getId()
|
||||
@ -48,6 +51,11 @@ class Item implements \Persistent
|
||||
return $this->groupName;
|
||||
}
|
||||
|
||||
public function getPrice()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
public function getPrimaryKey()
|
||||
{
|
||||
return $this->getId();
|
||||
|
@ -13,6 +13,12 @@ namespace Symfony\Bridge\Propel1\Tests\Fixtures;
|
||||
|
||||
class ItemQuery
|
||||
{
|
||||
private $map = array(
|
||||
'id' => \PropelColumnTypes::INTEGER,
|
||||
'value' => \PropelColumnTypes::VARCHAR,
|
||||
'price' => \PropelColumnTypes::FLOAT,
|
||||
);
|
||||
|
||||
public function getTableMap()
|
||||
{
|
||||
// Allows to define methods in this class
|
||||
@ -24,4 +30,24 @@ class ItemQuery
|
||||
{
|
||||
return array('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Method from the TableMap API
|
||||
*/
|
||||
public function hasColumn($column)
|
||||
{
|
||||
return in_array($column, array_keys($this->map));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method from the TableMap API
|
||||
*/
|
||||
public function getColumn($column)
|
||||
{
|
||||
if ($this->hasColumn($column)) {
|
||||
return new Column($column, $this->map[$column]);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Bridge\Propel1\Tests\Form;
|
||||
|
||||
use Symfony\Bridge\Propel1\Form\PropelTypeGuesser;
|
||||
use Symfony\Bridge\Propel1\Tests\Propel1TestCase;
|
||||
|
||||
class PropelTypeGuesserTest extends Propel1TestCase
|
||||
{
|
||||
const CLASS_NAME = 'Symfony\Bridge\Propel1\Tests\Fixtures\Item';
|
||||
|
||||
private $guesser;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->guesser = new PropelTypeGuesser();
|
||||
}
|
||||
|
||||
public function testGuessMaxLengthWithText()
|
||||
{
|
||||
$value = $this->guesser->guessMaxLength(self::CLASS_NAME, 'value');
|
||||
|
||||
$this->assertNotNull($value);
|
||||
$this->assertEquals(255, $value->getValue());
|
||||
}
|
||||
|
||||
public function testGuessMaxLengthWithFloat()
|
||||
{
|
||||
$value = $this->guesser->guessMaxLength(self::CLASS_NAME, 'price');
|
||||
|
||||
$this->assertNotNull($value);
|
||||
$this->assertNull($value->getValue());
|
||||
}
|
||||
|
||||
public function testGuessMinLengthWithText()
|
||||
{
|
||||
$value = $this->guesser->guessMinLength(self::CLASS_NAME, 'value');
|
||||
|
||||
$this->assertNull($value);
|
||||
}
|
||||
|
||||
public function testGuessMinLengthWithFloat()
|
||||
{
|
||||
$value = $this->guesser->guessMinLength(self::CLASS_NAME, 'price');
|
||||
|
||||
$this->assertNotNull($value);
|
||||
$this->assertNull($value->getValue());
|
||||
}
|
||||
|
||||
public function testGuessRequired()
|
||||
{
|
||||
$value = $this->guesser->guessRequired(self::CLASS_NAME, 'id');
|
||||
|
||||
$this->assertNotNull($value);
|
||||
$this->assertTrue($value->getValue());
|
||||
}
|
||||
|
||||
public function testGuessRequiredWithNullableColumn()
|
||||
{
|
||||
$value = $this->guesser->guessRequired(self::CLASS_NAME, 'value');
|
||||
|
||||
$this->assertNotNull($value);
|
||||
$this->assertFalse($value->getValue());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user