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

NumberTest::it_validates_between()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
nc 1
cc 1
eloc 8
nop 0
1
<?php
2
3
namespace Helmut\Forms\Testing;
4
5
class NumberTest extends FormTestCase {
6
7
	/** @test */
8
	public function it_can_be_rendered()
9
	{
10
		$form = $this->form();
11
		$form->number('foo');
0 ignored issues
show
Documentation Bug introduced by
The method number 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->number('foo')->default('123');
0 ignored issues
show
Documentation Bug introduced by
The method number 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="123"', $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->number('foo');
0 ignored issues
show
Documentation Bug introduced by
The method number 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->number('foo')->default('bar');
0 ignored issues
show
Documentation Bug introduced by
The method number 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->number('foo')->default('123&');
0 ignored issues
show
Documentation Bug introduced by
The method number 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="123&amp;"', $form->render());
50
	}	
51
52
	/** @test */
53
	public function it_provides_expected_values()
54
	{
55
		$form = $this->form();
56
		$form->number('foo');
0 ignored issues
show
Documentation Bug introduced by
The method number 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->number('foo')->default('123');
0 ignored issues
show
Documentation Bug introduced by
The method number 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'), '123');
68
	}
69
70
	/** @test */
71
    public function it_validates_required()
72
    {
73
    	$this->assertValid(function($form) { $form->number('foo'); });
74
75
    	$this->assertNotValid(function($form) { $form->number('foo')->required(); });
76
	}
77
78
	/** @test */
79
    public function it_validates_numeric()
80
    {
81
    	$this->assertValid(function($form) { $form->number('foo')->default(123); });
82
83
    	$this->assertNotValid(function($form) { $form->number('foo')->default('abc'); });
84
	}	
85
86
	/** @test */
87
    public function it_validates_between()
88
    {
89
    	$this->assertValid(function($form) { $form->number('foo')->between(5, 7); });
90
    	$this->assertValid(function($form) { $form->number('foo')->between(5, 7)->default('5'); });
91
    	$this->assertValid(function($form) { $form->number('foo')->between(5, 7)->default('6'); });
92
    	$this->assertValid(function($form) { $form->number('foo')->between(5, 7)->default('7'); });
93
94
    	$this->assertNotValid(function($form) { $form->number('foo')->between(5, 7)->required(); });
95
    	$this->assertNotValid(function($form) { $form->number('foo')->between(5, 7)->default('3'); });
96
    	$this->assertNotValid(function($form) { $form->number('foo')->between(5, 7)->default('12'); });
97
	}
98
99
	/** @test */
100
    public function it_validates_min()
101
    {
102
    	$this->assertValid(function($form) { $form->number('foo')->min(5); });
103
    	$this->assertValid(function($form) { $form->number('foo')->min(5)->default(5); });
104
    	$this->assertValid(function($form) { $form->number('foo')->min(5)->default(10); });
105
106
    	$this->assertNotValid(function($form) { $form->number('foo')->min(5)->required(); });
107
    	$this->assertNotValid(function($form) { $form->number('foo')->min(5)->default(3); });
108
    	$this->assertNotValid(function($form) { $form->number('foo')->min(5)->default(-5); });
109
	}	
110
111
	/** @test */
112
    public function it_validates_max()
113
    {
114
    	$this->assertValid(function($form) { $form->number('foo')->max(5); });
115
    	$this->assertValid(function($form) { $form->number('foo')->max(5)->default(3); });
116
    	$this->assertValid(function($form) { $form->number('foo')->max(5)->default(5); });
117
118
    	$this->assertNotValid(function($form) { $form->number('foo')->max(5)->required(); });
119
    	$this->assertNotValid(function($form) { $form->number('foo')->max(5)->default(5.1); });
120
    	$this->assertNotValid(function($form) { $form->number('foo')->max(5)->default(10); });
121
    	$this->assertNotValid(function($form) { $form->number('foo')->max(5)->default(12345); });
122
	}
123
124
	/** @test */
125
    public function it_validates_integer()
126
    {
127
    	$this->assertValid(function($form) { $form->number('foo')->integer(); });
128
    	$this->assertValid(function($form) { $form->number('foo')->integer()->default(4); });
129
    	$this->assertValid(function($form) { $form->number('foo')->integer()->default('4'); });
130
131
    	$this->assertNotValid(function($form) { $form->number('foo')->integer()->required(); });
132
    	$this->assertNotValid(function($form) { $form->number('foo')->integer()->default(10.3); });
133
    	$this->assertNotValid(function($form) { $form->number('foo')->integer()->default(1/3); });
134
    	$this->assertNotValid(function($form) { $form->number('foo')->integer()->default('10.2'); });
135
	}
136
137
	/** @test */
138 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...
139
    {
140
    	$this->assertValid(function($form) { $form->number('foo')->in(); });
141
    	$this->assertValid(function($form) { $form->number('foo')->in([1, 2, 3]); });
142
    	$this->assertValid(function($form) { $form->number('foo')->in([1, 2, 3])->default(1); });
143
144
    	$this->assertNotValid(function($form) { $form->number('foo')->in([1, 2, 3])->required(); });
145
    	$this->assertNotValid(function($form) { $form->number('foo')->in([1, 2, 3])->default(4); });
146
	}
147
148
	/** @test */
149 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...
150
    {
151
    	$this->assertValid(function($form) { $form->number('foo')->not_in(); });
152
    	$this->assertValid(function($form) { $form->number('foo')->not_in([1, 2, 3]); });
153
    	$this->assertValid(function($form) { $form->number('foo')->not_in([1, 2, 3])->default(4); });
154
155
    	$this->assertNotValid(function($form) { $form->number('foo')->not_in([1, 2, 3])->required(); });
156
    	$this->assertNotValid(function($form) { $form->number('foo')->not_in([1, 2, 3])->default(1); });
157
	}	
158
159
}
160