Skip to content

Commit 63f15a5

Browse files
committed
truncate test
check whether doctrine mysql orm silently truncates string value
1 parent ccfc97c commit 63f15a5

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\Models\Truncate;
6+
7+
use Doctrine\ORM\Mapping as ORM;
8+
9+
/**
10+
* @ORM\Entity()
11+
* @ORM\Table(name="truncate")
12+
*/
13+
class Truncate
14+
{
15+
/**
16+
* @ORM\Id()
17+
* @ORM\Column(type="integer")
18+
* @ORM\GeneratedValue()
19+
*
20+
* @var int
21+
*/
22+
private $id;
23+
24+
public function getId(): int
25+
{
26+
return $this->id;
27+
}
28+
29+
/**
30+
* @ORM\Column(type="string", length=25)
31+
*/
32+
private $test;
33+
34+
public function setTest(string $test): void
35+
{
36+
$this->test = $test;
37+
}
38+
39+
public function getTest(): string
40+
{
41+
return $this->test;
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\Tests\ORM\Functional\Ticket\Truncate;
6+
7+
use Doctrine\DBAL\Platforms\MySQLPlatform;
8+
use Doctrine\Tests\OrmFunctionalTestCase;
9+
use Doctrine\Tests\Models\Truncate\Truncate;
10+
11+
class TruncateTest extends OrmFunctionalTestCase
12+
{
13+
protected function setUp(): void
14+
{
15+
parent::setUp();
16+
17+
if (! $this->_em->getConnection()->getDatabasePlatform() instanceof MySQLPlatform) {
18+
self::markTestSkipped('The ' . self::class . ' requires the use of mysql.');
19+
20+
return;
21+
}
22+
23+
$this->createSchemaForModels(
24+
Truncate::class
25+
);
26+
}
27+
28+
public function testSilentlyTruncatingValue(): void
29+
{
30+
$qwerty = 'qwertyuiopasdfghjklzxcvbnm';
31+
32+
$model = new Truncate();
33+
$model->setTest($qwerty);
34+
35+
$this->_em->persist($model);
36+
$this->_em->flush();
37+
$this->_em->clear();
38+
39+
$fresh = $this->_em->find(Truncate::class, $model->getId());
40+
41+
self::assertSame($qwerty, $fresh->getTest());
42+
}
43+
}

0 commit comments

Comments
 (0)