哪种方法可以使用PHPUnit在Laravel 5.2中测试命令?

阿拉里瓦

我试图在PHPUnit中Commands编写测试用例,但没有成功。

在这一点上,我已经尝试了很多事情,可能是这篇文章是我找到的最接近我目的的方法。不过,要使此工作正常进行,我仍然很努力。

遵循为您提供的示例输出:

alariva@trinsic ~/timegrid.io/app $ phpunit --filter=SendBusinessReportTest
PHP Warning:  The use statement with non-compound name 'Artisan' has no effect in /home/alariva/timegrid.io/app/tests/unit/Console/Commands/SendBusinessReportTest.php on line 4
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_Command->handleArguments() /usr/share/php/PHPUnit/TextUI/Command.php:138
PHP   5. PHPUnit_Util_Configuration->getTestSuiteConfiguration() /usr/share/php/PHPUnit/TextUI/Command.php:657
PHP   6. PHPUnit_Util_Configuration->getTestSuite() /usr/share/php/PHPUnit/Util/Configuration.php:789
PHP   7. PHPUnit_Framework_TestSuite->addTestFiles() /usr/share/php/PHPUnit/Util/Configuration.php:873
PHP   8. PHPUnit_Framework_TestSuite->addTestFile() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:409
PHP   9. PHPUnit_Util_Fileloader::checkAndLoad() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:335
PHP  10. PHPUnit_Util_Fileloader::load() /usr/share/php/PHPUnit/Util/Fileloader.php:76
PHPUnit 4.8.26 by Sebastian Bergmann and contributors.

PHP Fatal error:  Call to undefined method App\Console\Kernel::resolve() in /home/alariva/timegrid.io/app/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 217
PHP Stack trace:
PHP   1. {main}() /usr/bin/phpunit:0
PHP   2. PHPUnit_TextUI_Command::main() /usr/bin/phpunit:46
PHP   3. PHPUnit_TextUI_Command->run() /usr/share/php/PHPUnit/TextUI/Command.php:129
PHP   4. PHPUnit_TextUI_TestRunner->doRun() /usr/share/php/PHPUnit/TextUI/Command.php:176
PHP   5. PHPUnit_Framework_TestSuite->run() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:440
PHP   6. PHPUnit_Framework_TestSuite->run() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
PHP   7. PHPUnit_Framework_TestCase->run() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
PHP   8. PHPUnit_Framework_TestResult->run() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestCase.php:724
PHP   9. PHPUnit_Framework_TestCase->runBare() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:612
PHP  10. PHPUnit_Framework_TestCase->runTest() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestCase.php:768
PHP  11. ReflectionMethod->invokeArgs() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestCase.php:909
PHP  12. SendBusinessReportTest->it_tests_command() /home/alariva/timegrid.io/app/vendor/phpunit/phpunit/src/Framework/TestCase.php:909
PHP  13. Illuminate\Support\Facades\Artisan::resolve() /home/alariva/timegrid.io/app/tests/unit/Console/Commands/SendBusinessReportTest.php:14
PHP  14. Illuminate\Support\Facades\Facade::__callStatic() /home/alariva/timegrid.io/app/tests/unit/Console/Commands/SendBusinessReportTest.php:14

  [Symfony\Component\Debug\Exception\FatalErrorException]  
  Call to undefined method App\Console\Kernel::resolve() 

您可以在这里找到我目前的尝试,(测试失败),但是也许您可以向我提示我所缺少的东西:)

仅供参考,我现在的工作方式但似乎没有涵盖以下代码:覆盖率报告测试用例

旁注:您可能会问为什么使用PHPUnit而不是另一个测试框架。到目前为止,我正在用PHPUnit生成测试覆盖率,我一直坚持下去,直到我感觉到实际需要切换为止。但是,欢迎提出所有建议。

提前致谢!

阿拉里瓦

我得到了一种可接受的方法,如下所示:

<?php

use App\Console\Commands\SendBusinessReport;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Tester\CommandTester;
use Timegridio\Concierge\Models\Appointment;

class SendBusinessReportTest extends TestCase
{
    use DatabaseTransactions;
    use CreateBusiness, CreateUser, CreateContact, CreateAppointment, CreateService, CreateVacancy;

    /** @test */
    public function it_reports_to_all_businesses()
    {
        $this->arrangeFixture();

        // BEGIN Actual solution code
        $application = new ConsoleApplication();

        $testedCommand = $this->app->make(SendBusinessReport::class);
        $testedCommand->setLaravel(app());
        $application->add($testedCommand);

        $command = $application->find('business:report');

        $commandTester = new CommandTester($command);

        $commandTester->execute([
            'command' => $command->getName(),
        ]);
        // END Actual solution code

        $this->assertRegExp('/Scanning all businesses../', $commandTester->getDisplay());
    }

    /**
     * Arrange Fixture.
     *
     * @return void
     */
    protected function arrangeFixture()
    {
        $this->owner = $this->createUser();
        $this->issuer = $this->createUser();

        $this->business = $this->createBusiness();
        $this->business->owners()->save($this->owner);

        $this->contact = $this->createContact();
        $this->contact->user()->associate($this->issuer);

        $this->service = $this->makeService();
        $this->business->services()->save($this->service);

        $this->vacancy = $this->makeVacancy();
        $this->vacancy->service()->associate($this->service);

        $this->business->vacancies()->save($this->vacancy);

        $appointment = $this->makeAppointment($this->business, $this->issuer, $this->contact, [
            'status' => Appointment::STATUS_CONFIRMED,
            ]);
    }
}


