Completed
Push — master ( 9f8480...602ed2 )
by Helmut
04:40
created

FormTestCase   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 51
rs 10
1
<?php
2
3
namespace Helmut\Forms\Testing;
4
5
//use Helmut\Forms\Testing\Stubs\Form;
6
7
class FormTestCase extends \PHPUnit_Framework_TestCase{
8
	
9
	public function request()
10
	{
11
		$request = $this->getMock('Helmut\Forms\Request');
12
    	$request->method('csrf')->will($this->returnValue([]));
13
		return $request;
14
	}
15
16
	public function form($request=null)
17
	{
18
		if ( ! $request) $request = $this->request();
19
20
		$form = new Stubs\Form($request);
21
		$form->removeAllPlugins();
22
		return $form;
23
	}
24
25
	public function model($properties = [])
26
	{
27
		$model = new \stdClass;
28
		foreach ($properties as $key => $value) {
29
			$model->$key = $value;
30
		}
31
		return $model;
32
	}	
33
34
35
	public function assertValid($callback)
36
	{
37
		$form = $this->form();
38
		call_user_func($callback, $form);
39
		return $this->assertTrue($form->valid());
40
	}
41
42
	public function assertNotValid($callback)
43
	{
44
		$form = $this->form();
45
		call_user_func($callback, $form);
46
		return $this->assertFalse($form->valid());
47
	}
48
49
	public function tearDown()
50
    {
51
        if (class_exists('Mockery')) 
52
        {
53
            \Mockery::close();
54
        }
55
	}
56
	
57
}