在 Codeception 中运行单元测试时的交互式控制台

问题描述 投票:0回答:1

我们有 2 个场景:

  1. 账户绑定(将银行账号注册到服务)
  2. 验证OTP(输入通过客户手机发送的OTP代码)

第二个场景中使用的帐户绑定的一些响应,但我需要在第二步之前“注入”OTP 代码值。

到目前为止,我在 Codeception 中所做的是使用

Codeception\Lib\Actor\Shared\Pause
:

    public function testVerificationFlow()
    {
        $faker = Faker\Factory::create();
        
        $sequence = '0000';
        $partnerReferenceNo = $faker->numerify('###########') . $sequence;
        $bankAccountNo      = $faker->numerify('##########');
        $bankCardNo         = $faker->randomNumber(4, true);
        $limit              = 250000.00;
        $email              = $faker->email();
        $custIdMerchant     = $faker->numerify('##########');
        
        $response = $this->autopay->accountBinding(
            $partnerReferenceNo,
            $bankAccountNo,
            $bankCardNo,
            $limit,
            $email,
            $custIdMerchant
        );

        codecept_debug($response);
        $this->assertEquals($response->responseCode, self::RESP_CODE_ACCOUNT_BINDING);
        
        $otpCode = '';
        
        // how to inject the value of $otpCode here?
        $this->pause();

        codecept_debug($otpCode);

        $verifyOtpResponse = $this->autopay->verifyOtp(
            $partnerReferenceNo,
            $response->originalReferenceNo,
            $response->chargeToken,
            $otpCode,
        );

        codecept_debug($verifyOtpResponse);
        $this->assertEquals($verifyOtpResponse->responseCode, self::RESP_CODE_OTP_VERIFY);

    }

Hoa\Console 项目多年前就被放弃了

 Execution PAUSED, starting interactive shell...
  Type in commands to try them:
  - ENTER to continue
  - TAB to auto-complete
  - F5 to stash a command
  - F6 to toggle auto-stashing of successful commands
  - F8 to view stashed commands
  - F10 to clear stashed commands

我仍然不知道暂停单元测试时该使用什么。任何用于搜索的见解/谷歌关键字都值得赞赏。

php codeception
1个回答
0
投票

我刚刚意识到

Hoa\Console
正在使用
readline()
来“暂停”该过程。

$otpCode = readline('Please input the OTP before run testVerifyOtp: ');

$verifyOtpResponse = $this->autopay->verifyOtp(
    $partnerReferenceNo,
    $response->referenceNo,
    $response->additionalInfo->chargeToken,
    (string) $otpCode,
);

codecept_debug($verifyOtpResponse);
$this->assertEquals($verifyOtpResponse->responseCode, self::RESP_CODE_OTP_VERIFY);
Please input the OTP before run testVerifyOtp: 364612
✔ AutopayTest: Verification flow (9.85s)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Time: 00:09.862, Memory: 10.00 MB

OK (1 test, 2 assertions)
© www.soinside.com 2019 - 2024. All rights reserved.