PHPUnit_Framework_Assert::assertStringMatchesFormat PHP Method

assertStringMatchesFormat() public static method

Asserts that a string matches a given format string.
public static assertStringMatchesFormat ( string $format, string $string, string $message = '' )
$format string
$string string
$message string
    public static function assertStringMatchesFormat($format, $string, $message = '')
    {
        if (!is_string($format)) {
            throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
        }
        if (!is_string($string)) {
            throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
        }
        $constraint = new PHPUnit_Framework_Constraint_StringMatches($format);
        static::assertThat($string, $constraint, $message);
    }

Usage Example

Example #1
0
 function run()
 {
     $raw = is_readable($this->file) ? file_get_contents($this->file) : '';
     $sections = array_values(array_filter(array_map('trim', preg_split('/^--(TEST|FILE|EXPECTF)--$/m', $raw))));
     if (3 === count($sections)) {
         list($this->name, $this->source, $this->expected) = $sections;
         try {
             $this->out = yay_parse($this->source);
             if (false !== strpos($this->name, '--pretty-print')) {
                 $this->out = yay_pretty($this->out) . PHP_EOL . PHP_EOL . '?>';
             }
         } catch (YayParseError $e) {
             $this->out = $e->getMessage();
             // $this->out = (string) $e;
         } catch (\PhpParser\Error $e) {
             $this->out = 'PHP ' . $e->getMessage();
             // $this->out = (string) $e;
         } catch (Exception $e) {
             $this->out = (string) $e;
         }
         try {
             Assert::assertStringMatchesFormat($this->expected, $this->out);
             $this->status = self::PASSED;
         } catch (Exception $e) {
             $this->status = self::FAILED;
             throw $e;
         }
     } else {
         $this->status = self::BORKED;
     }
 }
All Usage Examples Of PHPUnit_Framework_Assert::assertStringMatchesFormat
PHPUnit_Framework_Assert