Laravels在工作台中干净利落的测试助手? [英] Laravels neat testing helpers in workbench?

查看:72
本文介绍了Laravels在工作台中干净利落的测试助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看 laravel测试文档,您会了解我所喜欢的所有很棒的助手在工作台中使用.

Looking at the laravel testing documentation, you get an idea of all the cool helpers I'd love to use in workbench.

遗憾的是我无法这样做.

Sadly I'm unable to do so.

Illuminate\Foundation\Testing\TestCase似乎不可用,因此我无法扩展它.

Illuminate\Foundation\Testing\TestCase seems to be unavailable when running my tests from the package directory and therefore i can't extend it.

<?php namespace Acme\Foo;

    class TestCase extends \Illuminate\Foundation\Testing\TestCase {

    /**
     * Creates the application.
     *
     * @return \Symfony\Component\HttpKernel\HttpKernelInterface
     */
    public function createApplication()
    {
        $unitTesting = true;

        $testEnvironment = 'testing';

        return require __DIR__.'/../../../../bootstrap/start.php';
    }

}

PHP Fatal error:  Class 'Illuminate\Foundation\Testing\TestCase' not found in 
/Applications/MAMP/htdocs/Webseiten/acme/workbench/acme/foo/tests/TestCase.php on line 3

我认为那不是正确的方法,无论如何应该这样做...

I think thats not the correct way, this should be done anyways...

我已经找到了 orchestral/testbench ,但我不确定这是否是一个好主意使用它.似乎需要整个laravel框架,这对我来说没有意义? (软件包应该扩展laravel安装,而不是第二次添加框架!?)

I have already found orchestral/testbench but I'm not really sure if it is a good idea to use it. It seems to require the whole laravel framework, which doesn't make sense to me? ( A package should extend a laravel install and not add the framework a second time!? )

推荐答案

对我来说,由于设置了工作台,因此测试用例只能从PHPUnit_Framework_TestCase扩展.因此,我从app文件夹而不是package文件夹运行测试用例.

For me, because of the way workbench is setup, the test cases can only extend from PHPUnit_Framework_TestCase. So I run the test cases from the app folder instead of the package folder.

我选择第二个选项,因为测试平台在很大程度上取决于特定的Laravel版本,并且似乎设置起来有些繁重.我所做的是在主应用程序下配置phpunit.xml,以将package tests文件夹作为测试套件包括在内:

I choose the second option as testbench heavily depends on the particular Laravel version and seems a bit heavy to set up. What I did is configure the phpunit.xml under the main app to include the package tests folder as a test suite:

<testsuite name="MyPack">
    <directory>./workbench/winponta/mypack/tests/</directory>
</testsuite>

然后运行:

$ phpunit --testsuite=MyPack

使用此方法,我们仍然可以从\ Illuminate \ Foundation \ Testing \ TestCase扩展.

Using this method, we can still extends from \Illuminate\Foundation\Testing\TestCase.

我在 http中找到了此解决方案://ngo-hung.com/blog/2014/04/16/laravel-unit-testing-in-workbench-note

这篇关于Laravels在工作台中干净利落的测试助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