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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助