0
私は文字列を返すことができる簡単な方法get_db_password()
を持っています。あるいは、状況によってはnull
を返すことができます。いずれの場合も有効な応答と見なすべきです。
私が実際にテストしているのは、ゲッターが呼び出されたときにスクリプトが爆発しないということです。
get_db_password()
を呼び出して、スクリプトが終了しなかったこと、または応答がnull
または文字列であるかどうかをテストできることを主張するテスト/アサーションをどのように書くことができますか。例えば何かphpunitで有効な複数の値をテストするにはどうすればよいですか?
$this->assertInternalType("string || null", $this->config->get_db_password());
ソースコード
<?php
class Config {
/** @var string $db_password stored the database password */
private $db_password;
public function __construct() {
$this->db_password = require(PROJ_DIR . "config/productions.php");
}
/** @return string
*/
public function get_db_password() {
return $this->db_password;
}
}
テストコード
<?php
class ConfigTest extends PHPUnit\Framework\TestCase {
public $config;
public function test_get_db_password_returns_a_string_or_null() {
$this->config = new Config;
// how can I write this test?
$this->assertInternalType('string || null', $this->config->get_db_password());
}
}