/
IntegerTypeTest.php
94 lines (73 loc) · 2.51 KB
/
IntegerTypeTest.php
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
<?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\Component\Form\Tests\Extension\Core\Type;
use Symfony\Component\Intl\Util\IntlTestHelper;
class IntegerTypeTest extends BaseTypeTest
{
const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\IntegerType';
protected function setUp()
{
IntlTestHelper::requireIntl($this, false);
parent::setUp();
}
public function testSubmitCastsToInteger()
{
$form = $this->factory->create(static::TESTED_TYPE);
$form->submit('1.678');
$this->assertSame(1, $form->getData());
$this->assertSame('1', $form->getViewData());
}
public function testSubmitNull($expected = null, $norm = null, $view = null)
{
parent::testSubmitNull($expected, $norm, '');
}
public function testSubmitNullUsesDefaultEmptyData($emptyData = '10', $expectedData = 10)
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'empty_data' => $emptyData,
]);
$form->submit(null);
$this->assertSame($emptyData, $form->getViewData());
$this->assertSame($expectedData, $form->getNormData());
$this->assertSame($expectedData, $form->getData());
}
public function testSubmittedLargeIntegersAreNotCastToFloat()
{
if (4 === \PHP_INT_SIZE) {
$this->markTestSkipped('This test requires a 64bit PHP.');
}
$form = $this->factory->create(static::TESTED_TYPE);
$form->submit('201803221011791');
$this->assertSame(201803221011791, $form->getData());
$this->assertSame('201803221011791', $form->getViewData());
}
public function testTooSmallIntegersAreNotValid()
{
if (4 === \PHP_INT_SIZE) {
$min = '-2147483649';
} else {
$min = '-9223372036854775808';
}
$form = $this->factory->create(static::TESTED_TYPE);
$form->submit($min);
$this->assertFalse($form->isSynchronized());
}
public function testTooGreatIntegersAreNotValid()
{
if (4 === \PHP_INT_SIZE) {
$max = '2147483648';
} else {
$max = '9223372036854775808';
}
$form = $this->factory->create(static::TESTED_TYPE);
$form->submit($max);
$this->assertFalse($form->isSynchronized());
}
}