Completed
Push — master ( 5d0c73...7eb8d2 )
by Shcherbak
18:42 queued 03:41
created

RequiredTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testSimpleValidation() 0 32 1
1
<?php
2
3
  namespace Tests\Fiv\Form\Validator;
4
5
  use Fiv\Form\Form;
6
  use Fiv\Form\Validator\Required;
7
  use Tests\Fiv\Form\FormTestCase;
8
9
  /**
10
   *
11
   */
12
  class RequiredTest extends FormTestCase {
13
14
15
    public function testSimpleValidation() {
16
      $validator = new Required();
17
      $validator->setError('Test error message');
18
19
      $form = new Form();
20
      $form->input('login')
21
        ->addValidator($validator);
22
23
      $form->setData([
24
        $form->getUid() => 1,
25
        'login' => 'testLogin',
26
      ]);
27
28
      $this->assertTrue($form->isValid());
29
      $this->assertEmpty($validator->getErrors());
30
31
32
      $form->setData([
33
        $form->getUid() => 1,
34
        'login' => '',
35
      ]);
36
37
      $this->assertFalse($form->isValid());
38
      $this->assertEquals('Test error message', $validator->getFirstError());
39
40
41
      $form->setData([
42
        $form->getUid() => 1,
43
        'login' => '0',
44
      ]);
45
      $this->assertTrue($form->isValid());
46
    }
47
48
  }
49