/** * Configure generate options * * @param OptionsResolver $resolver */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setRequired(array('code', 'type', 'format'))->setDefined(array('width', 'height', 'color'))->setDefaults(array('width' => function (Options $options) { return Type::getDimension($options['type']) == '2D' ? 5 : 2; }, 'height' => function (Options $options) { return Type::getDimension($options['type']) == '2D' ? 5 : 30; }, 'color' => function (Options $options) { return $options['format'] == 'png' ? array(0, 0, 0) : 'black'; })); $allowedTypes = array('code' => array('string'), 'type' => array('string'), 'format' => array('string'), 'width' => array('integer'), 'height' => array('integer'), 'color' => array('string', 'array')); foreach ($allowedTypes as $typeName => $typeValue) { $resolver->setAllowedTypes($typeName, $typeValue); } $allowedValues = array('type' => array_merge(Type::$oneDimensionalBarcodeType, Type::$twoDimensionalBarcodeType), 'format' => array('html', 'png', 'svg')); foreach ($allowedValues as $valueName => $value) { $resolver->setAllowedValues($valueName, $value); } }
/** * testConfigureOptions * * @expectedException \InvalidArgumentException */ public function testInvalidArgumentException() { $type = new Type(); $type->getDimension('Unknown Type'); }