Symfony\Component\HttpKernel\Client::filterFiles PHP Method

filterFiles() protected method

This method created test instances of UploadedFile so that the move() method can be called on those instances. If the size of a file is greater than the allowed size (from php.ini) then an invalid UploadedFile is returned with an error set to UPLOAD_ERR_INI_SIZE.
See also: UploadedFile
protected filterFiles ( array $files ) : array
$files array An array of files
return array An array with all uploaded files marked as already moved
    protected function filterFiles(array $files)
    {
        $filtered = array();
        foreach ($files as $key => $value) {
            if (is_array($value)) {
                $filtered[$key] = $this->filterFiles($value);
            } elseif ($value instanceof UploadedFile) {
                if ($value->isValid() && $value->getSize() > UploadedFile::getMaxFilesize()) {
                    $filtered[$key] = new UploadedFile(
                        '',
                        $value->getClientOriginalName(),
                        $value->getClientMimeType(),
                        0,
                        UPLOAD_ERR_INI_SIZE,
                        true
                    );
                } else {
                    $filtered[$key] = new UploadedFile(
                        $value->getPathname(),
                        $value->getClientOriginalName(),
                        $value->getClientMimeType(),
                        $value->getClientSize(),
                        $value->getError(),
                        true
                    );
                }
            }
        }

        return $filtered;
    }

Usage Example

Example #1
0
 /**
  * Make sure files are \Illuminate\Http\UploadedFile instances with the private $test property set to true.
  * Fixes issue https://github.com/Codeception/Codeception/pull/3417.
  *
  * @param array $files
  * @return array
  */
 protected function filterFiles(array $files)
 {
     $files = parent::filterFiles($files);
     if (!class_exists('Illuminate\\Http\\UploadedFile')) {
         // The \Illuminate\Http\UploadedFile class was introduced in Laravel 5.2.15,
         // so don't change the $files array if it does not exist.
         return $files;
     }
     $filtered = [];
     foreach ($files as $key => $file) {
         $filtered[$key] = UploadedFile::createFromBase($file, true);
     }
     return $filtered;
 }