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

PasswordTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 135
Duplicated Lines 28.15 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 2
dl 38
loc 135
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A it_can_be_rendered() 0 6 1
A it_will_not_render_a_default_value() 0 6 1
A it_will_not_render_a_model_value() 0 7 1
A it_cannot_fill_model_values_using_default() 0 10 1
A it_can_fill_model_values_using_request() 19 19 1
A it_encrypts_passwords_automatically() 19 19 1
B it_can_check_if_password_matches() 0 25 1
A it_provides_expected_values() 0 7 1
A it_will_not_provide_default_values() 0 7 1
A it_validates_required() 0 6 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 PasswordTest extends FormTestCase {
6
7
	/** @test */
8
	public function it_can_be_rendered()
9
	{
10
		$form = $this->form();
11
		$form->password('foo');
0 ignored issues
show
Documentation Bug introduced by
The method password 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" type="password"', $form->render());
13
	}
14
15
	/** @test */
16
	public function it_will_not_render_a_default_value()
17
	{
18
		$form = $this->form();
19
		$form->password('foo')->default('bar');
0 ignored issues
show
Documentation Bug introduced by
The method password 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->assertNotContains('value="bar"', $form->render());
21
	}
22
23
	/** @test */
24
	public function it_will_not_render_a_model_value()
25
	{
26
		$form = $this->form();
27
		$form->defaults($this->model(['foo'=>'bar']));
28
		$form->password('foo');
0 ignored issues
show
Documentation Bug introduced by
The method password 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->assertNotContains('value="bar"', $form->render());
30
	}
31
32
	/** @test */
33
	public function it_cannot_fill_model_values_using_default()
34
	{
35
		$model = $this->model(['foo'=>'']);
36
37
		$form = $this->form();
38
		$form->password('foo')->default('bar');
0 ignored issues
show
Documentation Bug introduced by
The method password 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->assertEmpty($model->foo);
0 ignored issues
show
Documentation Bug introduced by
The method assertEmpty 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 View Code Duplication
	public function it_can_fill_model_values_using_request()
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...
46
	{
47
		$model = $this->model(['foo'=>'']);
48
49
		$request = $this->request();
50
    	$request->method('all')->will($this->returnValue(['foo'=>'bar', 'baz'=>true]));
51
    	$request->method('get')->will($this->returnValueMap([
52
    		['foo', 'bar'],
53
    		['baz', true],
54
    	]));
55
56
		$form = $this->form($request);
57
		$form->password('foo');
0 ignored issues
show
Documentation Bug introduced by
The method password 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...
58
		$form->button('baz');
0 ignored issues
show
Bug introduced by
The method button() does not exist on Helmut\Forms\Testing\Stubs\Form. Did you maybe mean addButton()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
59
60
		$form->fill($model);
61
62
		$this->assertNotEmpty($model->foo);
63
	}
64
65
	/** @test */
66 View Code Duplication
	public function it_encrypts_passwords_automatically()
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...
67
	{
68
		$model = $this->model(['foo'=>'']);
69
70
		$request = $this->request();
71
    	$request->method('all')->will($this->returnValue(['foo'=>'bar', 'baz'=>true]));
72
    	$request->method('get')->will($this->returnValueMap([
73
    		['foo', 'bar'],
74
    		['baz', true],
75
    	]));
76
77
		$form = $this->form($request);
78
		$form->password('foo');
0 ignored issues
show
Documentation Bug introduced by
The method password 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...
79
		$form->button('baz');
0 ignored issues
show
Bug introduced by
The method button() does not exist on Helmut\Forms\Testing\Stubs\Form. Did you maybe mean addButton()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
80
81
		$form->fill($model);
82
83
		$this->assertNotSame($model->foo, 'bar');
84
	}
85
86
	/** @test */
87
	public function it_can_check_if_password_matches()
88
	{
89
		$model = $this->model(['foo'=>'']);
90
91
		$request = $this->request();
92
    	$request->method('all')->will($this->returnValue(['foo'=>'bar', 'baz'=>true]));
93
    	$request->method('get')->will($this->returnValueMap([
94
    		['foo', 'bar'],
95
    		['baz', true],
96
    	]));
97
98
		$form = $this->form($request);
99
		$form->password('foo');
0 ignored issues
show
Documentation Bug introduced by
The method password 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...
100
		$form->button('baz');
0 ignored issues
show
Bug introduced by
The method button() does not exist on Helmut\Forms\Testing\Stubs\Form. Did you maybe mean addButton()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
101
102
		$form->fill($model);
103
104
		$hash = $form->password('foo')->hash('bar');
0 ignored issues
show
Documentation Bug introduced by
The method password 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...
105
		$invalid_hash = $form->password('foo')->hash('invalid');
0 ignored issues
show
Documentation Bug introduced by
The method password 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...
106
		$empty_hash = $form->password('foo')->hash('');
0 ignored issues
show
Documentation Bug introduced by
The method password 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...
107
108
		$this->assertTrue($form->password('foo')->matches($hash));
0 ignored issues
show
Documentation Bug introduced by
The method password 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...
109
		$this->assertFalse($form->password('foo')->matches($invalid_hash));
0 ignored issues
show
Documentation Bug introduced by
The method password 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...
110
		$this->assertFalse($form->password('foo')->matches($empty_hash));
0 ignored issues
show
Documentation Bug introduced by
The method password 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...
111
	}
112
113
	/** @test */
114
	public function it_provides_expected_values()
115
	{
116
		$form = $this->form();
117
		$form->password('foo');
0 ignored issues
show
Documentation Bug introduced by
The method password 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...
118
119
		$this->assertSame($form->get('foo'), '');
120
	}	
121
122
	/** @test */
123
	public function it_will_not_provide_default_values()
124
	{
125
		$form = $this->form();
126
		$form->password('foo')->default('bar');
0 ignored issues
show
Documentation Bug introduced by
The method password 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...
127
128
		$this->assertSame($form->get('foo'), '');
129
	}
130
131
	/** @test */
132
    public function it_validates_required()
133
    {
134
    	$this->assertValid(function($form) { $form->password('foo'); });
135
136
    	$this->assertNotValid(function($form) { $form->password('foo')->required(); });
137
	}
138
139
}
140