public function testInvalidFieldValueInMultipleValues() { $constraint = new ConfigValue(['name' => 'fooz']); $values = [MultiFoo::FOOZ, MultiFoo::BARZ * 100, MultiFoo::BAZZ]; $this->context->expects($this->once())->method('addViolation')->with($constraint->message); $this->validator->validate($values, $constraint); }
/** * @param string $sku * @param Product|null $product * @dataProvider validateProvider */ public function testValidate($sku, $product) { /** @var \PHPUnit_Framework_MockObject_MockObject|ProductRepository */ $repository = $this->getMockBuilder('OroB2B\\Bundle\\ProductBundle\\Entity\\Repository\\ProductRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->once())->method('findOneBySku')->with($sku)->will($this->returnValue($product)); $this->registry->expects($this->once())->method('getRepository')->with(self::PRODUCT_CLASS)->will($this->returnValue($repository)); $this->context->expects($product ? $this->never() : $this->once())->method('addViolation')->with($this->constraint->message); $this->validator->validate($sku, $this->constraint); }
public function testIsRegionValid() { /** @var \PHPUnit_Framework_MockObject_MockObject|Country $country */ $country = $this->getMockBuilder('Oro\\Bundle\\AddressBundle\\Entity\\Country')->disableOriginalConstructor()->getMock(); $country->expects($this->once())->method('hasRegions')->will($this->returnValue(true)); $country->expects($this->once())->method('getName')->will($this->returnValue('Country')); $this->context->expects($this->once())->method('getPropertyPath')->will($this->returnValue('test')); $this->context->expects($this->once())->method('addViolationAt')->with('test.region', $this->constraint->message, ['{{ country }}' => 'Country']); $address = $this->createAddress(); $address->setCountry($country); $this->validator->validate($address, $this->constraint); }
protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group = null) { switch ($this->getApiVersion()) { case Validation::API_VERSION_2_4: $this->context->expects($this->at($i))->method('validateValue')->with($value, $constraints, $propertyPath, $group); break; case Validation::API_VERSION_2_5: case Validation::API_VERSION_2_5_BC: $contextualValidator = $this->context->getValidator()->inContext($this->context); $contextualValidator->expects($this->at(2 * $i))->method('atPath')->with($propertyPath)->will($this->returnValue($contextualValidator)); $contextualValidator->expects($this->at(2 * $i + 1))->method('validate')->with($value, $constraints, $group); break; } }
protected function expectValidateAt($i, $propertyPath, $value, $group) { switch ($this->getApiVersion()) { case Validation::API_VERSION_2_4: $this->context->expects($this->at($i))->method('validate')->with($value, $propertyPath, $group); break; case Validation::API_VERSION_2_5: case Validation::API_VERSION_2_5_BC: $validator = $this->context->getValidator()->inContext($this->context); $validator->expects($this->at(2 * $i))->method('atPath')->with($propertyPath)->will($this->returnValue($validator)); $validator->expects($this->at(2 * $i + 1))->method('validate')->with($value, $this->logicalOr(null, array(), $this->isInstanceOf('\\Symfony\\Component\\Validator\\Constraints\\Valid')), $group); break; } }
/** * @param string $message * @param string $path */ protected function assertViolationCall($message, $path) { $violation = $this->getMock('Symfony\\Component\\Validator\\Violation\\ConstraintViolationBuilderInterface'); $violation->expects($this->any())->method('atPath')->with('[' . $path . ']')->will($this->returnSelf()); $this->context->expects($this->once())->method('buildViolation')->with($message)->will($this->returnValue($violation)); }
protected function expectValidateValueAt($i, $propertyPath, $value, $constraints, $group) { $this->context->expects($this->at($i))->method('validateValue')->with($value, $constraints, $propertyPath, $group); }