Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor & unit tests #2

Open
bcho opened this issue Jan 24, 2015 · 2 comments
Open

Refactor & unit tests #2

bcho opened this issue Jan 24, 2015 · 2 comments
Assignees

Comments

@bcho
Copy link
Member

bcho commented Jan 24, 2015

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:

@bcho
Copy link
Member Author

bcho commented Jan 24, 2015

cc @Luo2013 @Yannyezixin @Gallonq

@bcho
Copy link
Member Author

bcho commented Jan 24, 2015

@MaureenChan 这在你拿了很高分的设计模式里叫 facade / bridge ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants