1 | <?php |
||
12 | trait UploadedFileTestable |
||
13 | { |
||
14 | /** |
||
15 | * Create an instance of Illuminate\Http\UploadedFile for testing (param test=true). |
||
16 | * Before creating UploadedFile class check if file exists with assertFileExists($fullPath). |
||
17 | * @param string $fullPath |
||
18 | * @param string $mimeType if empty try to resolve mimeType automatically. |
||
19 | * @param int $errorCode default 0 (no error). |
||
20 | * For all possible values see Symfony\Component\HttpFoundation\File\UploadedFile::getErrorMessage() |
||
21 | * @return UploadedFile |
||
22 | * @throws \Symfony\Component\HttpFoundation\File\Exception\FileException |
||
23 | * @throws \Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException |
||
24 | */ |
||
25 | public function getUploadedFileForTest(string $fullPath, string $mimeType = '', int $errorCode = 0) : UploadedFile |
||
39 | |||
40 | /** |
||
41 | * Take $fullPath existing file, copy it to system temp dir with random name and |
||
42 | * Create an instance of Illuminate\Http\UploadedFile for testing (param test=true). |
||
43 | * Before creating UploadedFile class check if file exists with assertFileExists($fullPath). |
||
44 | * @param string $fullPath |
||
45 | * @param string $mimeType if empty try to resolve mimeType automatically. |
||
46 | * @param int $errorCode default 0 (no error). |
||
47 | * For all possible values see Symfony\Component\HttpFoundation\File\UploadedFile::getErrorMessage() |
||
48 | * @return UploadedFile |
||
49 | * @throws \Symfony\Component\HttpFoundation\File\Exception\FileException |
||
50 | * @throws \Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException |
||
51 | */ |
||
52 | public function getUploadedFileForTestAndCopyInSysTempDir( |
||
70 | } |
||
71 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.