alariva@trinsic ~/timegrid.io/app $ phpunit --filter=it_reports_to_all_businesses
PHPUnit 5.4.6 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 813 ms, Memory: 30.00MB

OK (1 test, 1 assertion)

参考

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用Laravel 5 [phpunit]的测试方法和控制器

来自分类Dev

卡在laravel 5中的phpunit测试中

来自分类Dev

在所有浏览器中,我可以使用哪种方法来获取时区缩写?

来自分类Dev

有没有一种方法可以使用Laravel 5 Migrations创建citext字段?

来自分类Dev

从AWS com切换到route53的软件,我可以使用哪种方法进行类似的使用,例如com包中的shutdown()方法

来自分类Dev

是否可以使用xcode 5在命令行上运行单个测试用例/测试类?

来自分类Dev

是否可以使用xcode 5在命令行上运行单个测试用例/测试类?

来自分类Dev

接口定义中可以使用多种方法吗?

来自分类Dev

使用 PhpUnit 测试包含 Laravel 5 包中的 @include 或 @extend 指令的刀片视图

来自分类Dev

在Laravel 5中是否可以使用不带ORM的MongoDB?

来自分类Dev

Laravel 5 PHPUnit测试json发布

来自分类Dev

有没有一种方法可以使文本字符刷新到HTML5中其边框的顶部?

来自分类Dev

在Laravel 5中运行工匠命令

来自分类Dev

有没有一种方法可以使用RSpec在模型中测试环境定义的动态验证?

来自分类Dev

有没有一种方法可以使用JavaScript发送CoAP命令?

来自分类Dev

您可以使用Laravel 5在数据库中创建条目而不填充Eloquent模型吗

来自分类Dev

您可以使用Laravel 5在数据库中创建条目而不填充Eloquent模型吗

来自分类Dev

如何使用PhpUnit模拟Laravel中的一种方法

来自分类Dev

有没有一种方法可以使用laravel 5.2中雄辩的一对多关系来选择列?

来自分类Dev

有多少种方法可以将元素添加到列表中,哪种方法最快?

来自分类Dev

只有在Laravel 5中访问根页面(visit('/'))时,PHPUnit测试才会失败

来自分类Dev

使用带有数据库的PHPUnit Laravel 5控制器进行测试(模拟?)

来自分类Dev

使用带有数据库的PHPUnit Laravel 5控制器进行测试(模拟?)

来自分类Dev

Laravel 5 PHPUnit测试失败,null上的getContent()

来自分类Dev

Laravel 5 PHPUnit测试失败,null上的getContent()

来自分类Dev

在JSQmessagesViewController中添加消息后使用哪种方法

来自分类Dev

有没有一种方法可以使用Taurus / JMeter从测试计划中仅运行一个测试?

来自分类Dev

在Angular2中完全渲染模板后,是否可以使用一种方法?

来自分类Dev

在LibGit2中可以使用子树命令吗?

Related 相关文章

  1. 1

    使用Laravel 5 [phpunit]的测试方法和控制器

  2. 2

    卡在laravel 5中的phpunit测试中

  3. 3

    在所有浏览器中,我可以使用哪种方法来获取时区缩写?

  4. 4

    有没有一种方法可以使用Laravel 5 Migrations创建citext字段?

  5. 5

    从AWS com切换到route53的软件,我可以使用哪种方法进行类似的使用,例如com包中的shutdown()方法

  6. 6

    是否可以使用xcode 5在命令行上运行单个测试用例/测试类?

  7. 7

    是否可以使用xcode 5在命令行上运行单个测试用例/测试类?

  8. 8

    接口定义中可以使用多种方法吗?

  9. 9

    使用 PhpUnit 测试包含 Laravel 5 包中的 @include 或 @extend 指令的刀片视图

  10. 10

    在Laravel 5中是否可以使用不带ORM的MongoDB?

  11. 11

    Laravel 5 PHPUnit测试json发布

  12. 12

    有没有一种方法可以使文本字符刷新到HTML5中其边框的顶部?

  13. 13

    在Laravel 5中运行工匠命令

  14. 14

    有没有一种方法可以使用RSpec在模型中测试环境定义的动态验证?

  15. 15

    有没有一种方法可以使用JavaScript发送CoAP命令?

  16. 16

    您可以使用Laravel 5在数据库中创建条目而不填充Eloquent模型吗

  17. 17

    您可以使用Laravel 5在数据库中创建条目而不填充Eloquent模型吗

  18. 18

    如何使用PhpUnit模拟Laravel中的一种方法

  19. 19

    有没有一种方法可以使用laravel 5.2中雄辩的一对多关系来选择列?

  20. 20

    有多少种方法可以将元素添加到列表中,哪种方法最快?

  21. 21

    只有在Laravel 5中访问根页面(visit('/'))时,PHPUnit测试才会失败

  22. 22

    使用带有数据库的PHPUnit Laravel 5控制器进行测试(模拟?)

  23. 23

    使用带有数据库的PHPUnit Laravel 5控制器进行测试(模拟?)

  24. 24

    Laravel 5 PHPUnit测试失败,null上的getContent()

  25. 25

    Laravel 5 PHPUnit测试失败,null上的getContent()

  26. 26

    在JSQmessagesViewController中添加消息后使用哪种方法

  27. 27

    有没有一种方法可以使用Taurus / JMeter从测试计划中仅运行一个测试?

  28. 28

    在Angular2中完全渲染模板后,是否可以使用一种方法?

  29. 29

    在LibGit2中可以使用子树命令吗?

热门标签

归档