Laravels neat testing helpers in workbench?

限于喜欢 提交于 2019-12-07 13:46:32

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.

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>

And then run:

$ phpunit --testsuite=MyPack

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

I found this solution at http://ngo-hung.com/blog/2014/04/16/laravel-unit-testing-in-workbench-note

I just did like this,

First of all, change your phpunit.xml content on your workbench directory. You will "bootstrap" attribute section, change it from vendor/autoload.php to ../../../bootstrap/autoload.php

Then try running phpunit on your workbench directory.

Removing

namespace Acme\Foo;

should fix it. Then you can run tests from the package dir. Also be sure to run composer dump-autoload in the package dir or php artisan dump-autoload from main app dir.

UPDATE I was able to replicate the error in a clean Laravel 4.1 installation and fixed it following this steps without installing extra packages:

1 - Install PHPUnit in the main laravel root composer.json (not the workbench package composer.json file)

"require-dev": {
     "phpunit/phpunit": "3.7.*"
},

2 - Run composer update in main laravel root dir.

3 - In your test classes use fully qualified names (namespace prefixed with )

<?php
class SomeTest extends \Illuminate\Foundation\Testing\TestCase {
   public function createApplication()
   {
       $unitTesting = true;
       $testEnvironment = 'testing';
       return require __DIR__.'/../../../../bootstrap/start.php';
   }
   public function testSomething()
   {
       $this->assertTrue(true);
   }
}

4 - To run workbench package tests, go to package directory and run main phpunit

# in workbench/package/vendor dir run
../../../vendor/bin/phpunit

5 - Output Green flag recognizing laravel app third party packages

marcanuy@bolso-server:~/public_html/pkgtesting/workbench/my/pack$ ../../../vendor/bin/phpunit --debug
PHPUnit 3.7.31 by Sebastian Bergmann.

Configuration read from /home/marcanuy/public_html/pkgtesting/workbench/my/pack/phpunit.xml


Starting test 'SomeTest::testSomething'.
.

Time: 64 ms, Memory: 6.25Mb

OK (1 test, 1 assertion)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!