Ejemplo n.º 1
0
 public function testFileBag()
 {
     $fileBag = new FileBag(['file' => ['name' => 'test.html', 'type' => 'text/html', 'tmp_name' => '/tmp/b', 'error' => UPLOAD_ERR_OK, 'size' => 123]]);
     $files = $fileBag->all();
     $this->assertEquals(['file' => new UploadedFile('test.html', 'text/html', '/tmp/b', 0, 123)], $files);
     $fileBag = new FileBag(['file' => ['name' => 'test.html', 'type' => 'text/html', 'tmp_name' => '/tmp/a', 'error' => UPLOAD_ERR_OK, 'size' => 123], 'name' => ['name' => 'test.html', 'type' => 'text/html', 'tmp_name' => '/tmp/b', 'error' => UPLOAD_ERR_OK, 'size' => 123]]);
     $this->assertEquals(['file' => new UploadedFile('test.html', 'text/html', '/tmp/a', 0, 123), 'name' => new UploadedFile('test.html', 'text/html', '/tmp/b', 0, 123)], $fileBag->all());
     $fileBag = new FileBag(['files' => ['name' => ['test.html', 'test2.html'], 'type' => ['text/html', 'text/html'], 'tmp_name' => ['/tmp/a', '/tmp/b'], 'error' => [UPLOAD_ERR_OK, UPLOAD_ERR_OK], 'size' => [123, 123]]]);
     $this->assertEquals(['files' => [new UploadedFile('test.html', 'text/html', '/tmp/a', 0, 123), new UploadedFile('test2.html', 'text/html', '/tmp/b', 0, 123)]], $fileBag->all());
     $fileBag = new FileBag(['files' => ['test' => ['test2' => ['name' => ['test.html', 'test2.html'], 'type' => ['text/html', 'text/html'], 'tmp_name' => ['/tmp/a', '/tmp/b'], 'error' => [UPLOAD_ERR_OK, UPLOAD_ERR_OK], 'size' => [123, 123]]]]]);
     $this->assertEquals($fileBag->all(), ['files' => ['test' => ['test2' => [new UploadedFile('test.html', 'text/html', '/tmp/a', 0, 123), new UploadedFile('test2.html', 'text/html', '/tmp/b', 0, 123)]]]]);
     $fileBag = new FileBag(['files' => ['test' => ['name' => ['test.html', 'test2.html'], 'type' => ['text/html', 'text/html'], 'tmp_name' => ['/tmp/a', '/tmp/b'], 'error' => [UPLOAD_ERR_OK, UPLOAD_ERR_OK], 'size' => [123, 123]]]]);
     $this->assertEquals($fileBag->all(), ['files' => ['test' => [new UploadedFile('test.html', 'text/html', '/tmp/a', 0, 123), new UploadedFile('test2.html', 'text/html', '/tmp/b', 0, 123)]]]);
 }
Ejemplo n.º 2
0
 /**
  * Create a new instance with the specified uploaded files.
  *
  * This method MUST be implemented in such a way as to retain the
  * immutability of the message, and MUST return an instance that has the
  * updated body parameters.
  *
  * @param array $uploadedFiles An array tree of UploadedFileInterface instances.
  * @return static
  * @throws InvalidArgumentException if an invalid structure is provided.
  */
 public function withUploadedFiles(array $uploadedFiles)
 {
     $this->file->initUploadedFiles($uploadedFiles);
     return $this;
 }