Completed
Push — master ( 37b207...7906ee )
by Helmut
37:09
created

TextTest   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 168
Duplicated Lines 30.36 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 16
c 1
b 0
f 0
lcom 2
cbo 2
dl 51
loc 168
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A it_can_be_rendered() 0 6 1
A it_renders_a_default_value() 0 6 1
A it_renders_model_values() 7 7 1
A it_can_fill_model_values() 10 10 1
A it_escapes_value() 0 6 1
A it_provides_expected_values() 0 7 1
A it_provides_expected_default_values() 0 7 1
A it_validates_required() 0 6 1
A it_validates_between() 0 9 1
A it_validates_min() 8 8 1
A it_validates_max() 8 8 1
A it_validates_alpha() 0 10 1
A it_validates_alpha_num() 0 12 1
A it_validates_alpha_dash() 0 13 1
A it_validates_in() 9 9 1
A it_validates_not_in() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Helmut\Forms\Testing;
4
5
class TextTest extends FormTestCase {
6
7
	/** @test */
8
	public function it_can_be_rendered()
9
	{
10
		$form = $this->form();
11
		$form->text('foo');
0 ignored issues
show
Documentation Bug introduced by
The method text does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
12
		$this->assertContains('<input name="foo" value=""', $form->render());
13
	}
14
15
	/** @test */
16
	public function it_renders_a_default_value()
17
	{
18
		$form = $this->form();
19
		$form->text('foo')->default('bar');
0 ignored issues
show
Documentation Bug introduced by
The method text does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
20
		$this->assertContains('<input name="foo" value="bar"', $form->render());
21
	}
22
23
	/** @test */
24 View Code Duplication
	public function it_renders_model_values()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
	{
26
		$form = $this->form();
27
		$form->defaults($this->model(['foo'=>'bar']));
28
		$form->text('foo');
0 ignored issues
show
Documentation Bug introduced by
The method text does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
29
		$this->assertContains('<input name="foo" value="bar"', $form->render());
30
	}
31
32
	/** @test */
33 View Code Duplication
	public function it_can_fill_model_values()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
	{
35
		$model = $this->model(['foo'=>'']);
36
37
		$form = $this->form();
38
		$form->text('foo')->default('bar');
0 ignored issues
show
Documentation Bug introduced by
The method text does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
39
		$form->fill($model);
40
41
		$form->assertEquals($model->foo, 'bar');
0 ignored issues
show
Documentation Bug introduced by
The method assertEquals does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
42
	}
43
44
	/** @test */
45
	public function it_escapes_value()
46
	{
47
		$form = $this->form();
48
		$form->text('foo')->default('bar&');
0 ignored issues
show
Documentation Bug introduced by
The method text does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
49
		$this->assertContains('<input name="foo" value="bar&amp;"', $form->render());
50
	}	
51
52
	/** @test */
53
	public function it_provides_expected_values()
54
	{
55
		$form = $this->form();
56
		$form->text('foo');
0 ignored issues
show
Documentation Bug introduced by
The method text does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
57
58
		$this->assertSame($form->get('foo'), '');
59
	}	
60
61
	/** @test */
62
	public function it_provides_expected_default_values()
63
	{
64
		$form = $this->form();
65
		$form->text('foo')->default('bar');
0 ignored issues
show
Documentation Bug introduced by
The method text does not exist on object<Helmut\Forms\Testing\Stubs\Form>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
66
67
		$this->assertSame($form->get('foo'), 'bar');
68
	}
69
70
	/** @test */
71
    public function it_validates_required()
72
    {
73
    	$this->assertValid(function($form) { $form->text('foo'); });
74
75
    	$this->assertNotValid(function($form) { $form->text('foo')->required(); });
76
	}
77
78
	/** @test */
79
    public function it_validates_between()
80
    {
81
    	$this->assertValid(function($form) { $form->text('foo')->between(5, 7); });
82
    	$this->assertValid(function($form) { $form->text('foo')->between(5, 7)->default('123456'); });
83
84
    	$this->assertNotValid(function($form) { $form->text('foo')->between(5, 7)->required(); });
85
    	$this->assertNotValid(function($form) { $form->text('foo')->between(5, 7)->default('123'); });
86
    	$this->assertNotValid(function($form) { $form->text('foo')->between(5, 7)->default('123456789'); });
87
	}
88
89
	/** @test */
90 View Code Duplication
    public function it_validates_min()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
    {
92
    	$this->assertValid(function($form) { $form->text('foo')->min(5); });
93
    	$this->assertValid(function($form) { $form->text('foo')->min(5)->default('123456789'); });
94
95
    	$this->assertNotValid(function($form) { $form->text('foo')->min(5)->required(); });
96
    	$this->assertNotValid(function($form) { $form->text('foo')->min(5)->default('123'); });
97
	}	
98
99
	/** @test */
100 View Code Duplication
    public function it_validates_max()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
    {
102
    	$this->assertValid(function($form) { $form->text('foo')->max(5); });
103
    	$this->assertValid(function($form) { $form->text('foo')->max(5)->default('123'); });
104
105
    	$this->assertNotValid(function($form) { $form->text('foo')->max(5)->required(); });
106
    	$this->assertNotValid(function($form) { $form->text('foo')->max(5)->default('123456789'); });
107
	}
108
109
	/** @test */
110
    public function it_validates_alpha()
111
    {
112
    	$this->assertValid(function($form) { $form->text('foo')->alpha(); });
113
    	$this->assertValid(function($form) { $form->text('foo')->alpha()->default('valid'); });
114
115
    	$this->assertNotValid(function($form) { $form->text('foo')->alpha()->required(); });
116
    	$this->assertNotValid(function($form) { $form->text('foo')->alpha()->default('inv@lid'); });
117
    	$this->assertNotValid(function($form) { $form->text('foo')->alpha()->default('123456'); });
118
    	$this->assertNotValid(function($form) { $form->text('foo')->alpha()->default('abc123'); });
119
	}
120
121
	/** @test */
122
    public function it_validates_alpha_num()
123
    {
124
    	$this->assertValid(function($form) { $form->text('foo')->alpha_num(); });
125
    	$this->assertValid(function($form) { $form->text('foo')->alpha_num()->default('valid'); });
126
    	$this->assertValid(function($form) { $form->text('foo')->alpha_num()->default('valid123'); });
127
    	$this->assertValid(function($form) { $form->text('foo')->alpha_num()->default('123'); });
128
129
    	$this->assertNotValid(function($form) { $form->text('foo')->alpha_num()->required(); });
130
    	$this->assertNotValid(function($form) { $form->text('foo')->alpha_num()->default('valid 123'); });
131
    	$this->assertNotValid(function($form) { $form->text('foo')->alpha_num()->default('valid_123'); });
132
    	$this->assertNotValid(function($form) { $form->text('foo')->alpha_num()->default('inv@lid123'); });
133
	}	
134
135
	/** @test */
136
    public function it_validates_alpha_dash()
137
    {
138
    	$this->assertValid(function($form) { $form->text('foo')->alpha_dash(); });
139
    	$this->assertValid(function($form) { $form->text('foo')->alpha_dash()->default('valid'); });
140
    	$this->assertValid(function($form) { $form->text('foo')->alpha_dash()->default('valid123'); });
141
    	$this->assertValid(function($form) { $form->text('foo')->alpha_dash()->default('valid-123'); });
142
    	$this->assertValid(function($form) { $form->text('foo')->alpha_dash()->default('valid_123'); });
143
    	$this->assertValid(function($form) { $form->text('foo')->alpha_dash()->default('123'); });
144
145
    	$this->assertNotValid(function($form) { $form->text('foo')->alpha_dash()->required(); });
146
    	$this->assertNotValid(function($form) { $form->text('foo')->alpha_dash()->default('valid 123'); });
147
    	$this->assertNotValid(function($form) { $form->text('foo')->alpha_dash()->default('inv@lid123'); });
148
	}
149
150
	/** @test */
151 View Code Duplication
    public function it_validates_in()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
    {
153
    	$this->assertValid(function($form) { $form->text('foo')->in(); });
154
    	$this->assertValid(function($form) { $form->text('foo')->in(['a', 'b','c']); });
155
    	$this->assertValid(function($form) { $form->text('foo')->in(['a', 'b','c'])->default('a'); });
156
157
    	$this->assertNotValid(function($form) { $form->text('foo')->in(['a', 'b','c'])->required(); });
158
    	$this->assertNotValid(function($form) { $form->text('foo')->in(['a', 'b','c'])->default('d'); });
159
	}
160
161
	/** @test */
162 View Code Duplication
    public function it_validates_not_in()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
163
    {
164
    	$this->assertValid(function($form) { $form->text('foo')->not_in(); });
165
    	$this->assertValid(function($form) { $form->text('foo')->not_in(['a', 'b','c']); });
166
    	$this->assertValid(function($form) { $form->text('foo')->not_in(['a', 'b','c'])->default('d'); });
167
168
    	$this->assertNotValid(function($form) { $form->text('foo')->not_in(['a', 'b','c'])->required(); });
169
    	$this->assertNotValid(function($form) { $form->text('foo')->not_in(['a', 'b','c'])->default('a'); });
170
	}	
171
172
}
173