本文整理汇总了PHP中Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException::expected方法的典型用法代码示例。如果您正苦于以下问题:PHP InvalidArgumentException::expected方法的具体用法?PHP InvalidArgumentException::expected怎么用?PHP InvalidArgumentException::expected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pim\Bundle\CatalogBundle\Exception\InvalidArgumentException
的用法示例。
在下文中一共展示了InvalidArgumentException::expected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function it_fails_if_the_group_code_is_not_found($groupRepository, ProductInterface $product, GroupInterface $pack, GroupTypeInterface $nonVariantType)
{
$groupRepository->findOneByIdentifier('not valid code')->willReturn(null);
$pack->getType()->willReturn($nonVariantType);
$nonVariantType->isVariant()->willReturn(false);
$this->shouldThrow(InvalidArgumentException::expected('variant_group', 'existing variant group code', 'setter', 'variant_group', 'not valid code'))->during('setFieldData', [$product, 'variant_group', 'not valid code']);
}
示例2:
function it_fails_if_one_of_the_associated_group_does_not_exist($productBuilder, $groupRepository, ProductInterface $product, AssociationInterface $xsellAssociation)
{
$product->getAssociations()->willReturn([$xsellAssociation]);
$productBuilder->addMissingAssociations($product)->shouldBeCalled();
$product->getAssociationForTypeCode('xsell')->willReturn($xsellAssociation);
$groupRepository->findOneByIdentifier('not existing group')->willReturn(null);
$this->shouldThrow(InvalidArgumentException::expected('associations', 'existing group code', 'adder', 'association', 'not existing group'))->during('addFieldData', [$product, 'associations', ['xsell' => ['groups' => ['not existing group'], 'products' => []]]]);
}
示例3: addFieldFilter
/**
* {@inheritdoc}
*/
public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
{
if (!is_numeric($value) && !is_array($value)) {
throw InvalidArgumentException::expected($field, 'array or numeric value', 'filter', 'productId', $value);
}
$field = current($this->qb->getRootAliases()) . '.' . $field;
$condition = $this->prepareCriteriaCondition($field, $operator, $value);
$this->qb->andWhere($condition);
return $this;
}
示例4:
function it_fails_if_the_group_code_does_not_correspond_to_a_simple_group($groupRepository, ProductInterface $product, GroupInterface $pack, GroupInterface $variant, GroupTypeInterface $nonVariantType, GroupTypeInterface $variantType)
{
$groupRepository->findOneByIdentifier('pack')->willReturn($pack);
$pack->getType()->willReturn($nonVariantType);
$nonVariantType->isVariant()->willReturn(false);
$groupRepository->findOneByIdentifier('variant')->willReturn($variant);
$variant->getType()->willReturn($variantType);
$variantType->isVariant()->willReturn(true);
$this->shouldThrow(InvalidArgumentException::expected('groups', 'non variant group code', 'remover', 'groups', 'variant'))->during('removeFieldData', [$product, 'groups', ['pack', 'variant']]);
}
示例5: addFieldFilter
/**
* {@inheritdoc}
*/
public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
{
if (!is_string($value) && !is_array($value)) {
throw InvalidArgumentException::expected($field, 'array or string value', 'filter', 'productId', $value);
}
$field = '_id';
$value = is_array($value) ? $value : [$value];
$this->applyFilter($value, $field, $operator);
return $this;
}
示例6: setFieldData
/**
* {@inheritdoc}
*
* Expected data input format : "family_code"
*/
public function setFieldData(ProductInterface $product, $field, $data, array $options = [])
{
$this->checkData($field, $data);
if (null !== $data && '' !== $data) {
$family = $this->getFamily($data);
if (null === $family) {
throw InvalidArgumentException::expected($field, 'existing family code', 'setter', 'family', $data);
}
$product->setFamily($family);
} else {
$product->setFamily(null);
}
}
示例7: removeFieldData
/**
* {@inheritdoc}
*
* Expected data input format : ["category_code", "another_category_code"]
*/
public function removeFieldData(ProductInterface $product, $field, $data, array $options = [])
{
$this->checkData($field, $data);
$categories = [];
foreach ($data as $categoryCode) {
$category = $this->categoryRepository->findOneByIdentifier($categoryCode);
if (null === $category) {
throw InvalidArgumentException::expected($field, 'existing category code', 'remover', 'category', $categoryCode);
}
$categories[] = $category;
}
foreach ($categories as $categoryToRemove) {
$product->removeCategory($categoryToRemove);
}
}
示例8: addFieldData
/**
* {@inheritdoc}
*
* Expected data input format : ["group_code"]
*/
public function addFieldData(ProductInterface $product, $field, $data, array $options = [])
{
$this->checkData($field, $data);
$groups = [];
foreach ($data as $groupCode) {
$group = $this->groupRepository->findOneByIdentifier($groupCode);
if (null === $group) {
throw InvalidArgumentException::expected($field, 'existing group code', 'adder', 'groups', $groupCode);
} elseif ($group->getType()->isVariant()) {
throw InvalidArgumentException::expected($field, 'non variant group code', 'adder', 'groups', $groupCode);
} else {
$groups[] = $group;
}
}
foreach ($groups as $group) {
$product->addGroup($group);
}
}
示例9: addFieldFilter
/**
* Override to add new operator and to work on time
* {@inheritdoc}
*/
public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
{
if (static::GREATER_THAN_OR_EQUALS_WITH_TIME === $operator) {
if ($value instanceof \DateTime) {
$dateTimeValue = $value;
} else {
try {
$dateTimeValue = new \DateTime($value);
} catch (\Exception $e) {
throw InvalidArgumentException::expected($field, 'DateTime object or new DateTime() compatible string. Error:' . $e->getMessage(), 'filter', 'date_time', is_string($value) ? $value : gettype($value));
}
}
$normalizedField = sprintf('%s.%s', ProductQueryUtility::NORMALIZED_FIELD, $field);
$this->qb->field($normalizedField)->gte($dateTimeValue->getTimestamp());
} else {
parent::addFieldFilter($field, $operator, $value, $locale, $scope, $options);
}
}
示例10: setFieldData
/**
* {@inheritdoc}
*
* Expected data input format : ["group_code"]
*/
public function setFieldData(ProductInterface $product, $field, $data, array $options = [])
{
$this->checkData($field, $data);
$groups = [];
foreach ($data as $groupCode) {
$group = $this->groupRepository->findOneByIdentifier($groupCode);
if (null === $group) {
throw InvalidArgumentException::expected($field, 'existing group code', 'setter', 'groups', $groupCode);
} else {
$groups[] = $group;
}
}
$oldGroups = $product->getGroups();
foreach ($oldGroups as $group) {
$product->removeGroup($group);
}
foreach ($groups as $group) {
$product->addGroup($group);
}
}
示例11: setFieldData
/**
* {@inheritdoc}
*
* Expected data input format : ["category_code"]
*/
public function setFieldData(ProductInterface $product, $field, $data, array $options = [])
{
$this->checkData($field, $data);
$categories = [];
foreach ($data as $categoryCode) {
$category = $this->getCategory($categoryCode);
if (null === $category) {
throw InvalidArgumentException::expected($field, 'existing category code', 'setter', 'category', $categoryCode);
} else {
$categories[] = $category;
}
}
$oldCategories = $product->getCategories();
foreach ($oldCategories as $category) {
$product->removeCategory($category);
}
foreach ($categories as $category) {
$product->addCategory($category);
}
}
示例12: addFieldFilter
/**
* Override to add new operator and to work on time
* {@inheritdoc}
*/
public function addFieldFilter($field, $operator, $value, $locale = null, $scope = null, $options = [])
{
if (static::GREATER_THAN_OR_EQUALS_WITH_TIME === $operator) {
if ($value instanceof \DateTime) {
$dateTimeValue = $value;
} else {
try {
$dateTimeValue = new \DateTime($value);
} catch (\Exception $e) {
throw InvalidArgumentException::expected($field, 'DateTime object or new DateTime() compatible string. Error:' . $e->getMessage(), 'filter', 'date_time', is_string($value) ? $value : gettype($value));
}
}
$field = current($this->qb->getRootAliases()) . '.' . $field;
$utcDateTimeValue = new \DateTime();
$utcDateTimeValue->setTimezone(new \DateTimeZone('Etc/UTC'));
$utcDateTimeValue->setTimestamp($dateTimeValue->getTimestamp());
$this->qb->andWhere($this->qb->expr()->gte($field, $this->qb->expr()->literal($utcDateTimeValue->format('Y-m-d H:i:s'))));
} else {
parent::addFieldFilter($field, $operator, $value, $locale, $scope, $options);
}
}
示例13: setFieldData
/**
* {@inheritdoc}
*
* Expected data input format : "variant_group_code"
*/
public function setFieldData(ProductInterface $product, $field, $data, array $options = [])
{
$this->checkData($field, $data);
if (null !== $data) {
$variantGroup = $this->groupRepository->findOneByIdentifier($data);
if (null === $variantGroup) {
throw InvalidArgumentException::expected($field, 'existing variant group code', 'setter', 'variant_group', $data);
}
if (!$variantGroup->getType()->isVariant()) {
throw InvalidArgumentException::expected($field, 'variant group code', 'setter', 'variant_group', $data);
}
}
$existingGroups = $product->getGroups();
foreach ($existingGroups as $group) {
if ($group->getType()->isVariant()) {
$product->removeGroup($group);
}
}
if (null !== $data) {
$product->addGroup($variantGroup);
}
}
示例14:
function it_throws_an_error_if_attribute_data_is_not_a_valid_path(AttributeInterface $attribute, ProductInterface $product)
{
$attribute->getCode()->willReturn('attributeCode');
$data = ['filePath' => 'path/to/unknown/file', 'originalFilename' => 'image'];
$this->shouldThrow(InvalidArgumentException::expected('attributeCode', 'a valid pathname', 'setter', 'media', 'path/to/unknown/file'))->during('setAttributeData', [$product, $attribute, $data, ['locale' => 'fr_FR', 'scope' => 'mobile']]);
}
示例15:
function it_throws_an_exception_if_value_is_not_a_numeric_or_an_array()
{
$this->shouldThrow(InvalidArgumentException::expected('id', 'array or string value', 'filter', 'productId', 1234))->during('addFieldFilter', ['id', '=', 1234]);
}