Completed
Push — master ( deefe5...bad3f4 )
by Corey
03:41
created

ContactFormTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testSendEmail() 0 20 1
A testRules() 0 20 1
1
<?php
2
3
namespace site\tests\unit\models;
4
5
use Yii;
6
use \site\models\ContactForm;
7
8
class ContactFormTest extends \Codeception\Test\Unit {
9
10
  public function testRules() {
11
    $form = new ContactForm();
12
13
    $form->attributes = [];
14
    expect('with no values, the form should not pass validation', $this->assertFalse($form->validate()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($form->validate()) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
15
16
    $form->attributes = [
17
      'name' => 'Corey',
18
      'email' => 'not_an-email',
19
      'subject' => 'a question',
20
      'body' => 'hello there'
21
    ];
22
    expect('with a value that is not an email, the form should not pass validation', $this->assertFalse($form->validate()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertFalse($form->validate()) targeting PHPUnit\Framework\Assert::assertFalse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
23
    $form->attributes = [
24
      'name' => 'Corey',
25
      'email' => '  [email protected]  ',
26
      'subject' => 'a question',
27
      'body' => 'hello there'
28
    ];
29
    expect('with a valid email, the form should pass validation', $this->assertTrue($form->validate()));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->assertTrue($form->validate()) targeting PHPUnit\Framework\Assert::assertTrue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
30
  }
31
32
  public function testSendEmail() {
33
    $form = new ContactForm();
34
35
    $form->attributes = [
36
      'name' => 'Corey',
37
      'email' => '  [email protected]  ',
38
      'subject' => 'a question',
39
      'body' => 'hello there'
40
    ];
41
42
    $form->validate();
43
    $form->sendEmail('[email protected]');
44
45
    $this->tester->seeEmailIsSent();
0 ignored issues
show
Bug Best Practice introduced by
The property tester does not exist on site\tests\unit\models\ContactFormTest. Did you maybe forget to declare it?
Loading history...
46
    $emailMessage = $this->tester->grabLastSentEmail();
47
    expect('valid email is sent', $emailMessage)->isInstanceOf('yii\mail\MessageInterface');
48
    expect($emailMessage->getTo())->hasKey('[email protected]');
49
    expect($emailMessage->getFrom())->hasKey('[email protected]');
50
    expect($emailMessage->getSubject())->equals('[FSA Contact] a question');
51
    expect($emailMessage->toString())->contains('hello there');
52
  }
53
}
54
55