Skip to content

Commit 4988b71

Browse files
PKuhlmayclaude
andcommitted
[BUGFIX] Fix #785: Change SelectProperty type from int to string
TYPO3 type=select fields store values as varchar(255), but the generated PHP model used int type and int(11) SQL — causing a type mismatch in the backend and runtime errors when select items have string values. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5d7137e commit 4988b71

4 files changed

Lines changed: 70 additions & 9 deletions

File tree

Classes/Domain/Model/DomainObject/SelectProperty.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@ class SelectProperty extends AbstractProperty
2222
/**
2323
* the property's default value
2424
*
25-
* @var int
25+
* @var string
2626
*/
27-
protected $defaultValue = 0;
27+
protected $defaultValue = '';
2828

2929
public function getTypeForComment(): string
3030
{
31-
return 'int';
31+
return 'string';
3232
}
3333

3434
public function getTypeHint(): string
3535
{
36-
return 'int';
36+
return 'string';
3737
}
3838

3939
public function getSqlDefinition(): string
4040
{
41-
return $this->getFieldName() . " int(11) DEFAULT '0' NOT NULL,";
41+
return $this->getFieldName() . " varchar(255) NOT NULL DEFAULT '',";
4242
}
4343
}

Tests/Functional/FileGenerator/Property/GeneratedPropertyTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -920,13 +920,13 @@ public function writeModelClassWithSelectProperty(): void
920920
$classFileContent = $this->fileGenerator->generateDomainObjectCode($domainObject);
921921

922922
self::assertMatchesRegularExpression(
923-
'/.*\* @var int.*/',
923+
'/.*\* @var string.*/',
924924
$classFileContent,
925925
'var tag for select property was not generated'
926926
);
927927

928928
self::assertMatchesRegularExpression(
929-
'/.*protected \\$color = 0;.*/',
929+
"/.*protected \\\$color = '';.*/",
930930
$classFileContent,
931931
'select property was not generated'
932932
);
@@ -937,7 +937,7 @@ public function writeModelClassWithSelectProperty(): void
937937
'Getter for select property was not generated'
938938
);
939939
self::assertMatchesRegularExpression(
940-
'/.*public function setColor\(int \$color\).*/',
940+
'/.*public function setColor\(string \$color\).*/',
941941
$classFileContent,
942942
'Setter for select property was not generated'
943943
);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the TYPO3 CMS project.
7+
*
8+
* It is free software; you can redistribute it and/or modify it under
9+
* the terms of the GNU General Public License, either version 2
10+
* of the License, or any later version.
11+
*
12+
* For the full copyright and license information, please read the
13+
* LICENSE.txt file that was distributed with this source code.
14+
*
15+
* The TYPO3 project - inspiring people to share!
16+
*/
17+
18+
namespace EBT\ExtensionBuilder\Tests\Unit\Domain\Model\DomainObject;
19+
20+
use EBT\ExtensionBuilder\Domain\Model\DomainObject\SelectProperty;
21+
use EBT\ExtensionBuilder\Tests\BaseUnitTest;
22+
23+
/**
24+
* Select properties are stored as varchar(255) in TYPO3, consistent with
25+
* the TCA type=select schema and the fact that item values can be strings.
26+
*/
27+
class SelectPropertySqlTest extends BaseUnitTest
28+
{
29+
/**
30+
* @test
31+
*/
32+
public function selectPropertyReturnsVarcharSqlDefinition(): void
33+
{
34+
$property = new SelectProperty();
35+
$property->setName('status');
36+
$property->setDomainObject($this->buildDomainObject('TestModel'));
37+
38+
self::assertSame(
39+
"status varchar(255) NOT NULL DEFAULT '',",
40+
$property->getSqlDefinition()
41+
);
42+
}
43+
44+
/**
45+
* @test
46+
*/
47+
public function selectPropertyTypeForCommentIsString(): void
48+
{
49+
$property = new SelectProperty();
50+
self::assertSame('string', $property->getTypeForComment());
51+
}
52+
53+
/**
54+
* @test
55+
*/
56+
public function selectPropertyTypeHintIsString(): void
57+
{
58+
$property = new SelectProperty();
59+
self::assertSame('string', $property->getTypeHint());
60+
}
61+
}

Tests/Unit/Service/ClassBuilderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public static function propertyDefaultTypesProviderTypes(): array
195195
'nativeDateTime' => ['nativeDateTime', null],
196196
'password' => ['password', ''],
197197
'richText' => ['richText', ''],
198-
'select' => ['select', 0],
198+
'select' => ['select', ''],
199199
'string' => ['string', ''],
200200
'text' => ['text', ''],
201201
'nativeTime' => ['nativeTime', null],

0 commit comments

Comments
 (0)