我可以解释一下这个代码是如何重构的吗?期待将文件设置和请求触发器移动到设置部分,因为它不会一直改变。我一直在使用phpunit测试。
感谢任何帮助!
<?php
class OrdersControllerTest extends TestCase
{
public function setUp()
{
$this->resetInstance();
}
public function testEmptyOrderUpload() {
$filename = 'empty.pdf';
$filepath = APPPATH.'tests/fixtures/'.$filename;
$files = [
'order_file' => [
'name' => $filename,
'type' => 'pdf',
'tmp_name' => $filepath,
],
];
$this->request->setFiles($files);
$output = $this->request('POST', 'orders/upload');
$this->assertContains(500, $result->errors);
}
public function testValidOrderUpload() {
$filename = 'order.pdf';
$filepath = APPPATH.'tests/fixtures/'.$filename;
$files = [
'order_file' => [
'name' => $filename,
'type' => 'pdf',
'tmp_name' => $filepath,
],
];
$this->request->setFiles($files);
$output = $this->request('POST', 'orders/upload');
$this->assertContains(444, $result->errors);
}
}