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..2573ab12fe --- /dev/null +++ b/plugins/baser-core/tests/TestCase/Database/Migration/BcMigrationTest.php @@ -0,0 +1,90 @@ + + * 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\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; + +/** + * 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' + ]; + $factory = AdapterFactory::instance(); + $adapter = $factory->getAdapter('mysql', $options); + $this->BcMigration->setAdapter($adapter); + + // 実行 + $rs = $this->BcMigration->table('test'); + $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 7a5059a9a1..9f7755efcb 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php @@ -891,7 +891,10 @@ public function testGetTitlesById() public function testBatch() { // データを生成 - $this->loadFixtureScenario(BlogContentScenario::class, 5, 1, null, 'news1', '/news/'); + BlogContentFactory::make([ + 'id' => 5, + 'eye_catch_size' => 'YTo0OntzOjExOiJ0aHVtYl93aWR0aCI7czozOiIzMDAiO3M6MTI6InRodW1iX2hlaWdodCI7czozOiIzMDAiO3M6MTg6Im1vYmlsZV90aHVtYl93aWR0aCI7czozOiIxMDAiO3M6MTk6Im1vYmlsZV90aHVtYl9oZWlnaHQiO3M6MzoiMTAwIjt9', + ])->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(); @@ -914,10 +917,13 @@ public function testBatch() // 戻り値を確認 $this->assertTrue($result); + // 存在しない処理を指定した場合は false を返すこと + $this->assertFalse($this->BlogPostsService->batch('test', [1, 2, 3])); + // 存在しない id を指定された場合は例外が発生すること // サービスメソッドを呼ぶ $this->expectException('Cake\Datasource\Exception\RecordNotFoundException'); - $result = $this->BlogPostsService->batch('delete', [1, 2, 3]); + $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 eaf8344588..e1ca3e359a 100755 --- a/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php +++ b/plugins/bc-blog/tests/TestCase/Service/BlogTagsServiceTest.php @@ -145,8 +145,10 @@ public function test_batch() // 戻り値を確認 $this->assertTrue($result); + // 存在メソッドの場合は false を返すこと + $this->assertFalse($this->BlogTagsService->batch('test', [1, 2, 3])); + // 存在しない id を指定された場合は例外が発生すること - // サービスメソッドを呼ぶ $this->expectException('Cake\Datasource\Exception\RecordNotFoundException'); $this->BlogTagsService->batch('delete', [1, 2, 3]); }