|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * This file is part of the FreshDoctrineEnumBundle |
| 4 | + * |
| 5 | + * (c) Artem Genvald <genvaldartem@gmail.com> |
| 6 | + * |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + */ |
| 10 | +namespace Fresh\Bundle\DoctrineEnumBundle\Tests\DBAL\Types; |
| 11 | + |
| 12 | +use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 13 | +use Doctrine\DBAL\Platforms\MySqlPlatform; |
| 14 | +use Doctrine\DBAL\Platforms\SqlitePlatform; |
| 15 | + |
| 16 | +/** |
| 17 | + * AbstractEnumTypeTest |
| 18 | + * |
| 19 | + * @author Ben Davies <ben.davies@gmail.com> |
| 20 | + * |
| 21 | + * @coversDefaultClass \Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType |
| 22 | + */ |
| 23 | +class AbstractEnumTypeTest extends \PHPUnit_Framework_TestCase |
| 24 | +{ |
| 25 | + /** |
| 26 | + * @var \Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType |
| 27 | + */ |
| 28 | + private $type; |
| 29 | + |
| 30 | + /** |
| 31 | + * Set up EnumType |
| 32 | + */ |
| 33 | + public function setUp() |
| 34 | + { |
| 35 | + $this->type = $this->getMockBuilder('Fresh\Bundle\DoctrineEnumBundle\DBAL\Types\AbstractEnumType') |
| 36 | + ->disableOriginalConstructor() |
| 37 | + ->setMethods(array('getValues')) |
| 38 | + ->getMockForAbstractClass(); |
| 39 | + |
| 40 | + $this->type->staticExpects($this->any()) |
| 41 | + ->method('getValues') |
| 42 | + ->will($this->returnValue(array('M', 'F'))); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Test that the SQL declaration is the correct for the platform |
| 47 | + * |
| 48 | + * @param array $fieldDeclaration The Field Declaration |
| 49 | + * @param AbstractPlatform $platform The DBAL Platform |
| 50 | + * @param string $expected Expected Sql Declaration |
| 51 | + * |
| 52 | + * @test |
| 53 | + * @covers ::getSqlDeclaration |
| 54 | + * @dataProvider platformProvider |
| 55 | + */ |
| 56 | + public function getSqlDeclaration(array $fieldDeclaration, AbstractPlatform $platform, $expected) |
| 57 | + { |
| 58 | + $this->assertEquals($expected, $this->type->getSqlDeclaration($fieldDeclaration, $platform)); |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @return array |
| 63 | + */ |
| 64 | + public function platformProvider() |
| 65 | + { |
| 66 | + return array( |
| 67 | + array(array('name' => 'sex'), new MySqlPlatform(), "ENUM('M', 'F')"), |
| 68 | + array(array('name' => 'sex'), new SqlitePlatform(), "TEXT CHECK(sex IN ('M', 'F'))") |
| 69 | + ); |
| 70 | + } |
| 71 | +} |
0 commit comments