mirror of https://github.com/FriendsOfTYPO3/tea.git synced 2024-11-24 13:16:13 +01:00

Compare commits

...

22 commits

Author SHA1 Message Date
Karsten Nowak
5bd5b3bf8d
Merge 055a2f07bc into 161196288a 2024-11-14 16:23:15 +05:30
dependabot[bot]
161196288a
[TASK][Dependabot] Update spaze/phpstan-disallowed-calls requirement (#1513)
Updates the requirements on [spaze/phpstan-disallowed-calls](https://github.com/spaze/phpstan-disallowed-calls) to permit the latest version.
- [Release notes](https://github.com/spaze/phpstan-disallowed-calls/releases)
- [Commits](https://github.com/spaze/phpstan-disallowed-calls/compare/v3.5.1...v4.0.1)

---
updated-dependencies:
- dependency-name: spaze/phpstan-disallowed-calls
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-14 05:22:25 +00:00
dependabot[bot]
45056facaa
[TASK][Dependabot] Update squizlabs/php_codesniffer requirement (#1512)
Updates the requirements on [squizlabs/php_codesniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer) to permit the latest version.
- [Release notes](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases)
- [Changelog](https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/CHANGELOG.md)
- [Commits](https://github.com/PHPCSStandards/PHP_CodeSniffer/compare/3.10.3...3.11.0)

---
updated-dependencies:
- dependency-name: squizlabs/php_codesniffer
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-13 06:03:17 +00:00
dependabot[bot]
de096dac50
[TASK][Dependabot] Update phpstan/phpstan requirement (#1511)
Updates the requirements on [phpstan/phpstan](https://github.com/phpstan/phpstan) to permit the latest version.
- [Release notes](https://github.com/phpstan/phpstan/releases)
- [Changelog](https://github.com/phpstan/phpstan/blob/2.0.x/CHANGELOG.md)
- [Commits](https://github.com/phpstan/phpstan/compare/1.12.8...1.12.9)

---
updated-dependencies:
- dependency-name: phpstan/phpstan
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-11-10 18:13:18 +00:00
Karsten Nowak
055a2f07bc [BUGFIX] Fix error with spread operator in php 7.4
In php 7.4 error occured:
`Cannot unpack array with string keys`

Related #1120
2024-10-20 11:49:44 +02:00
Karsten Nowak
bf7ade8f98 [BUGFIX] Fix some php stan errors
Related #1120
2024-10-20 11:49:44 +02:00
Karsten Nowak
f86b37df41 [TASK] Remove unused imports
Related #1120
2024-10-20 11:49:44 +02:00
Karsten Nowak
a1cf83ccbc [TASK] Rename test functions
Related #1120
2024-10-20 11:49:44 +02:00
Karsten Nowak
a4ba103993 [TASK] Check that existing teas in other pids were not deleted
Related #1120
2024-10-20 11:49:44 +02:00
13b1116532 Fix broken functional test
SQLite does reset the UID autoincrement during deletion.
That way the assertions do not match.
We now use a different set up and remove the uids from assertions.

That way we still ensure that the imported data is removed and new data
is imported. We do not need to care about UID.
2024-10-20 11:49:44 +02:00
Karsten Nowak
271bd24c4f [TASK] Add functional test for createTestDataCommand
Related #1120
2024-10-20 11:49:44 +02:00
Karsten Nowak
1af328f27b [TASK] Remove unnecessary is_int check of pageUid
Related #1120
2024-10-20 11:49:44 +02:00
Karsten Nowak
e3544f4ade [TASK] Update reference index after changing test data
Related #1120
2024-10-20 11:49:44 +02:00
Karsten Nowak
18b804f179 [TASK] use assert to state data restrictions
Related #1120
2024-10-20 11:49:44 +02:00
Karsten Nowak
d1420a21b3 [TASK] Rename pageId to pageUid
Related #1120
2024-10-20 11:49:44 +02:00
Karsten Nowak
8200302d31 [TASK] Move comment directly above the class
Related #1120
2024-10-20 11:49:44 +02:00
Karsten Nowak
dd1f4832ff Update Classes/Command/CreateTestDataCommand.php
Co-authored-by: Oliver Klee <typo3-coding@oliverklee.de>
2024-10-20 11:49:44 +02:00
Karsten Nowak
5ad2d2d8ad Update Classes/Command/CreateTestDataCommand.php
Co-authored-by: Oliver Klee <typo3-coding@oliverklee.de>
2024-10-20 11:49:43 +02:00
Karsten Nowak
72d449b9bd [BUGFIX] Fix errors from php cs fixer
Related: #1120
2024-10-20 11:49:43 +02:00
Karsten Nowak
277a167621 [DOCS] Add documentation part for command controller
Related: #1120
2024-10-20 11:49:43 +02:00
Karsten Nowak
cc64515cd6 [TASK] Remove phpDocumentor reflection type
Related: #1120
2024-10-20 11:49:43 +02:00
Karsten Nowak
b42f6ed08e [FEATURE] Add command controller to create test data
Related: #11120
2024-10-20 11:49:43 +02:00
12 changed files with 278 additions and 3 deletions

View file

@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
namespace TTN\Tea\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\ReferenceIndex;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/*
* Command to create test data for the tea extension.
*/
final class CreateTestDataCommand extends Command
{
/**
* @var list<array{title: non-empty-string, description: non-empty-string, sys_language_uid: int<0, max>}>
*/
protected array $teaData = [
[
'title' => 'Darjeeling',
'description' => 'I love that tea!',
'sys_language_uid' => 0,
],
[
'title' => 'Earl Grey',
'description' => 'A nice tea!',
'sys_language_uid' => 0,
],
];
protected function configure(): void
{
$this
->setHelp('Create test data for the tea extension in an already existing page (sysfolder).')
->addArgument(
'pageUid',
InputArgument::REQUIRED,
'Existing sysfolder page id.'
)
->addOption(
'delete-data-before',
'd',
InputOption::VALUE_NONE,
'Delete all tea data in the defined pid before creating new data.'
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$pageUid = $input->getArgument('pageUid') ?? 0;
\assert(\is_int($pageUid));
$deleteDataBefore = $input->getOption('delete-data-before') ?? false;
\assert(\is_bool($deleteDataBefore));
$table = 'tx_tea_domain_model_tea';
$connectionForTable = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
if ($deleteDataBefore) {
$query = $connectionForTable;
$query->delete($table, ['pid' => $pageUid], [Connection::PARAM_INT]);
$output->writeln(sprintf('Existing data in page %s deleted.', $pageUid));
}
$query = $connectionForTable;
foreach ($this->teaData as $item) {
$item = ['pid' => $pageUid, 'title' => $item['title'], 'description' => $item['description']];
$query->insert(
$table,
$item
);
}
$output->writeln(sprintf('Test data in page %s created.', $pageUid));
$referenceIndex = GeneralUtility::makeInstance(ReferenceIndex::class);
$referenceIndex->updateIndex(false);
$output->writeln('Reference index updated.');
return Command::SUCCESS;
}
}

View file

@ -4,6 +4,8 @@ declare(strict_types=1);
namespace Symfony\Component\DependencyInjection\Loader\Configurator; namespace Symfony\Component\DependencyInjection\Loader\Configurator;
use TTN\Tea\Command\CreateTestDataCommand;
return static function (ContainerConfigurator $containerConfigurator) { return static function (ContainerConfigurator $containerConfigurator) {
$services = $containerConfigurator->services() $services = $containerConfigurator->services()
->defaults() ->defaults()
@ -12,4 +14,13 @@ return static function (ContainerConfigurator $containerConfigurator) {
$services->load('TTN\\Tea\\', '../Classes/*') $services->load('TTN\\Tea\\', '../Classes/*')
->exclude('../Classes/Domain/Model/*'); ->exclude('../Classes/Domain/Model/*');
$services->set(CreateTestDataCommand::class)
->tag(
'console.command',
[
'command' => 'tea:createtestdata',
'description' => 'Create test data in existing sysfolder',
]
);
}; };

View file

@ -0,0 +1,28 @@
.. include:: /Includes.rst.txt
.. _command-controller:
==================
Command Controller
==================
The "tea" extension comes with a CommandController that can be used for the
automatic creation of test data. It also serves to illustrate how data can be
created in the database using a command controller.
You must set a page id as argument. Therefore it's necessary to create an
sysfolder before.
You can add option `-d` to delete already existing data.
.. code-block:: bash
vendor/bin/typo3 tea:createtestdata 3
.. seealso::
For further details to Console Commands read the
:ref:`Creating a basic command <t3coreapi:console-command-tutorial-create>`
tutorial.

View file

@ -47,6 +47,7 @@ continuous integration.
ReleaseBranchingStrategy ReleaseBranchingStrategy
Environment Environment
DependencyManager DependencyManager
CommandController
Running Running
ContinuousIntegration ContinuousIntegration
Documentation Documentation

View file

@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
namespace TTN\Tea\Tests\Functional\Command;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;
use TTN\Tea\Command\CreateTestDataCommand;
use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
/**
* @covers \TTN\Tea\Command\CreateTestDataCommand
*/
class CreateTestDataCommandTest extends FunctionalTestCase
{
private const COMMAND_NAME = 'tea:createtestdata';
protected array $testExtensionsToLoad = ['ttn/tea'];
private CreateTestDataCommand $subject;
private CommandTester $commandTester;
protected function setUp(): void
{
parent::setUp();
$this->importCSVDataSet(__DIR__ . '/Fixtures/Database/Pages.csv');
$this->subject = new CreateTestDataCommand(self::COMMAND_NAME);
$application = new Application();
$application->add($this->subject);
$command = $application->find('tea:createtestdata');
$this->commandTester = new CommandTester($command);
}
/**
* @test
*/
public function isConsoleCommand(): void
{
self::assertInstanceOf(Command::class, $this->subject);
}
/**
* @test
*/
public function hasDescription(): void
{
$expected = 'Create test data for the tea extension in an already existing page (sysfolder).';
self::assertSame($expected, $this->subject->getHelp());
}
/**
* @test
*/
public function hasHelpText(): void
{
$expected = 'Create test data for the tea extension in an already existing page (sysfolder).';
self::assertSame($expected, $this->subject->getHelp());
}
/**
* @test
*/
public function runReturnsSuccessStatus(): void
{
$result = $this->commandTester->execute(
[
'pageUid' => '1',
],
);
self::assertSame(Command::SUCCESS, $result);
}
/**
* @test
*/
public function createsTestData(): void
{
$this->commandTester->execute([
'pageUid' => '1',
]);
self::assertCSVDataSet(__DIR__ . '/Fixtures/Database/Teas.csv');
}
/**
* @test
*/
public function deletesExistingDataOnGivenPidBeforeCreatingNewData(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/Database/ExistingTeas.csv');
$this->commandTester->execute(
[
'pageUid' => '1',
'--delete-data-before' => true,
]
);
self::assertCSVDataSet(__DIR__ . '/Fixtures/Database/TeasAfterDelete.csv');
}
/**
* @test
*/
public function doesNotDeleteDataOnOtherPid(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/Database/OtherExistingTeas.csv');
$this->commandTester->execute(
[
'pageUid' => '1',
'--delete-data-before' => true,
]
);
self::assertCSVDataSet(__DIR__ . '/Fixtures/Database/TeasAfterDeleteOtherExistingTeas.csv');
}
}

View file

@ -0,0 +1,4 @@
"tx_tea_domain_model_tea"
,"uid","pid","title","description","deleted"
,1,1,"Darjeeling","Which already existed in the system",0
,2,1,"Earl Grey","Which already existed in the system",0
Can't render this file because it has a wrong number of fields in line 2.

View file

@ -0,0 +1,6 @@
"tx_tea_domain_model_tea"
,"uid","pid","title","description","deleted"
,3,1,"Darjeeling","Exists and should be deleted","0"
,4,1,"Earl Grey","Exists and should be deleted","0"
,1,2,"Darjeeling","Which already existed in the system",0
,2,2,"Earl Grey","Which already existed in the system",0
Can't render this file because it has a wrong number of fields in line 2.

View file

@ -0,0 +1,4 @@
"pages",,,,,,,,,
,"uid","pid","sorting","deleted","t3_origuid","title",,,
,1,0,256,0,0,"Tea data",,,
,2,0,512,0,0,"Other tea data",,,
1 pages
2 uid pid sorting deleted t3_origuid title
3 1 0 256 0 0 Tea data
4 2 0 512 0 0 Other tea data

View file

@ -0,0 +1,4 @@
"tx_tea_domain_model_tea"
,"uid","pid","title","description","deleted"
,1,1,"Darjeeling","I love that tea!",0
,2,1,"Earl Grey","A nice tea!",0
Can't render this file because it has a wrong number of fields in line 2.

View file

@ -0,0 +1,4 @@
"tx_tea_domain_model_tea"
,"pid","title","description","deleted"
,1,"Darjeeling","I love that tea!",0
,1,"Earl Grey","A nice tea!",0
Can't render this file because it has a wrong number of fields in line 2.

View file

@ -0,0 +1,6 @@
"tx_tea_domain_model_tea"
,"pid","title","description","deleted"
,1,"Darjeeling","I love that tea!",0
,1,"Earl Grey","A nice tea!",0
,2,"Darjeeling","Which already existed in the system",0
,2,"Earl Grey","Which already existed in the system",0
Can't render this file because it has a wrong number of fields in line 2.

View file

@ -54,14 +54,14 @@
"php-parallel-lint/php-parallel-lint": "1.4.0", "php-parallel-lint/php-parallel-lint": "1.4.0",
"phpmd/phpmd": "2.15.0", "phpmd/phpmd": "2.15.0",
"phpstan/extension-installer": "1.4.3", "phpstan/extension-installer": "1.4.3",
"phpstan/phpstan": "1.12.8", "phpstan/phpstan": "1.12.9",
"phpstan/phpstan-phpunit": "1.4.0", "phpstan/phpstan-phpunit": "1.4.0",
"phpstan/phpstan-strict-rules": "1.6.1", "phpstan/phpstan-strict-rules": "1.6.1",
"phpunit/phpunit": "9.6.20", "phpunit/phpunit": "9.6.20",
"saschaegerer/phpstan-typo3": "1.10.2", "saschaegerer/phpstan-typo3": "1.10.2",
"seld/jsonlint": "1.11.0", "seld/jsonlint": "1.11.0",
"spaze/phpstan-disallowed-calls": "3.5.1", "spaze/phpstan-disallowed-calls": "4.0.1",
"squizlabs/php_codesniffer": "3.10.3", "squizlabs/php_codesniffer": "3.11.0",
"ssch/typo3-rector": "2.11.0", "ssch/typo3-rector": "2.11.0",
"ssch/typo3-rector-testing-framework": "2.0.1", "ssch/typo3-rector-testing-framework": "2.0.1",
"symfony/console": "^5.4.44 || ^6.4.12 || ^7.1.5", "symfony/console": "^5.4.44 || ^6.4.12 || ^7.1.5",