/** * @covers ::vnsprintf * @expectedException InvalidArgumentException */ public function testThrowsExceptionWhenNamedParameterNotInArgs() { // ---------------------------------------------------------------- // setup your test $args = ['place' => 'the mat']; $format = "The %animal\$s sat on %place\$s"; // ---------------------------------------------------------------- // perform the change $actualResult = vnsprintf($format, $args); // ---------------------------------------------------------------- // test the results }
/** * our constructor * * You should call one of the 'newFromXXX()' methods to create a new * exception to throw. These methods customise the format string and * exception data for different contexts. * * @param string $formatString * the sprintf() format string for our human-readable message * @param array $data * the data required to sprintf() with $formatString * @param int $code * the error code that you want to set (if any) */ public function __construct($formatString, $data = [], $code = 0) { // remember our extra parameters $this->formatString = $formatString; $this->data = $data; // build the printable message // // this uses vnsprintf() from ganbarodigital/php-the-missing-bits // to support named parameters in the format string :) $message = vnsprintf($formatString, $data); parent::__construct($message, $code); }