title: The class 'Symfony\\Component\\HttpFoundation\\File\\UploadedFile' was not found in the chain configured namespaces during Rest API Unit Test
body: <p>I'm writing a REST API client and I am trying to unit test the user creation process which let a user to upload an image.</p>
  
  <p>I am using Symfony 2.7, Doctrine Extension Bundle (Uploadable extension) and FOS Rest Bundle</p>
  
  <p>The unit tests are working well excepted when I try to upload a file, it triggers me the following error when I error_log the 500 HTTP Reponse : </p>
  
  <pre><code>The class 'Symfony\\Component\\HttpFoundation\\File\\UploadedFile' was not found in the chain configured namespaces 
  </code></pre>
  
  <p>Please find the relevant code :</p>
  
  <p><strong>UsersControllerTest.php</strong></p>
  
  <pre><code>&lt;?php
  namespace Acme\Bundle\UserBundle\Tests\Controller;
  
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
  use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  
  class UsersControllerTest extends WebTestCase
  {
      public function testAvatar(){
          $client = static::createClient();
  
          $shortImage = tempnam(sys_get_temp_dir(), 'upl');
          imagepng(imagecreatetruecolor(10, 10), $shortImage);
  
          $file = new UploadedFile(
              $shortImage,
              basename($shortImage),
              MimeTypeGuesser::getInstance()-&gt;guess($shortImage),
              filesize($shortImage)
          );
  
          $crawler = $client-&gt;request(
              "POST",
              "/api/users",
              array(
                  "user_registration" =&gt; array(
                      "firstName" =&gt; "test",          
                      "lastName" =&gt; "test"        
                  ),
              ),          
              array(
                  'user_registration'=&gt;array('avatar'=&gt;$file)
              ),          
              array(
                  'Content-Type' =&gt; 'multipart/formdata'
              )           
          );      
          error_log($client-&gt;getResponse()); //Here I see the Uploadable class namespace error
          $this-&gt;assertEquals(200, $client-&gt;getResponse()-&gt;getStatusCode());      
      }   
  }
  </code></pre>
  
  <p><strong>UserRegistrationType.php</strong></p>
  
  <pre><code>&lt;?php
  namespace Acme\Bundle\UserBundle\Form\Type;
  
  use Acme\Bundle\UserBundle\Entity\User;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\OptionsResolver\OptionsResolverInterface;
  use Symfony\Component\Form\FormBuilderInterface;
  
  class UserRegistrationType extends AbstractType{
  
      public function setDefaultOptions(OptionsResolverInterface $resolver)
      {
          $resolver-&gt;setDefaults(array(
              'data_class' =&gt; 'Acme\Bundle\UserBundle\Entity\User',
              'cascade_validation' =&gt; true,
              'csrf_protection' =&gt; false
          ));
      }
  
      public function buildForm(FormBuilderInterface $builder, array $options)
      {
          $builder-&gt;add('firstName', 'text');
          $builder-&gt;add('lastName', 'text');
          $builder-&gt;add('avatar', 'file', array(
              'required' =&gt; false
          ));
      }
  
      public function getParent()
      {
          return 'form';
      }
  
      public function getName()
      {
          return 'user_registration';
      }
  
  }
  </code></pre>
  
  <p><strong>UsersController.php</strong></p>
  
  <pre><code>&lt;?php
  namespace Acme\Bundle\UserBundle\Controller;
  
  use FOS\RestBundle\Controller\FOSRestController;
  use FOS\RestBundle\Controller\Annotations\View;
  use Acme\Bundle\UserBundle\Entity\User;
  use Acme\Bundle\UserBundle\Entity\Avatar;
  use Acme\Bundle\UserBundle\Form\Type\UserRegistrationType;
  use Symfony\Component\HttpFoundation\Request;
  use FOS\RestBundle\Controller\Annotations\RouteResource;
  use JMS\SecurityExtraBundle\Annotation as JMSSecurity;
  
  class UsersController extends FOSRestController
  {
  
      /**
       * @View(serializerGroups={"Registration"})
      */
      public function postUsersAction(Request $request){
          $user = new User();
  
          $form = $this-&gt;createForm(new UserRegistrationType(), $user);
          $form-&gt;submit($request);
  
  
          if ($form-&gt;isValid()) {                     
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $em-&gt;persist($user);
              if(null !== $user-&gt;getAvatar()){
                  $uploadableManager = $this-&gt;get('stof_doctrine_extensions.uploadable.manager');
                  $uploadableManager-&gt;markEntityToUpload($user, $user-&gt;getAvatar());                  
              }       
              $em-&gt;flush();           
              return $user;
          }
  
          else {
              $validator = $this-&gt;get('validator');
              $errors = $validator-&gt;validate($user, array('Default','Registration'));
              $view = $this-&gt;view($errors, 400);
              return $this-&gt;handleView($view);
          }
      }
  }
  </code></pre>
  
  <p><strong>Avatar.php</strong></p>
  
  <pre><code>&lt;?php
  
  namespace Acme\Bundle\UserBundle\Entity;
  
  use Doctrine\ORM\Mapping as ORM;
  use Gedmo\Mapping\Annotation as Gedmo;
  
  /**
   * Avatar
   *
   * @ORM\Table("avatar")
   * @ORM\Entity
   * @Gedmo\Uploadable(pathMethod="getPath", callback="postUploadAction", filenameGenerator="SHA1", allowOverwrite=true, appendNumber=true) 
   */
  class Avatar
  {
      /**
       * @var integer
       *
       * @ORM\Column(name="id", type="integer")
       * @ORM\Id
       * @ORM\GeneratedValue(strategy="AUTO")
       */
      private $id;
  
      /**
       * @ORM\Column(name="path", type="string")
       * @Gedmo\UploadableFilePath
       */
      private $path;
  
      /**
       * @ORM\Column(name="name", type="string")
       * @Gedmo\UploadableFileName
       */
      private $name;
  
      /**
       * @ORM\Column(name="mime_type", type="string")
       * @Gedmo\UploadableFileMimeType
       */
      private $mimeType;
  
      /**
       * @ORM\Column(name="size", type="decimal")
       * @Gedmo\UploadableFileSize
       */
      private $size;
  
  
      public function postUploadAction(array $info)
      {
          // Do some stuff with the file..
      }
  
  
      /**
       * Get id
       *
       * @return integer 
       */
      public function getId()
      {
          return $this-&gt;id;
      }
  
      public function getPath(){
          return __DIR__.'../../web/avatars/';
      }
  
      /**
       * Set path
       *
       * @param string $path
       * @return Image
       */
      public function setPath($path)
      {
          $this-&gt;path = $path;
  
          return $this;
      }
  
      /**
       * Set mimeType
       *
       * @param string $mimeType
       * @return Image
       */
      public function setMimeType($mimeType)
      {
          $this-&gt;mimeType = $mimeType;
  
          return $this;
      }
  
      /**
       * Get mimeType
       *
       * @return string
       */
      public function getMimeType()
      {
          return $this-&gt;mimeType;
      }
  
      /**
       * Set size
       *
       * @param string $size
       * @return Image
       */
      public function setSize($size)
      {
          $this-&gt;size = $size;
  
          return $this;
      }
  
      /**
       * Get size
       *
       * @return string
       */
      public function getSize()
      {
          return $this-&gt;size;
      }
  }
  </code></pre>
  
  <p><strong>User.php</strong>
      
  
  <pre><code>class User{
  
      ...
  
      /**
      * Avatar
      * 
      * @ORM\OneToOne(targetEntity="Acme\Bundle\UserBundle\Entity\Avatar", cascade={"all"})
      * @ORM\JoinColumn(nullable=true)
      * @Assert\Valid
      */
      private $avatar;
  
  
      public function getAvatar(){
          return $this-&gt;avatar;
      }
  
      public function setAvatar($avatar = null){
          $this-&gt;avatar = $avatar;
          return $this;
      }
  }
  </code></pre>
  
  <p><strong>Error stack (JSON)</strong>
  For full stack please see here : <a href="http://pastebin.com/sgPE4Uh1" rel="nofollow">http://pastebin.com/sgPE4Uh1</a></p>
  
  <pre><code>{
     "error":{
        "code":500,
        "message":"Internal Server Error",
        "exception":[
           {
              "message":"The class 'Symfony\\Component\\HttpFoundation\\File\\UploadedFile' was not found in the chain configured namespaces Acme\\Bundle\\UserBundle\\Entity",
              "class":"Doctrine\\Common\\Persistence\\Mapping\\MappingException",
              "trace":[
                 {
                    "namespace":"",
                    "short_class":"",
                    "class":"",
                    "type":"",
                    "function":"",
                    "file":"D:\\xampp\\htdocs\\RestApi\\vendor\\doctrine\\common\\lib\\Doctrine\\Common\\Persistence\\Mapping\\MappingException.php",
                    "line":37,
                    "args":[
  
                    ]
                 }]
          }
      }
  }
  </code></pre>
  
  <p>I really don't know the origin of the error, On my config.yml the doctrine mapping is set to auto</p>
  
  <p>Thank you in advance for any help</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>I have completely refactored the code with this scenario :</p>
  
  <p>The upload request is now independant, it has it own isolated request with a Content-Type set to multipart/form-data</p>
  
  <p>This time it would not have any problem, but..the same error is still here :</p>
  
  <pre><code>{
    code: 500
    message: "The class 'Symfony\Component\HttpFoundation\File\UploadedFile' was not found in the chain configured namespaces Sowq\Bundle\UserBundle\Entity"
  }
  </code></pre>
  
  <p>I am wondering if that's not a bug or a compatibility issue between Symfony 2.7 and the doctrine Uploadable extension, any idea?</p>