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

EmailTest::it_can_fill_model_values()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
nc 1
cc 1
eloc 6
nop 0
1
<?php
2
3
namespace Helmut\Forms\Testing;
4
5
class EmailTest extends FormTestCase {
6
7
	/** @test */
8
	public function it_can_be_rendered()
9
	{
10
		$form = $this->form();
11
		$form->email('foo');
0 ignored issues
show
Documentation Bug introduced by
The method email 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->email('foo')->default('bar');
0 ignored issues
show
Documentation Bug introduced by
The method email 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->email('foo');
0 ignored issues
show
Documentation Bug introduced by
The method email 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->email('foo')->default('bar');
0 ignored issues
show
Documentation Bug introduced by
The method email 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->email('foo')->default('bar&');
0 ignored issues
show
Documentation Bug introduced by
The method email 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->email('foo');
0 ignored issues
show
Documentation Bug introduced by
The method email 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->email('foo')->default('[email protected]');
0 ignored issues
show
Documentation Bug introduced by
The method email 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'), '[email protected]');
68
	}
69
70
	/** @test */
71
    public function it_validates_required()
72
    {
73
    	$this->assertValid(function($form) { $form->email('foo'); });
74
75
    	$this->assertNotValid(function($form) { $form->email('foo')->required(); });
76
	}
77
78
	/** @test */
79
    public function it_validates_email()
80
    {
81
    	$this->assertValid(function($form) { $form->email('foo')->default('[email protected]'); });
82
    	$this->assertValid(function($form) { $form->email('foo')->default('bar\'[email protected]'); });
83
84
    	$this->assertNotValid(function($form) { $form->email('foo')->default('bar@invalid'); });
85
    	$this->assertNotValid(function($form) { $form->email('foo')->default('bar@inva\'lid.com'); });
86
	}
87
88
}
89