핵심 PHP 함수를 도발하는 것은 조금 까다 롭습니다.
게시물 모델에 다음과 같이 표시되어 있습니다.
public function processFile($file)
{
if (is_uploaded_file($file)) {
//process the file
return true;
}
return false;
}
그리고 이와 같은 테스트가 있습니다.
public function testProcessFile()
{
$actual = $this->Posts->processFile('noFile');
$this->assertTrue($actual);
}
테스트 프로세스 중에 아무 것도 업로드하지 않으므로 테스트가 항상 실패합니다.
하나의 파일에 더 많은 네임 스페이스가있는 경우에도 PostsTableTest.php의 시작 부분에 두 번째 네임 스페이스를 추가해야합니다.
<?php
namespace {
// This allows us to configure the behavior of the "global mock"
// by changing its value you switch between the core PHP function and
// your implementation
$mockIsUploadedFile = false;
}
원래 네임 스페이스 선언이 중괄호 형식이어야합니다. http://www.apress.com/9781484212134
:
namespace App\Model\Table {
그리고 당신은 PHP 코어의 방법을 추가 할 수는
function is_uploaded_file()
{
global $mockIsUploadedFile;
if ($mockIsUploadedFile === true) {
return true;
} else {
return call_user_func_array('\is_uploaded_file',func_get_args());
}
}
//other model methods
} //this closes the second namespace declaration
여기 CakePHP의 단위 테스트에 대한 자세한을
을 덮어 쓸 수
출처
2016-09-19 12:58:18
rrd