Próbowałem przetestować plik move_uploaded_file i is_uploaded_file z PHPUnit i vfsStream. Zawsze zwracają fałsz.Test move_uploaded_file i is_uploaded_file z vfsStreamem
public function testShouldUploadAZipFileAndMoveIt()
{
$_FILES = array('fieldName' => array(
'name' => 'file.zip',
'type' => 'application/zip',
'tmp_name' => 'vfs://root/file.zip',
'error' => 0,
'size' => 0,
));
vfsStream::setup();
$vfsStreamFile = vfsStream::newFile('file.zip');
vfsStreamWrapper::getRoot()
->addChild($vfsStreamFile);
$vfsStreamDirectory = vfsStream::newDirectory('/destination');
vfsStreamWrapper::getRoot()
->addChild($vfsStreamDirectory);
$fileUpload = new File_Upload();
$fileUpload->upload(
vfsStream::url('root/file.zip'),
vfsStream::url('root/destination/file.zip')
);
$this->assertFileExists(vfsStream::url('root/destination/file.zip'));
}
Czy to możliwe? Jak mogę to zrobić? Czy mogę wysłać plik vfsStreamFile (lub dowolne dane) bez formularza, używając tylko kodu PHP? Dziękuję.
W jaki sposób testuje się jednostki za pomocą tych funkcji? Dzięki. – user972959
Nie mam pojęcia. Nigdy nie używałem phpunit. Jest tu trochę rzeczy: http://stackoverflow.com/questions/3402765/how-can-i-write-tests-for-file-upload-in-php, ale nie specjalnie dla phpunit. –