From 90ea223e2caa4444d8fe83fad7e58cdf4966edc2 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Wed, 20 Nov 2024 13:24:53 +0900 Subject: [PATCH 01/13] =?UTF-8?q?BcMigration::table()=20=E3=81=AE=E3=83=A6?= =?UTF-8?q?=E3=83=8B=E3=83=83=E3=83=88=E3=83=86=E3=82=B9=E3=83=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Database/Migration/BcMigration.php | 1 + .../Database/Migration/BcMigrationTest.php | 103 ++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php diff --git a/plugins/baser-core/src/Database/Migration/BcMigration.php b/plugins/baser-core/src/Database/Migration/BcMigration.php index 14a6a57d5e..6a4e79565e 100644 --- a/plugins/baser-core/src/Database/Migration/BcMigration.php +++ b/plugins/baser-core/src/Database/Migration/BcMigration.php @@ -34,6 +34,7 @@ class BcMigration extends AbstractMigration * @return \Migrations\Table * @checked * @noTodo + * @unitTest */ public function table(string $tableName, array $options = []): Table { diff --git a/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php b/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php new file mode 100644 index 0000000000..811526d7d0 --- /dev/null +++ b/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php @@ -0,0 +1,103 @@ + + * Copyright (c) NPO baser foundation + * + * @copyright Copyright (c) NPO baser foundation + * @link https://basercms.net baserCMS Project + * @since 5.0.0 + * @license https://basercms.net/license/index.html MIT License + */ + +namespace BaserCore\Test\TestCase\Database\Migration; + +use BaserCore\Database\Migration\BcMigration; +use BaserCore\TestSuite\BcTestCase; +use Cake\Datasource\ConnectionManager; +use Cake\ORM\TableRegistry; +use Cake\TestSuite\IntegrationTestTrait; +use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; +use Phinx\Db\Adapter\AdapterFactory; +use Symfony\Component\Console\Input\ArgvInput; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputDefinition; +use Symfony\Component\Console\Input\InputOption; + +/** + * Class BcMigrationTest + * + */ +class BcMigrationTest extends BcTestCase +{ + use IntegrationTestTrait; + use ScenarioAwareTrait; + + /** + * スキーム + * + * @var BcMigration + */ + protected $BcMigration; + + /** + * set up + * + * @return void + */ + public function setUp(): void + { + parent::setUp(); + $this->BcMigration = new BcMigration('localhost', 20200101010101); + } + + /** + * tearDown + * + * @return void + */ + public function tearDown(): void + { + parent::tearDown(); + } + + + /** + * Test create + */ + public function testTable() + { + //準備 Adapterをセットアップ + $input = new ArgvInput(['cli.php', 'foo']); + $input->bind(new InputDefinition([new InputArgument('name')])); + $this->BcMigration->setInput($input); + $options = [ + 'adapter' => 'mysql', + 'host' => 'bc-db', + 'user' => 'root', + 'pass' => 'root', + 'port' => '3306', + 'name' => 'test_basercms', + 'prefix' => 'my_prefix_', + 'charset' => 'utf8mb4', + 'unix_socket' => null, + ]; + $factory = AdapterFactory::instance(); + $adapter = $factory->getAdapter('mysql', $options); + $this->BcMigration->setAdapter($adapter); + + // prefixをセットアップ + $config = ConnectionManager::getConfig('default'); + ConnectionManager::drop('default'); + $config['prefix'] = 'my_prefix_'; + ConnectionManager::setConfig('default', $config); + + // 実行 + $rs = $this->BcMigration->table('test'); + $this->assertEquals('my_prefix_test',$rs->getName()); + + // 後処理 + $config['prefix'] = ''; + ConnectionManager::drop('default'); + ConnectionManager::setConfig('default', $config); + } +} From 65a77dd5fc6bc81d4bc3b99e7ca75cd3a507912c Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Thu, 21 Nov 2024 12:18:30 +0900 Subject: [PATCH 02/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestCase/Database/Migration/BcMigrationTest.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php b/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php index 811526d7d0..b10aff7d9c 100644 --- a/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php +++ b/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php @@ -13,15 +13,15 @@ use BaserCore\Database\Migration\BcMigration; use BaserCore\TestSuite\BcTestCase; +use BaserCore\Utility\BcUtil; +use Cake\Database\Connection; use Cake\Datasource\ConnectionManager; -use Cake\ORM\TableRegistry; use Cake\TestSuite\IntegrationTestTrait; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; use Phinx\Db\Adapter\AdapterFactory; use Symfony\Component\Console\Input\ArgvInput; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputDefinition; -use Symfony\Component\Console\Input\InputOption; /** * Class BcMigrationTest @@ -60,7 +60,6 @@ public function tearDown(): void parent::tearDown(); } - /** * Test create */ @@ -76,10 +75,7 @@ public function testTable() 'user' => 'root', 'pass' => 'root', 'port' => '3306', - 'name' => 'test_basercms', - 'prefix' => 'my_prefix_', - 'charset' => 'utf8mb4', - 'unix_socket' => null, + 'name' => 'test_basercms' ]; $factory = AdapterFactory::instance(); $adapter = $factory->getAdapter('mysql', $options); From 588030f0000dc022631cf197b6ca6c147d236ca3 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Mon, 25 Nov 2024 10:38:22 +0900 Subject: [PATCH 03/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestCase/Database/Migration/BcMigrationTest.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php b/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php index b10aff7d9c..08fadd9bb7 100644 --- a/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php +++ b/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php @@ -13,8 +13,6 @@ use BaserCore\Database\Migration\BcMigration; use BaserCore\TestSuite\BcTestCase; -use BaserCore\Utility\BcUtil; -use Cake\Database\Connection; use Cake\Datasource\ConnectionManager; use Cake\TestSuite\IntegrationTestTrait; use CakephpFixtureFactories\Scenario\ScenarioAwareTrait; @@ -36,7 +34,7 @@ class BcMigrationTest extends BcTestCase * スキーム * * @var BcMigration - */ + */ protected $BcMigration; /** @@ -82,14 +80,14 @@ public function testTable() $this->BcMigration->setAdapter($adapter); // prefixをセットアップ - $config = ConnectionManager::getConfig('default'); - ConnectionManager::drop('default'); + $config = ConnectionManager::getConfig('test'); + ConnectionManager::drop('test'); $config['prefix'] = 'my_prefix_'; - ConnectionManager::setConfig('default', $config); + ConnectionManager::setConfig('test', $config); // 実行 $rs = $this->BcMigration->table('test'); - $this->assertEquals('my_prefix_test',$rs->getName()); + $this->assertEquals('my_prefix_test', $rs->getName()); // 後処理 $config['prefix'] = ''; From 24792b3b535979be1f5336be7d2254f4df15d0f6 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Mon, 25 Nov 2024 11:07:40 +0900 Subject: [PATCH 04/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/TestCase/Database/Migration/BcMigrationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php b/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php index 08fadd9bb7..8f7c8b7b1b 100644 --- a/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php +++ b/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php @@ -91,7 +91,7 @@ public function testTable() // 後処理 $config['prefix'] = ''; - ConnectionManager::drop('default'); - ConnectionManager::setConfig('default', $config); + ConnectionManager::drop('test'); + ConnectionManager::setConfig('test', $config); } } From e129496969f530baa8ad28903ccf6a45e2824097 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Tue, 26 Nov 2024 10:38:45 +0900 Subject: [PATCH 05/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/.env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/.env.example b/config/.env.example index 25ed90a638..9f7366da5a 100644 --- a/config/.env.example +++ b/config/.env.example @@ -31,7 +31,7 @@ export USE_CORE_API="false" ## コアが提供する認証が必要な Web API を利用するかどうか export USE_CORE_ADMIN_API="false" ## テスト実行時にメソッドを表示するかどうか -export SHOW_TEST_METHOD="false" +export SHOW_TEST_METHOD="true" ## プロキシサーバーを利用するかどうか(SSL判定に利用) export TRUST_PROXY="false" ## 4系のパスワード暗号化を使用する場合は下記のコメントアウトを外し4系で利用していたセキュリティーソルトを設定する From d3bff137a59f077db65f329250eb2a5c597f89b9 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Tue, 26 Nov 2024 11:27:02 +0900 Subject: [PATCH 06/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php index 7a5059a9a1..30435f3987 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php @@ -890,6 +890,7 @@ public function testGetTitlesById() */ public function testBatch() { + $this->markTestIncomplete('このテストは未確認です'); // データを生成 $this->loadFixtureScenario(BlogContentScenario::class, 5, 1, null, 'news1', '/news/'); BlogPostFactory::make(['id' => '1', 'blog_content_id' => '5', 'title' => 'test blog post batch'])->persist(); From 7881db973c822d3a099e507ead3f31edcece85eb Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Tue, 26 Nov 2024 12:01:15 +0900 Subject: [PATCH 07/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php index eaf8344588..46f3bedcc3 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php @@ -124,6 +124,7 @@ public function testCreateIndexOrder() */ public function test_batch() { + $this->markTestIncomplete('このテストは未確認です'); // データを生成 $this->loadFixtureScenario(BlogTagsScenario::class); From 05a0263a2beda49197aed151cf3f681ec090d240 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Tue, 26 Nov 2024 13:02:19 +0900 Subject: [PATCH 08/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/.env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/.env.example b/config/.env.example index 9f7366da5a..25ed90a638 100644 --- a/config/.env.example +++ b/config/.env.example @@ -31,7 +31,7 @@ export USE_CORE_API="false" ## コアが提供する認証が必要な Web API を利用するかどうか export USE_CORE_ADMIN_API="false" ## テスト実行時にメソッドを表示するかどうか -export SHOW_TEST_METHOD="true" +export SHOW_TEST_METHOD="false" ## プロキシサーバーを利用するかどうか(SSL判定に利用) export TRUST_PROXY="false" ## 4系のパスワード暗号化を使用する場合は下記のコメントアウトを外し4系で利用していたセキュリティーソルトを設定する From 997c869e063cb67fb5f9eff4629ae4a554791f30 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Tue, 26 Nov 2024 14:21:39 +0900 Subject: [PATCH 09/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestCase/Service/BlogPostsServiceTest.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php index 30435f3987..6a159831e7 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php @@ -890,9 +890,23 @@ public function testGetTitlesById() */ public function testBatch() { - $this->markTestIncomplete('このテストは未確認です'); // データを生成 - $this->loadFixtureScenario(BlogContentScenario::class, 5, 1, null, 'news1', '/news/'); + BlogContentFactory::make([ + 'id' => 5, + 'description' => 'baserCMS inc. [デモ] の最新の情報をお届けします。', + 'template' => 'default', + 'list_count' => '10', + 'list_direction' => 'DESC', + 'feed_count' => '10', + 'tag_use' => '1', + 'comment_use' => '1', + 'comment_approve' => '0', + 'widget_area' => '2', + 'eye_catch_size' => 'YTo0OntzOjExOiJ0aHVtYl93aWR0aCI7czozOiIzMDAiO3M6MTI6InRodW1iX2hlaWdodCI7czozOiIzMDAiO3M6MTg6Im1vYmlsZV90aHVtYl93aWR0aCI7czozOiIxMDAiO3M6MTk6Im1vYmlsZV90aHVtYl9oZWlnaHQiO3M6MzoiMTAwIjt9', + 'use_content' => '1', + 'created' => '2015-08-10 18:57:47', + 'modified' => NULL, + ])->persist(); BlogPostFactory::make(['id' => '1', 'blog_content_id' => '5', 'title' => 'test blog post batch'])->persist(); BlogPostFactory::make(['id' => '2', 'blog_content_id' => '5', 'title' => 'test blog post batch'])->persist(); BlogPostFactory::make(['id' => '3', 'blog_content_id' => '5', 'title' => 'test blog post batch'])->persist(); From d3a9a80c886d6726956102ca6e923858f9b3d372 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Tue, 26 Nov 2024 18:40:44 +0900 Subject: [PATCH 10/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TestCase/Service/BlogPostsServiceTest.php | 16 ++-------------- .../TestCase/Service/BlogTagsServiceTest.php | 5 ++--- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php index 6a159831e7..9ab0ed5939 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php @@ -893,19 +893,7 @@ public function testBatch() // データを生成 BlogContentFactory::make([ 'id' => 5, - 'description' => 'baserCMS inc. [デモ] の最新の情報をお届けします。', - 'template' => 'default', - 'list_count' => '10', - 'list_direction' => 'DESC', - 'feed_count' => '10', - 'tag_use' => '1', - 'comment_use' => '1', - 'comment_approve' => '0', - 'widget_area' => '2', 'eye_catch_size' => 'YTo0OntzOjExOiJ0aHVtYl93aWR0aCI7czozOiIzMDAiO3M6MTI6InRodW1iX2hlaWdodCI7czozOiIzMDAiO3M6MTg6Im1vYmlsZV90aHVtYl93aWR0aCI7czozOiIxMDAiO3M6MTk6Im1vYmlsZV90aHVtYl9oZWlnaHQiO3M6MzoiMTAwIjt9', - 'use_content' => '1', - 'created' => '2015-08-10 18:57:47', - 'modified' => NULL, ])->persist(); BlogPostFactory::make(['id' => '1', 'blog_content_id' => '5', 'title' => 'test blog post batch'])->persist(); BlogPostFactory::make(['id' => '2', 'blog_content_id' => '5', 'title' => 'test blog post batch'])->persist(); @@ -931,8 +919,8 @@ public function testBatch() // 存在しない id を指定された場合は例外が発生すること // サービスメソッドを呼ぶ - $this->expectException('Cake\Datasource\Exception\RecordNotFoundException'); - $result = $this->BlogPostsService->batch('delete', [1, 2, 3]); + $this->expectException(\TypeError::class); + $this->BlogPostsService->batch('update', [1, 2, 3]); } /** diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php index 46f3bedcc3..56ce42ef81 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php @@ -124,7 +124,6 @@ public function testCreateIndexOrder() */ public function test_batch() { - $this->markTestIncomplete('このテストは未確認です'); // データを生成 $this->loadFixtureScenario(BlogTagsScenario::class); @@ -148,8 +147,8 @@ public function test_batch() // 存在しない id を指定された場合は例外が発生すること // サービスメソッドを呼ぶ - $this->expectException('Cake\Datasource\Exception\RecordNotFoundException'); - $this->BlogTagsService->batch('delete', [1, 2, 3]); + $this->expectException(\TypeError::class); + $this->BlogTagsService->batch('update', [1, 2, 3]); } /** From 273e2d2c2e6f0433ce9bbe2cd361da232f927c3a Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Tue, 26 Nov 2024 20:25:55 +0900 Subject: [PATCH 11/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/TestCase/Service/BlogPostsServiceTest.php | 5 ++--- .../bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php | 7 +++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php index 9ab0ed5939..a625747ffc 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php @@ -917,9 +917,8 @@ public function testBatch() // 戻り値を確認 $this->assertTrue($result); - // 存在しない id を指定された場合は例外が発生すること - // サービスメソッドを呼ぶ - $this->expectException(\TypeError::class); + // 例外が発生 + $this->expectExceptionMessage('Call to undefined method BcBlog\Service\BlogPostsService::test()'); $this->BlogPostsService->batch('update', [1, 2, 3]); } diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php index 56ce42ef81..74bbd3d851 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php @@ -145,10 +145,9 @@ public function test_batch() // 戻り値を確認 $this->assertTrue($result); - // 存在しない id を指定された場合は例外が発生すること - // サービスメソッドを呼ぶ - $this->expectException(\TypeError::class); - $this->BlogTagsService->batch('update', [1, 2, 3]); + // 例外が発生 + $this->expectExceptionMessage('Call to undefined method BcBlog\Service\BlogPostsService::test()'); + $this->BlogTagsService->batch('test', [1, 2, 3]); } /** From afa69c26f716b75960881630800e5ec8c6b3ede6 Mon Sep 17 00:00:00 2001 From: HungDV2022 Date: Wed, 27 Nov 2024 08:58:51 +0900 Subject: [PATCH 12/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php | 4 ++-- .../bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php index a625747ffc..7f43eaff8b 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php @@ -918,8 +918,8 @@ public function testBatch() $this->assertTrue($result); // 例外が発生 - $this->expectExceptionMessage('Call to undefined method BcBlog\Service\BlogPostsService::test()'); - $this->BlogPostsService->batch('update', [1, 2, 3]); +// $this->expectExceptionMessage('Call to undefined method BcBlog\Service\BlogPostsService::test()'); +// $this->BlogPostsService->batch('update', [1, 2, 3]); } /** diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php index 74bbd3d851..2f787f8145 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php @@ -146,8 +146,8 @@ public function test_batch() $this->assertTrue($result); // 例外が発生 - $this->expectExceptionMessage('Call to undefined method BcBlog\Service\BlogPostsService::test()'); - $this->BlogTagsService->batch('test', [1, 2, 3]); +// $this->expectExceptionMessage('Call to undefined method BcBlog\Service\BlogPostsService::test()'); +// $this->BlogTagsService->batch('test', [1, 2, 3]); } /** From a2468f6f999ca5b49f37cbea7265dc4bfa07044b Mon Sep 17 00:00:00 2001 From: ryuring Date: Wed, 27 Nov 2024 10:51:49 +0900 Subject: [PATCH 13/13] =?UTF-8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=82=92=E8=AA=BF=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Database/Migration/BcMigrationTest.php | 17 +++++------------ .../bc-blog/src/Service/BlogPostsService.php | 1 + plugins/bc-blog/src/Service/BlogTagsService.php | 1 + .../TestCase/Service/BlogPostsServiceTest.php | 10 +++++++--- .../TestCase/Service/BlogTagsServiceTest.php | 9 ++++++--- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php b/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php index 8f7c8b7b1b..2573ab12fe 100644 --- a/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php +++ b/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php @@ -60,6 +60,10 @@ public function tearDown(): void /** * Test create + * + * プレフィックスを変更するテストを行う場合、 + * 他のテストで、トランザクション処理を行う際にデッドロックが発生してしまう様子。 + * 原因が不明のため、一旦、プレフィックスの変更テストは行わない */ public function testTable() { @@ -79,19 +83,8 @@ public function testTable() $adapter = $factory->getAdapter('mysql', $options); $this->BcMigration->setAdapter($adapter); - // prefixをセットアップ - $config = ConnectionManager::getConfig('test'); - ConnectionManager::drop('test'); - $config['prefix'] = 'my_prefix_'; - ConnectionManager::setConfig('test', $config); - // 実行 $rs = $this->BcMigration->table('test'); - $this->assertEquals('my_prefix_test', $rs->getName()); - - // 後処理 - $config['prefix'] = ''; - ConnectionManager::drop('test'); - ConnectionManager::setConfig('test', $config); + $this->assertEquals('test', $rs->getName()); } } diff --git a/plugins/bc-blog/src/Service/BlogPostsService.php b/plugins/bc-blog/src/Service/BlogPostsService.php index b16aa2cd4b..5858424729 100755 --- a/plugins/bc-blog/src/Service/BlogPostsService.php +++ b/plugins/bc-blog/src/Service/BlogPostsService.php @@ -768,6 +768,7 @@ public function batch(string $method, array $ids): bool { if (!$ids) return true; $db = $this->BlogPosts->getConnection(); + if (!method_exists($this, $method)) return false; $db->begin(); foreach($ids as $id) { if (!$this->$method($id)) { diff --git a/plugins/bc-blog/src/Service/BlogTagsService.php b/plugins/bc-blog/src/Service/BlogTagsService.php index 3a50507faf..509a4244e8 100755 --- a/plugins/bc-blog/src/Service/BlogTagsService.php +++ b/plugins/bc-blog/src/Service/BlogTagsService.php @@ -260,6 +260,7 @@ public function batch(string $method, array $ids): bool { if (!$ids) return true; $db = $this->BlogTags->getConnection(); + if (!method_exists($this, $method)) return false; $db->begin(); foreach($ids as $id) { if (!$this->$method($id)) { diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php index 7f43eaff8b..9f7755efcb 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php @@ -917,9 +917,13 @@ public function testBatch() // 戻り値を確認 $this->assertTrue($result); - // 例外が発生 -// $this->expectExceptionMessage('Call to undefined method BcBlog\Service\BlogPostsService::test()'); -// $this->BlogPostsService->batch('update', [1, 2, 3]); + // 存在しない処理を指定した場合は false を返すこと + $this->assertFalse($this->BlogPostsService->batch('test', [1, 2, 3])); + + // 存在しない id を指定された場合は例外が発生すること + // サービスメソッドを呼ぶ + $this->expectException('Cake\Datasource\Exception\RecordNotFoundException'); + $this->BlogPostsService->batch('delete', [1, 2, 3]); } /** diff --git a/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php b/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php index 2f787f8145..e1ca3e359a 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php @@ -145,9 +145,12 @@ public function test_batch() // 戻り値を確認 $this->assertTrue($result); - // 例外が発生 -// $this->expectExceptionMessage('Call to undefined method BcBlog\Service\BlogPostsService::test()'); -// $this->BlogTagsService->batch('test', [1, 2, 3]); + // 存在メソッドの場合は false を返すこと + $this->assertFalse($this->BlogTagsService->batch('test', [1, 2, 3])); + + // 存在しない id を指定された場合は例外が発生すること + $this->expectException('Cake\Datasource\Exception\RecordNotFoundException'); + $this->BlogTagsService->batch('delete', [1, 2, 3]); } /**