StringFilterTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 9 1
A testFilter() 0 11 1
1
<?php
2
3
/**
4
 * @file
5
 * Grafizzi\Graph\Tests\StringFilterTest: a component of the Grafizzi library.
6
 *
7
 * (c) 2012 Frédéric G. MARAND <[email protected]>
8
 *
9
 * Grafizzi is free software: you can redistribute it and/or modify it under the
10
 * terms of the GNU Lesser General Public License as published by the Free
11
 * Software Foundation, either version 3 of the License, or (at your option) any
12
 * later version.
13
 *
14
 * Grafizzi is distributed in the hope that it will be useful, but WITHOUT ANY
15
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
 * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17
 * details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public License
20
 * along with Grafizzi, in the COPYING.LESSER.txt file.  If not, see
21
 * <http://www.gnu.org/licenses/>
22
 */
23
24
namespace Grafizzi\Graph\Tests;
25
26
require 'vendor/autoload.php';
27
28
use Grafizzi\Graph\Filter\StringFilter;
29
30
/**
31
 * StringFilter test case.
32
 */
33
class StringFilterTest extends BaseFilterTest {
34
35
  /**
36
   * String to copy to.
37
   *
38
   * @var string
39
   */
40
  private $out = 'initial data';
41
42
  /**
43
   * Prepares the environment before running a test.
44
   */
45
  protected function setUp() : void {
46
    parent::setUp();
47
    $this->filters[] = new StringFilter();
48
    $args = array(
49
      'out' => &$this->out,
50
      'callback' => function ($x) { return strrev($x) ; },
51
    );
52
    $this->filters[] = new StringFilter($args);
53
  }
54
55
  /**
56
   * Tests StringFilter->filter()
57
   */
58
  public function testFilter() {
59
    $in = 'String test';
60
    list($stdout, $err) = $this->filters[0]->filter($in);
61
    $this->assertEquals($in, $stdout, 'String filter returns its input.');
62
63
    list($stdout, $err) = $this->filters[1]->filter($in);
64
    $expected = strrev($in);
65
    $this->assertEquals($expected, $stdout, 'String filter with callback applies it.');
66
    $this->assertEquals($expected, $this->out, 'String filter with out string assigns it.');
67
    $this->assertEmpty($err, 'String filter does not return errors');
68
  }
69
}
70