对于PHP应用程序I m Developing,我需要阅读目前对SHA的轮值修订,当然,我可以通过使用壳体/外壳或背标语来实施该轮指挥线客户。
我显然把这一呼吁变成了自己的一种方法,以便我能够轻易地孤立起来,为我的单位测试的其余部分进行模拟。 因此,我的班子看着这样的情况:
class Task_Bundle
{
public function execute()
{
// Do things
$revision = $this->git_sha();
// Do more things
}
protected function git_sha()
{
return `git rev-parse --short HEAD`;
}
}
Of course, although I can test most of the class by mocking git_sha, I m struggling to see how to test the actual git_sha() method because I don t see a way to create a known state for it. I don t think there s any real value in a unit test that also calls git rev-parse
to compare the results? I was wondering about at least asserting that the command had been run, but I can t see any way to get a history of shell commands executed by PHP - even if I specify that PHP should use BASH rather than SH the history list comes up empty, I presume because the separate backticks executions are separate terminal sessions.
我很想知道,我会如何检验,或者说,在将来维持这种评估时,是否只是让这种方法未经测试和加以谨慎?