~tcuthbert/wordpress/openstack-objectstorage

« back to all changes in this revision

Viewing changes to vendor/phpunit/phpunit/src/Framework/Constraint/PCREMatch.php

  • Committer: Jacek Nykis
  • Date: 2015-02-11 15:35:31 UTC
  • Revision ID: jacek.nykis@canonical.com-20150211153531-hmy6zi0ov2qfkl0b
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * This file is part of PHPUnit.
 
4
 *
 
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 
6
 *
 
7
 * For the full copyright and license information, please view the LICENSE
 
8
 * file that was distributed with this source code.
 
9
 */
 
10
 
 
11
/**
 
12
 * Constraint that asserts that the string it is evaluated for matches
 
13
 * a regular expression.
 
14
 *
 
15
 * Checks a given value using the Perl Compatible Regular Expression extension
 
16
 * in PHP. The pattern is matched by executing preg_match().
 
17
 *
 
18
 * The pattern string passed in the constructor.
 
19
 *
 
20
 * @package    PHPUnit
 
21
 * @subpackage Framework_Constraint
 
22
 * @author     Sebastian Bergmann <sebastian@phpunit.de>
 
23
 * @author     Bernhard Schussek <bschussek@2bepublished.at>
 
24
 * @copyright  Sebastian Bergmann <sebastian@phpunit.de>
 
25
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 
26
 * @link       http://www.phpunit.de/
 
27
 * @since      Class available since Release 3.0.0
 
28
 */
 
29
class PHPUnit_Framework_Constraint_PCREMatch extends PHPUnit_Framework_Constraint
 
30
{
 
31
    /**
 
32
     * @var string
 
33
     */
 
34
    protected $pattern;
 
35
 
 
36
    /**
 
37
     * @param string $pattern
 
38
     */
 
39
    public function __construct($pattern)
 
40
    {
 
41
        parent::__construct();
 
42
        $this->pattern = $pattern;
 
43
    }
 
44
 
 
45
    /**
 
46
     * Evaluates the constraint for parameter $other. Returns true if the
 
47
     * constraint is met, false otherwise.
 
48
     *
 
49
     * @param  mixed $other Value or object to evaluate.
 
50
     * @return bool
 
51
     */
 
52
    protected function matches($other)
 
53
    {
 
54
        return preg_match($this->pattern, $other) > 0;
 
55
    }
 
56
 
 
57
    /**
 
58
     * Returns a string representation of the constraint.
 
59
     *
 
60
     * @return string
 
61
     */
 
62
    public function toString()
 
63
    {
 
64
        return sprintf(
 
65
            'matches PCRE pattern "%s"',
 
66
            $this->pattern
 
67
        );
 
68
    }
 
69
}