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

DropdownTest::it_can_be_rendered()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 9
rs 9.6666
nc 1
cc 1
eloc 7
nop 0
1
<?php
2
3
namespace Helmut\Forms\Testing;
4
5
class DropdownTest extends FormTestCase {
6
7
	/** @test */
8 View Code Duplication
	public function it_can_be_rendered()
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...
9
	{
10
		$form = $this->form();
11
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']);
0 ignored issues
show
Documentation Bug introduced by
The method dropdown 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('<select name="foo"', $form->render());
13
		$this->assertContains('<option value="a">A</option>', $form->render());
14
		$this->assertContains('<option value="b">B</option>', $form->render());
15
		$this->assertContains('<option value="c">C</option>', $form->render());
16
	}
17
18
	/** @test */
19 View Code Duplication
	public function it_renders_a_default_value()
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...
20
	{
21
		$form = $this->form();
22
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->default('b');
0 ignored issues
show
Documentation Bug introduced by
The method dropdown 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...
23
24
		$this->assertContains('<option value="a">A</option>', $form->render());
25
		$this->assertContains('<option value="b" selected="selected">B</option>', $form->render());
26
		$this->assertContains('<option value="c">C</option>', $form->render());
27
	}
28
29
	/** @test */
30 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...
31
	{
32
		$form = $this->form();
33
		$form->defaults($this->model(['foo'=>'b']));
34
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']);
0 ignored issues
show
Documentation Bug introduced by
The method dropdown 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...
35
36
		$this->assertContains('<option value="a">A</option>', $form->render());
37
		$this->assertContains('<option value="b" selected="selected">B</option>', $form->render());
38
		$this->assertContains('<option value="c">C</option>', $form->render());
39
	}
40
41
	/** @test */
42
	public function it_can_fill_model_values()
43
	{
44
		$model = $this->model(['foo'=>'']);
45
46
		$form = $this->form();
47
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->default('b');
0 ignored issues
show
Documentation Bug introduced by
The method dropdown 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...
48
		$form->fill($model);
49
50
		$form->assertEquals($model->foo, 'b');
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...
51
	}	
52
53
	/** @test */
54 View Code Duplication
	public function it_provides_expected_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...
55
	{
56
		$form = $this->form();
57
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']);
0 ignored issues
show
Documentation Bug introduced by
The method dropdown 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
59
		$this->assertSame($form->get('foo'), '');
60
	}	
61
62
	/** @test */
63 View Code Duplication
	public function it_provides_expected_default_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...
64
	{
65
		$form = $this->form();
66
		$form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->default('c');
0 ignored issues
show
Documentation Bug introduced by
The method dropdown 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...
67
68
		$this->assertSame($form->get('foo'), 'c');
69
	}
70
71
	/** @test */
72
    public function it_validates_required()
73
    {
74
    	$this->assertValid(function($form) { $form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C']); });
75
76 View Code Duplication
    	$this->assertNotValid(function($form) { $form->dropdown('foo')->options(['a'=>'A', 'b'=>'B', 'c'=>'C'])->required(); });
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
77
	}	
78
79
}
80