Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional integer type support #199

Open
wants to merge 2 commits into
base: 2.13.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/book/sql-ddl.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,15 @@ Column (generic) | `$name = null`
Date | `$name`
DateTime | `$name`
Decimal | `$name`, `$precision`, `$scale = null`
Double | `$name`, `$digits`, `$decimal`
Float | `$name`, `$digits`, `$decimal` (Note: this class is deprecated as of 2.4.0; use Floating instead)
Floating | `$name`, `$digits`, `$decimal`
Integer | `$name`, `$nullable = false`, `default = null`, `array $options = array()`
SmallInteger | `$name`, `$nullable = false`, `$default = null`, `array $options = array()`
Text | `$name`, `$length`, `nullable = false`, `$default = null`, `array $options = array()`
Time | `$name`
Timestamp | `$name`
TinyInteger | `$name`, `$nullable = false`, `$default = null`, `array $options = array()`
Varbinary | `$name`, `$length`
Varchar | `$name`, `$length`

Expand Down
14 changes: 14 additions & 0 deletions src/Sql/Ddl/Column/Double.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Laminas\Db\Sql\Ddl\Column;

/**
* Column representing a DOUBLE type.
*/
class Double extends AbstractPrecisionColumn
{
/**
* @var string
*/
protected $type = 'DOUBLE';
}
11 changes: 11 additions & 0 deletions src/Sql/Ddl/Column/SmallInteger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Laminas\Db\Sql\Ddl\Column;

class SmallInteger extends Integer
{
/**
* @var string
*/
protected $type = 'SMALLINT';
}
11 changes: 11 additions & 0 deletions src/Sql/Ddl/Column/TinyInteger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Laminas\Db\Sql\Ddl\Column;

class TinyInteger extends Integer
{
/**
* @var string
*/
protected $type = 'TINYINT';
}
25 changes: 25 additions & 0 deletions test/unit/Sql/Ddl/Column/DoubleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace LaminasTest\Db\Sql\Ddl\Column;

use Laminas\Db\Sql\Ddl\Column\Double;
use PHPUnit\Framework\TestCase;

class DoubleTest extends TestCase
{
/**
* @covers \Laminas\Db\Sql\Ddl\Column\Double::getExpressionData
*/
public function testGetExpressionData()
{
$column = new Double('foo', 10, 5);
self::assertEquals(
[[
'%s %s NOT NULL',
['foo', 'DOUBLE(10,5)'],
[$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL],
]],
$column->getExpressionData()
);
}
}
30 changes: 30 additions & 0 deletions test/unit/Sql/Ddl/Column/SmallIntegerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace LaminasTest\Db\Sql\Ddl\Column;

use Laminas\Db\Sql\Ddl\Column\SmallInteger;
use PHPUnit\Framework\TestCase;

class SmallIntegerTest extends TestCase
{
/**
* @covers \Laminas\Db\Sql\Ddl\Column\SmallInteger::__construct
*/
public function testObjectConstruction()
{
$integer = new SmallInteger('foo');
self::assertEquals('foo', $integer->getName());
}

/**
* @covers \Laminas\Db\Sql\Ddl\Column\Column::getExpressionData
*/
public function testGetExpressionData()
{
$column = new SmallInteger('foo');
self::assertEquals(
[['%s %s NOT NULL', ['foo', 'SMALLINT'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]]],
$column->getExpressionData()
);
}
}
30 changes: 30 additions & 0 deletions test/unit/Sql/Ddl/Column/TinyIntegerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace LaminasTest\Db\Sql\Ddl\Column;

use Laminas\Db\Sql\Ddl\Column\TinyInteger;
use PHPUnit\Framework\TestCase;

class TinyIntegerTest extends TestCase
{
/**
* @covers \Laminas\Db\Sql\Ddl\Column\TinyInteger::__construct
*/
public function testObjectConstruction()
{
$integer = new TinyInteger('foo');
self::assertEquals('foo', $integer->getName());
}

/**
* @covers \Laminas\Db\Sql\Ddl\Column\Column::getExpressionData
*/
public function testGetExpressionData()
{
$column = new TinyInteger('foo');
self::assertEquals(
[['%s %s NOT NULL', ['foo', 'TINYINT'], [$column::TYPE_IDENTIFIER, $column::TYPE_LITERAL]]],
$column->getExpressionData()
);
}
}