gpt4 book ai didi

php - TYPO3 测试框架 - FunctionalTestCase 不从扩展加载 TCA 覆盖

转载 作者:行者123 更新时间:2023-12-04 14:55:34 34 4
gpt4 key购买 nike

如何在 FunctionalTestCase 类中应用 TCA 覆盖?

我正在为扩展 FrontendUser 域模型和存储库的扩展编写 TYPO3 功能测试。 TYPO3 测试框架用于运行测试,但它似乎没有从 Configuration/TCA/Overrides/fe_users.php 加载覆盖 TCA。文件。有没有Bootstrap我缺少的功能或者额外的设置? (出于 NDA 目的,< > 标签中的以下内容已被替换,例如内部扩展 key )

这是错误:


├ TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException: Unknown column 'gender' in 'field list'

╵ <extension-folder>/.Build/Web/typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php:146
╵ <extension-folder>/.Build/Web/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php:634
╵ <extension-folder>/.Build/Web/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php:282
╵ <extension-folder>/.Build/Web/typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php:269
╵ <extension-folder>/.Build/Web/typo3/sysext/extbase/Classes/Persistence/Generic/PersistenceManager.php:166
╵ <extension-folder>/Tests/Functional/Domain/Repository/FrontendUserRepositoryTest.php:96


这是功能测试类:

class FrontendUserRepositoryTest extends FunctionalTestCase
{

protected $testExtensionsToLoad = [
'typo3conf/ext/<my-extension-key>'
];

protected $coreExtensionsToLoad = [
'typo3/sysext/extbase'
];

/**
* @var FrontendUserRepository
*/
protected $frontendUserRepository;

/**
* @var PersistenceManager
*/
protected $persistenceManager;

/**
* @var FrontendUser
*/
protected $frontendUser;

/**
* @var string
*/
protected $email;

/**
* @var string
*/
protected $firstName;

/**
* @var string
*/
protected $lastName;

protected function setUp(): void
{
parent::setUp();

Bootstrap::initializeBackendUser();
$GLOBALS['BE_USER']->user['admin'] = 1;
$GLOBALS['BE_USER']->user['uid'] = 1;
$GLOBALS['BE_USER']->workspace = 0;
Bootstrap::initializeLanguageObject();

/** @var PersistenceManager $persistenceManager */
$this->persistenceManager = GeneralUtility::makeInstance(PersistenceManager::class);

$objectContainer = new Container($this->getContainer());
$objectManager = new ObjectManager($this->getContainer(), $objectContainer);
$this->frontendUserRepository = new FrontendUserRepository($objectManager);
$this->frontendUserRepository->injectPersistenceManager($this->persistenceManager);


$this->email = 'test@test.com';
$this->firstName = 'Tester';
$this->lastName = 'Man';

$this->frontendUser = GeneralUtility::makeInstance(FrontendUser::class);
$this->frontendUser->setEmail($this->email);
$this->frontendUser->setFirstName($this->firstName);
$this->frontendUser->setLastName($this->lastName);
}

/**
* @test
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
*/
public function testRetrieveByEmailFromRepository()
{
$this->frontendUserRepository->add($this->frontendUser);
$this->persistenceManager->persistAll();

/** @var FrontendUser $frontendUser */
$frontendUser = $this->frontendUserRepository->findUserByEmail($this->email)->getFirst();
$this->assertEquals($this->email, $frontendUser->getEmail());
$this->assertEquals($this->firstName, $frontendUser->getFirstName());
$this->assertEquals($this->lastName, $frontendUser->getLastName());
}

/**
* @test
*/
public function checkIfTableExists()
{
$queryBuilder = $this->getConnectionPool()->getQueryBuilderForTable('INFORMATION_SCHEMA.COLUMNS');
$queryBuilder->getRestrictions()->removeAll();
$query = $queryBuilder->select('COLUMN_NAME')
->from('INFORMATION_SCHEMA.COLUMNS')
->where(
$queryBuilder->expr()->eq('TABLE_NAME', $queryBuilder->createNamedParameter('fe_users'))
)
->execute();

/* Dumps the base fe_users table columns without the TCA overrides applied */
var_dump($query->fetchAllAssociative());
}

}

最佳答案

我通过在 ext_tables.sql 文件中显式定义缺失的列来解决这个问题,但这不是必需的,因为扩展在没有定义这个的情况下工作:

CREATE TABLE fe_users (
gender tinyint DEFAULT 0 NOT NULL,
status tinyint DEFAULT 0 NOT NULL,
privacy tinyint(1) DEFAULT false NOT NULL,
--etc. etc.
);

如果有人能告诉我将 TCA 覆盖保存到数据库表的位置,将不胜感激。

关于php - TYPO3 测试框架 - FunctionalTestCase 不从扩展加载 TCA 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68097802/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com