Skip to content

Commit

Permalink
Merge pull request #3987 from HungDV2022/unittest_PrefixOrmResolver_find
Browse files Browse the repository at this point in the history
PrefixOrmResolver::find() ユニットテスト
  • Loading branch information
HungDV2022 authored Nov 8, 2024
2 parents 9a10616 + c401dc0 commit ce4536b
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class PrefixOrmResolver extends OrmResolver implements ResolverInterface
* @return array|EntityInterface|null
* @checked
* @noTodo
* @unitTest
*/
public function find(array $conditions, $type = self::TYPE_AND): \ArrayAccess|array|null
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* baserCMS : Based Website Development Project <https://basercms.net>
* Copyright (c) NPO baser foundation <https://baserfoundation.org/>
*
* @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\Identifier\Resolver;

use BaserCore\Identifier\Resolver\PrefixOrmResolver;
use BaserCore\Test\Factory\UserFactory;
use BaserCore\TestSuite\BcTestCase;
use CakephpFixtureFactories\Scenario\ScenarioAwareTrait;

/**
* Class PrefixOrmResolverTest
* @property PrefixOrmResolver $PrefixOrmResolver
*
*/
class PrefixOrmResolverTest extends BcTestCase
{
/**
* ScenarioAwareTrait
*/
use ScenarioAwareTrait;

/**
* Set Up
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
$this->PrefixOrmResolver = new PrefixOrmResolver();
}

/**
* Tear Down
*
* @return void
*/
public function tearDown(): void
{
parent::tearDown();
}

/**
* testInitialize
*
* @return void
*/
public function testFind(): void
{
//準備
UserFactory::make(['id' => 1, 'name' => 'user_test'])->persist();
$this->PrefixOrmResolver->setConfig('prefix', 'test');

//正常テスト
$rs = $this->PrefixOrmResolver->find(['id' => 'test_1']);
$this->assertEquals('user_test', $rs->name);

//異常テスト 
$rs = $this->PrefixOrmResolver->find(['id' => 'user_1']);
$this->assertNull($rs);
}
}

0 comments on commit ce4536b

Please sign in to comment.