public function testCreateUserWithDisabledValidationWillProceedImmediatelyToSave()
 {
     $user = $this->createExampleUser();
     $this->validatorMock->expects($this->never())->method('validate');
     $this->repositoryMock->expects($this->once())->method('save')->with($user);
     $this->useCase->createUser($user, false);
 }
 public function testAddNumberToUserValidationPassesWillProceedToSaveUser()
 {
     $number = $this->createExamplePhoneNumber();
     $this->repositoryMock->expects($this->once())->method('findById')->with(100)->will($this->returnValue($number));
     $this->validatorMock->expects($this->once())->method('validate')->with($number)->will($this->returnValue(new ConstraintViolationList()));
     $this->repositoryMock->expects($this->once())->method('save')->with($number);
     $this->useCase->editPhoneNumber($number);
 }
Esempio n. 3
0
 public function testProcessWithAllowedExtraFields()
 {
     $this->filter->addOption('allowExtraFields', true);
     $data = ['title' => null, 'telephone' => '0155/555-555'];
     $this->filter->add('title', $constraint = new Constraints\NotNull());
     $list = new ConstraintViolationList();
     $list->add($this->buildConstraintViolation());
     $this->validator->expects($this->once())->method('validate')->willReturn($list);
     $this->assertFalse($this->filter->process($data));
     $this->assertEquals([1 => $list], $this->filter->getViolations());
 }
 /**
  * @expectedException Symfony\Component\HttpKernel\Exception\BadRequestHttpException
  * @expectedMessage expected exception.
  */
 public function testValidationErrorsInStrictMode()
 {
     $param = $this->createMockedParam('foo', null, [], false, null, ['constraint']);
     list($fetcher, $method) = $this->getFetcherToCheckValidation($param);
     $errors = $this->getMock(ConstraintViolationListInterface::class);
     $errors->expects($this->once())->method('count')->willReturn(1);
     $this->validator->expects($this->once())->method('validate')->with('value', array('constraint'))->willReturn($errors);
     $this->violationFormatter->expects($this->once())->method('formatList')->with($param, $errors)->willReturn('expected exception.');
     $method->invokeArgs($fetcher, array($param, 'value', true));
 }
Esempio n. 5
0
 /**
  * @dataProvider getLanguages
  *
  * @param array $languages
  * @param string $expected
  * @param string $locale
  */
 public function testGetLocaleFromRequest(array $languages, $expected, $locale = '')
 {
     /* @var $request \PHPUnit_Framework_MockObject_MockObject|HttpRequest */
     $request = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\Request')->disableOriginalConstructor()->getMock();
     $request->expects($this->once())->method('getLanguages')->will($this->returnValue($languages));
     $request->expects($locale ? $this->once() : $this->never())->method('getLocale')->will($this->returnValue($locale));
     // validate languages
     $that = $this;
     for ($i = 0; $i < count($languages); ++$i) {
         $this->validator->expects($this->at($i))->method('validate')->will($this->returnCallback(function ($language, $constraint) use($that, $i, $languages, $locale) {
             $that->assertEquals($languages[$i], $language);
             $that->assertInstanceOf('\\Symfony\\Component\\Validator\\Constraints\\Locale', $constraint);
             $list = $that->getMock('\\Symfony\\Component\\Validator\\ConstraintViolationListInterface');
             $list->expects($that->once())->method('has')->will($this->returnValue($i + 1 < count($languages) || $locale))->with(0);
             return $list;
         }));
     }
     $listener = new Request($this->translatable, $this->translator, $this->validator, '');
     $this->assertEquals($expected, $listener->getLocale($request));
 }
Esempio n. 6
0
 /**
  * Download image field remote.
  *
  * @param bool $toggle
  * @param string $message
  */
 protected function downloadImageFieldRemote($toggle, $message = '')
 {
     $that = $this;
     $file = 'foo.txt';
     $path = 'bar';
     $target = $this->dir . $path . '/' . $file;
     $remote = $toggle ? 'http://example.com/test/' . $file : '';
     $url = $toggle ? '' : 'http://example.com/test/' . $file;
     mkdir($this->dir . $path, 0755, true);
     file_put_contents($target, base64_decode(self::IMAGE));
     $entity = $this->getImageFieldRemote($remote, $url);
     $entity->expects($this->once())->method('setFilename')->with($file);
     $entity->expects($this->atLeastOnce())->method('getFilename')->will($this->returnValue($file));
     $entity->expects($this->once())->method('getDownloadPath')->will($this->returnValue($path));
     $entity->expects($this->once())->method('setLocal')->will($this->returnCallback(function ($uploaded_file) use($that, $target, $file) {
         // test uploaded file
         /* @var $uploaded_file UploadedFile */
         $that->assertInstanceOf('\\Symfony\\Component\\HttpFoundation\\File\\UploadedFile', $uploaded_file);
         $that->assertEquals($target, $uploaded_file->getPathname());
         $that->assertEquals($file, $uploaded_file->getClientOriginalName());
         $that->assertEquals(getimagesize($target)['mime'], $uploaded_file->getClientMimeType());
         $that->assertEquals(filesize($target), $uploaded_file->getClientSize());
         $that->assertEquals(UPLOAD_ERR_OK, $uploaded_file->getError());
     }));
     $entity->expects($message ? $this->never() : $this->once())->method('clear');
     // validation
     $list = $this->getMock('\\Symfony\\Component\\Validator\\ConstraintViolationListInterface');
     $list->expects($this->once())->method('has')->will($this->returnValue((bool) $message))->with(0);
     if ($message) {
         $error = $this->getMock('\\Symfony\\Component\\Validator\\ConstraintViolationInterface');
         $error->expects($this->once())->method('getMessage')->will($this->returnValue($message));
         $list->expects($this->once())->method('get')->will($this->returnValue($error))->with(0);
     }
     $this->validator->expects($this->once())->method('validate')->will($this->returnValue($list))->with($entity);
     $this->download($this->dir . $path . '/' . $file, true, $url ?: $remote);
     // test
     $this->downloader->imageField($entity, $url, true);
 }