public function formatToFile(FieldSpec $spec, $value) { $slice = $spec->getSlice(); $paddingChar = $spec->getPaddingChar(); if (!in_array($paddingChar, array(' ', 0, '0', ''), true)) { $paddingChar = "'" . $paddingChar; } return sprintf(sprintf('%%%s%s%s%s', $paddingChar, $spec->getPaddingDirection() == FieldSpec::PADDING_DIRECTION_LEFT ? '' : '-', $slice->getWidth(), $spec->getFormatSpecifier()), $value); }
public function testGetters() { $default = $this->getFaker()->word; $formatSpecifier = $this->getFaker()->word; $name = $this->getFaker()->word; $slice = Slice::createFromString($this->getFaker()->numberBetween(0, 10) . ':' . $this->getFaker()->numberBetween(10, 20)); $paddingChar = $this->getFaker()->word; $paddingDirection = $this->getFaker()->word; $type = $this->getFaker()->word; $spec = new FieldSpec($name, $slice, $default, $formatSpecifier, $paddingChar, $paddingDirection, $type); $this->assertEquals($default, $spec->getDefault()); $this->assertEquals($formatSpecifier, $spec->getFormatSpecifier()); $this->assertEquals($name, $spec->getName()); $this->assertEquals($slice, $spec->getSlice()); $this->assertEquals($paddingChar, $spec->getPaddingChar()); $this->assertEquals($paddingDirection, $spec->getPaddingDirection()); $this->assertEquals($type, $spec->getType()); }