Skip to content

Refactor & unit tests #2

@bcho

Description

@bcho

Please add some unit tests.

For example, in https://github.com/vtmer/vtmer-wechat/blob/da696d2dbb8646aa2318e0e4a5a4dd4dc2a4e4aa/app/controllers/WeixinEventHandler.php#L11,L30 , you can add a simple layer for retrieving contact information:

<?php
$name = WeixinInput::get('content');
$contact = Contact::findByName($name);
$message = WeixinMessage:text(/* xxx */, View::render('contact_card', $contact));
return Response::xml($message);

Then you can test Contact on method findByName:

<?php namespace Test\Contact;

use Contact;

class ContactTest extends \TestCase
{
    public function testFindByName()
    {
        // You may mock your contact model first.
       $contact = $this->mockContact();
       $contact->shouldReceive('where')->andReturn($contact)->shouldReceive('first')->andReturn($contact);
       $this->assertEquals($contact, Contact::findByName('test'));
    }
}

References:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions