Skip to content

Commit

Permalink
TASK: Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sabbelasichon committed May 28, 2024
1 parent bc656ec commit 92139d8
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 21 deletions.
2 changes: 0 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
verbose="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ public function refactor(Node $node)
$tableNames = $this->valueResolver->getValue($tableArgument);

foreach (explode(',', $tableNames) as $tableName) {
if (!$tableName) {
if ($tableName === '') {
continue;
}

$directoryName = dirname($this->file->getFilePath());
$newConfigurationFile = $directoryName . '/Configuration/TCA/Overrides/' . $tableName . '.php';
$this->writeConfigurationToFile($newConfigurationFile, $tableName);
}

return NodeTraverser::REMOVE_NODE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,9 @@ public function refactor(Node $node): ?Node
return null;
}

$node->args[1]->value = $this->nodeFactory->createClassConstFetch(
'Doctrine\\DBAL\\Platforms\\TrimMode',
'UNSPECIFIED'
);
return $node;

if (! $this->nodeTypeResolver->isMethodStaticCallOrClassMethodObjectType(
$node,
new ObjectType('TYPO3\\CMS\\Core\Database\\Query\\Expression\\ExpressionBuilder')
new ObjectType('TYPO3\\CMS\\Core\\Database\\Query\\Expression\\ExpressionBuilder')
)) {
return null;
}
Expand All @@ -98,15 +92,15 @@ public function refactor(Node $node): ?Node

$trimMode = $this->valueResolver->getValue($secondArgument->value);

if (! is_int($trimMode)) {
if (! is_numeric($trimMode)) {
return null;
}

if (! isset(self::$integerToTrimMode[$trimMode])) {
if (! isset(self::$integerToTrimMode[((int) $trimMode)])) {
return null;
}

$trimModeConstant = self::$integerToTrimMode[$trimMode];
$trimModeConstant = self::$integerToTrimMode[((int) $trimMode)];

$node->args[1]->value = $this->nodeFactory->createClassConstFetch(
'Doctrine\\DBAL\\Platforms\\TrimMode',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Ssch\TYPO3Rector\Tests\Rector\General\Renaming\RenameAttributeRector;

use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\ValueObject\PhpVersionFeature;

final class RenameAttributeRectorTest extends AbstractRectorTestCase
{
Expand All @@ -14,10 +13,6 @@ final class RenameAttributeRectorTest extends AbstractRectorTestCase
*/
public function test(string $filePath): void
{
if (PHP_VERSION_ID < PhpVersionFeature::ATTRIBUTES) {
$this->markTestSkipped('Do not execute');
}

$this->doTestFile($filePath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\ValueObject\PhpVersion;
use Rector\ValueObject\PhpVersionFeature;
use Ssch\TYPO3Rector\General\Renaming\RenameAttributeRector;
use Ssch\TYPO3Rector\General\Renaming\ValueObject\RenameAttribute;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../../../config/config_test.php');
$rectorConfig->phpVersion(PhpVersion::PHP_80);
$rectorConfig->phpVersion(PhpVersionFeature::ATTRIBUTES);
$rectorConfig->ruleWithConfiguration(RenameAttributeRector::class, [
new RenameAttribute('TYPO3\CMS\Backend\Attribute\Controller', 'TYPO3\CMS\Backend\Attribute\AsController'),
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Ssch\TYPO3Rector\Tests\Rector\v13\v0\MigrateExpressionBuilderTrimMethodSecondParameterRector\Fixture;

use Doctrine\DBAL\Platforms\TrimMode;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;

$queryBuilder = GeneralUtility::makeInstance(Connection::class)->createQueryBuilder();
$queryBuilder->expr()
->comparison(
$queryBuilder->expr()
->trim('string', 0),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);

$queryBuilder->expr()
->comparison(
$queryBuilder->expr()
->trim('string', 1),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);

$queryBuilder->expr()
->comparison(
$queryBuilder->expr()
->trim('string', 2),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);

$queryBuilder->expr()
->comparison(
$queryBuilder->expr()
->trim('string', 3),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);

$queryBuilder->expr()
->comparison(
$queryBuilder->expr()
->trim('string', 5),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);

$queryBuilder->expr()
->comparison(
$queryBuilder->expr()
->trim('string', TrimMode::LEADING),
ExpressionBuilder::EQ,
$queryBuilder->createNamedParameter('', Connection::PARAM_STR)
);
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\ValueObject\PhpVersionFeature;
use Ssch\TYPO3Rector\TYPO313\v0\MigrateExpressionBuilderTrimMethodSecondParameterRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->import(__DIR__ . '/../../../../../../config/config.php');
$rectorConfig->import(__DIR__ . '/../../../../../../config/config_test.php');
$rectorConfig->phpVersion(PhpVersionFeature::ENUM);
$rectorConfig->rule(MigrateExpressionBuilderTrimMethodSecondParameterRector::class);
};

0 comments on commit 92139d8

Please sign in to comment.