dream07769 2015-04-07 20:19
浏览 118
已采纳

Laravel 5单元测试和命名空间

I'm running into a few issues regarding PHPUnit in Laravel 5 with Namespacing. I'm attempting to do a simple test on one of my routes, which of course calls a Model, but I'm getting an unexpected error when it makes the call.

PHP Fatal error: Class 'Eloquent' not found in /home/app/Models/User.php on line 10

Here is the relevant code block from User.php

<?php

use Laravel\Cashier\Billable;
use Laravel\Cashier\Contracts\Billable as BillableContract;
use Illuminate\Auth\Authenticatable;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends \Eloquent implements AuthenticatableContract, CanResetPasswordContract, BillableContract {

It appears that I'm having some issues with Namespacing in the Testing environment. I do not want to change my Model, as it works precisely as I'd like it to with my application.

How can I make the PHPUnit environment interact with my application without making direct changes to the application?

  • 写回答

2条回答 默认 最新

  • duanru6816 2015-04-07 20:23
    关注

    Try adding parent::setUp() in your test's setUp function as well to make sure your testing environment gets setup properly.

    /**
     * Default preparation for each test
     *
     */
    public function setUp()
    {
        parent::setUp(); // Don't forget this!
    
        $this->prepareForTests();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号