当前位置: 首页>>代码示例>>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;未经允许,请勿转载。