當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ValidatorInterface::expects方法代碼示例

本文整理匯總了PHP中Symfony\Component\Validator\Validator\ValidatorInterface::expects方法的典型用法代碼示例。如果您正苦於以下問題:PHP ValidatorInterface::expects方法的具體用法?PHP ValidatorInterface::expects怎麽用?PHP ValidatorInterface::expects使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Validator\Validator\ValidatorInterface的用法示例。


在下文中一共展示了ValidatorInterface::expects方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testCreateUserWithDisabledValidationWillProceedImmediatelyToSave

 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);
 }
開發者ID:Nakard,項目名稱:hexagonal_phonebook,代碼行數:7,代碼來源:CreateUserTest.php

示例2: testAddNumberToUserValidationPassesWillProceedToSaveUser

 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);
 }
開發者ID:Nakard,項目名稱:hexagonal_phonebook,代碼行數:8,代碼來源:EditPhoneNumberTest.php

示例3: testProcessWithAllowedExtraFields

 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());
 }
開發者ID:ddeboer,項目名稱:data-import,代碼行數:11,代碼來源:ValidatorStepTest.php

示例4: testValidationErrorsInStrictMode

 /**
  * @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));
 }
開發者ID:AAstakhov,項目名稱:FOSRestBundle,代碼行數:14,代碼來源:ParamFetcherTest.php

示例5: testGetLocaleFromRequest

 /**
  * @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));
 }
開發者ID:anime-db,項目名稱:app-bundle,代碼行數:27,代碼來源:RequestTest.php

示例6: downloadImageFieldRemote

 /**
  * 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);
 }
開發者ID:anime-db,項目名稱:app-bundle,代碼行數:44,代碼來源:DownloaderTest.php


注:本文中的Symfony\Component\Validator\Validator\ValidatorInterface::expects方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。