public function testUploadActionWithValidationException() { $request = new Request(); $exception = FileValidationException::create(new \SplFileInfo(__FILE__), ['some error']); $this->teachContainer($request, true, $exception); $result = $this->ctr->uploadAction($request); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\JsonResponse', $result); $content = json_decode($result->getContent(), true); $this->assertArrayHasKey('success', $content); $this->assertFalse($content['success']); $this->assertArrayHasKey('error', $content); $this->assertArrayHasKey('errors', $content); $this->assertTrue(is_array($content['errors'])); $this->assertEquals(1, count($content['errors'])); $this->assertContains('some error', $content['errors'][0]); }
/** * {@inheritdoc} */ public function beforePut(\SplFileInfo $file, Repository $repository) { $config = $repository->getConfig(); $wrapper = new FileWrapper($file); if (isset($config['images_only']) && true === $config['images_only']) { $wrapper->addImageConstraint(); } if (isset($config['max_size']) && '' != $config['max_size']) { $wrapper->addFileConstraint(array('maxSize' => $config['max_size'])); } if (isset($config['file_constraint']) && is_array($config['file_constraint'])) { $wrapper->addFileConstraint($config['file_constraint']); } if (isset($config['image_constraint']) && is_array($config['image_constraint'])) { $wrapper->addImageConstraint($config['image_constraint']); } $errors = $wrapper->validate($this->validator); if (count($errors)) { throw FileValidationException::create($file, $errors, $repository); } }