不从代码中处理异常

时间:2014-10-25 13:06:33

标签: php exception laravel codeception

我在global.php中处理了一个异常,但是当我运行codeception时,它会显示抛出异常但未处理。当我使用浏览器时,一切都很好。怎么可能这样呢?


Codeception功能Cept代码

$I = new FunctionalTester($scenario);
$I->am('a user');
$I->wantTo('send a message to another user');

//setup
$I->haveAnAccount(['username' => 'OtherUser']);

//actions
$I->signIn();
$I->click('Messages');
$I->seeCurrentUrlEquals('/inbox/new');
$I->fillField('Send to:','OtherUser');
$I->fillField('Message:','some random message');
$I->click('Send');

$I->click('Messages);失败并显示错误

Couldn't click "Messages":
Larabook\Conversations\Exceptions\ConversationNotFoundException: 

但是我已经在global.php

处理了它
App::error(function(Larabook\Conversations\Exceptions\ConversationNotFoundException $exception, $code)
{
    return Redirect::route('new_message_path');
});

它还显示抛出异常的位置:

Scenario Steps:
4. I click "Messages"
3. I sign in 
2. I have an account {"username":"OtherUser"}
1. As a a Larabook user

#1 /home/vagrant/Code/larabook.app/app/Larabook/Conversations/getConversationCommandHandler.php:41
#2  /home/vagrant/Code/larabook.app/vendor/laracasts/commander/src/Laracasts/Commander/DefaultCommandBus.php:58
#3  /home/vagrant/Code/larabook.app/vendor/laracasts/commander/src/Laracasts/Commander/ValidationCommandBus.php:64
#4  /home/vagrant/Code/larabook.app/vendor/laracasts/commander/src/Laracasts/Commander/CommanderTrait.php:34
#5  /home/vagrant/Code/larabook.app/app/controllers/InboxController.php:39
#6  /home/vagrant/Code/larabook.app/vendor/laravel/framework/src/Illuminate/Routing/Controller.php:231
#7  /home/vagrant/Code/larabook.app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:93
#8  /home/vagrant/Code/larabook.app/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:62
#9  /home/vagrant/Code/larabook.app/vendor/laravel/framework/src/Illuminate/Routing/Router.php:962
#10 /home/vagrant/Code/larabook.app/vendor/laravel/framework/src/Illuminate/Routing/Route.php:109

getConversationCommandHandler.php        

    28:    public function handle($command)
    29:    {
    30:        try
    31:         {
    32:             //get the user by username
    33:             $user = $this->userRepository->findbyUsername($command->sendToUsername);
    34:    
    35:             //get the conversation between users
    36:             $conversation = $this->conversationRepository->getConversationWith($user);
    37:         }
    38:         catch(UserNotFoundException $e)
    39:         {
    40:             //if the user not found get the last conversation
    41:             $conversation = $this->conversationRepository->getLastConversation();
    42:         }
    43:         catch(ConversationNotFoundException $e)
    44:         {
    45:             //if the conversation not found get the last conversation
    46:             $conversation = $this->conversationRepository->getLastConversation();
    47:         }
    48:
    59:         return $conversation;
    50:         }

0 个答案:

没有答案