Completed
Pull Request — master (#6)
by Jefersson
07:01
created

RegexTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 45
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A it_should_assert_given_regex_on_content() 0 6 1
A it_should_not_assert_given_regex_on_content() 0 6 1
A valid_regex_and_content() 0 12 1
A invalid_regex_and_content() 0 7 1
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
namespace DocHeaderTest\Validator;
19
20
use DocHeader\Validator\Regex;
21
22
/**
23
 * Tests for {@see \DocHeader\Validator\Regex}.
24
 *
25
 * @group   Unitary
26
 * @author  Jefersson Nathan <[email protected]>
27
 * @license MIT
28
 *
29
 * @covers  \DocHeader\Validator\Regex
30
 */
31
final class RegexTest extends \PHPUnit_Framework_TestCase
32
{
33
    /**
34
     * @test
35
     * @dataProvider valid_regex_and_content
36
     */
37
    public function it_should_assert_given_regex_on_content($regex, $content)
38
    {
39
        $filter = new Regex($regex);
40
41
        $this->assertTrue($filter->__invoke($content));
42
    }
43
44
    /**
45
     * @test
46
     * @dataProvider invalid_regex_and_content
47
     */
48
    public function it_should_not_assert_given_regex_on_content($regex, $content)
49
    {
50
        $filter = new Regex($regex);
51
52
        $this->assertFalse($filter->__invoke($content));
53
    }
54
55
    public function valid_regex_and_content()
56
    {
57
        return [
58
            'Space around content' => ['Heya %re:\d{2}+%', '             Heya 12            '],
59
            'Content' => ['Heya %re:\d{2}+%', 'If you are reading it? Heya 12, you should buy me sushi.'],
60
            'Number' => ['Heya %re:\d{2}+%', 'Heya 12'],
61
            'Mixed chars' => ['Heya %re:\d{2}-\d{1}\w\s+%', 'Heya 12-1a '],
62
            'Year format' => ['Heya %re:20\d{2}%', 'Heya 2020'],
63
            'Year format 2' => ['Heya 20%re:\d{2}%', 'Heya 2020'],
64
            'Year format 3' => ['Heya %re:20\d{2}%-%year%', 'Heya 2020-%year%'],
65
        ];
66
    }
67
68
    public function invalid_regex_and_content()
69
    {
70
        return [
71
            'Space around content' => ['Heya %re:\d{2}+%', '             Heya 1 23            '],
72
            'Content' => ['Heya %re:\d{2}+%', 'If you are reading it? Heya 1a2, you should buy me sushi.'],
73
        ];
74
    }
75
}
76