Skip to content

Commit

Permalink
AppTable::belongsToMany のユニットテスト (#3756)
Browse files Browse the repository at this point in the history
Co-authored-by: Đỗ Văn Hùng <[email protected]>
  • Loading branch information
HungDV2022 and dovanhung authored Sep 18, 2024
1 parent 5da4814 commit 3ea31cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/baser-core/src/Model/Table/AppTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function getTable(): string
* @return BelongsToMany
* @checked
* @noTodo
* @unitTest
*/
public function belongsToMany(string $associated, array $options = []): BelongsToMany
{
Expand Down
23 changes: 23 additions & 0 deletions plugins/baser-core/tests/TestCase/Model/Table/AppTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,29 @@ public static function getUrlPatternDataProvider()
];
}

/**
* test belongsToMany
*/
public function testBelongsToMany()
{
//プレフィックスを設定
$dbConfig = BcUtil::getCurrentDbConfig();
$dbConfig['prefix'] = 'unittest_';
$connection = new Connection($dbConfig);
$this->App = $this->getTableLocator()->get('BaserCore.App')->setConnection($connection);

$this->App = $this->getTableLocator()->get('BcBlog.BlogPosts');
//Usersに連携
$rs = $this->App->belongsToMany('Users', [
'className' => 'BaserCore.Users',
'foreignKey' => 'user_id',
]);
//戻り値を確認
$this->assertEquals('user_id', $rs->getForeignKey());
$this->assertEquals('BaserCore.Users', $rs->getClassName());
$this->assertEquals('unittest_blog_posts', $rs->getSource()->getTable());
}

/**
* Test getMax
*
Expand Down

0 comments on commit 3ea31cb

Please sign in to comment.