From b8267291de4627a2cdd5739ea531dcc2ceae9dac Mon Sep 17 00:00:00 2001
From: Mark Story <mark@mark-story.com>
Date: Mon, 11 Nov 2024 11:34:01 -0500
Subject: [PATCH 1/2] Start rector set for 5.2

- Add rector for Argument::getMultipleOption()
---
 config/rector/cakephp52.php                       |  9 +++++++++
 config/rector/sets/cakephp52.php                  | 13 +++++++++++++
 src/Rector/Set/CakePHPSetList.php                 |  5 +++++
 tests/TestCase/Command/RectorCommandTest.php      |  7 +++++++
 .../RectorCommand-testApply52/src/SomeTest.php    | 15 +++++++++++++++
 .../RectorCommand-testApply52/src/SomeTest.php    | 15 +++++++++++++++
 6 files changed, 64 insertions(+)
 create mode 100644 config/rector/cakephp52.php
 create mode 100644 config/rector/sets/cakephp52.php
 create mode 100644 tests/test_apps/original/RectorCommand-testApply52/src/SomeTest.php
 create mode 100644 tests/test_apps/upgraded/RectorCommand-testApply52/src/SomeTest.php

diff --git a/config/rector/cakephp52.php b/config/rector/cakephp52.php
new file mode 100644
index 0000000..49e95ee
--- /dev/null
+++ b/config/rector/cakephp52.php
@@ -0,0 +1,9 @@
+<?php
+declare(strict_types=1);
+
+use Cake\Upgrade\Rector\Set\CakePHPSetList;
+use Rector\Config\RectorConfig;
+
+return static function (RectorConfig $rectorConfig): void {
+    $rectorConfig->sets([CakePHPSetList::CAKEPHP_52]);
+};
diff --git a/config/rector/sets/cakephp52.php b/config/rector/sets/cakephp52.php
new file mode 100644
index 0000000..2995218
--- /dev/null
+++ b/config/rector/sets/cakephp52.php
@@ -0,0 +1,13 @@
+<?php
+declare(strict_types=1);
+
+use Rector\Config\RectorConfig;
+use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
+use Rector\Renaming\ValueObject\MethodCallRename;
+
+# @see https://book.cakephp.org/5/en/appendices/5-2-migration-guide.html
+return static function (RectorConfig $rectorConfig): void {
+    $rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
+        new MethodCallRename('Cake\Console\Arguments', 'getMultipleOption', 'getArrayOption'),
+    ]);
+};
diff --git a/src/Rector/Set/CakePHPSetList.php b/src/Rector/Set/CakePHPSetList.php
index ff149d9..eb4c368 100644
--- a/src/Rector/Set/CakePHPSetList.php
+++ b/src/Rector/Set/CakePHPSetList.php
@@ -77,6 +77,11 @@ final class CakePHPSetList implements SetListInterface
      */
     public const CAKEPHP_51 = __DIR__ . '/../../../config/rector/sets/cakephp51.php';
 
+    /**
+     * @var string
+     */
+    public const CAKEPHP_52 = __DIR__ . '/../../../config/rector/sets/cakephp52.php';
+
     /**
      * @var string
      */
diff --git a/tests/TestCase/Command/RectorCommandTest.php b/tests/TestCase/Command/RectorCommandTest.php
index 4b27913..d109ee4 100644
--- a/tests/TestCase/Command/RectorCommandTest.php
+++ b/tests/TestCase/Command/RectorCommandTest.php
@@ -98,4 +98,11 @@ public function testApply51()
         $this->exec('upgrade rector --rules cakephp51 ' . TEST_APP);
         $this->assertTestAppUpgraded();
     }
+
+    public function testApply52()
+    {
+        $this->setupTestApp(__FUNCTION__);
+        $this->exec('upgrade rector --rules cakephp52 ' . TEST_APP);
+        $this->assertTestAppUpgraded();
+    }
 }
diff --git a/tests/test_apps/original/RectorCommand-testApply52/src/SomeTest.php b/tests/test_apps/original/RectorCommand-testApply52/src/SomeTest.php
new file mode 100644
index 0000000..3b7cfc7
--- /dev/null
+++ b/tests/test_apps/original/RectorCommand-testApply52/src/SomeTest.php
@@ -0,0 +1,15 @@
+<?php
+declare(strict_types=1);
+
+namespace MyPlugin;
+
+use Cake\Console\Arguments;
+
+class SomeTest extends TestCase
+{
+    public function testRenames(): void
+    {
+        $args = new Arguments([], ['a' => [1, 2]], []);
+        $option = $args->getMultipleOption('c');
+    }
+}
diff --git a/tests/test_apps/upgraded/RectorCommand-testApply52/src/SomeTest.php b/tests/test_apps/upgraded/RectorCommand-testApply52/src/SomeTest.php
new file mode 100644
index 0000000..713e0dd
--- /dev/null
+++ b/tests/test_apps/upgraded/RectorCommand-testApply52/src/SomeTest.php
@@ -0,0 +1,15 @@
+<?php
+declare(strict_types=1);
+
+namespace MyPlugin;
+
+use Cake\Console\Arguments;
+
+class SomeTest extends TestCase
+{
+    public function testRenames(): void
+    {
+        $args = new Arguments([], ['a' => [1, 2]], []);
+        $option = $args->getArrayOption('a');
+    }
+}

From 31d82e415de7bfdc658e9048301e1e07a68160c1 Mon Sep 17 00:00:00 2001
From: Mark Story <mark@mark-story.com>
Date: Mon, 11 Nov 2024 11:39:54 -0500
Subject: [PATCH 2/2] Fix mistake

---
 .../original/RectorCommand-testApply52/src/SomeTest.php         | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/test_apps/original/RectorCommand-testApply52/src/SomeTest.php b/tests/test_apps/original/RectorCommand-testApply52/src/SomeTest.php
index 3b7cfc7..ef14d99 100644
--- a/tests/test_apps/original/RectorCommand-testApply52/src/SomeTest.php
+++ b/tests/test_apps/original/RectorCommand-testApply52/src/SomeTest.php
@@ -10,6 +10,6 @@ class SomeTest extends TestCase
     public function testRenames(): void
     {
         $args = new Arguments([], ['a' => [1, 2]], []);
-        $option = $args->getMultipleOption('c');
+        $option = $args->getMultipleOption('a');
     }
 }