Laravel Dusk Junit未登录到文件 [英] Laravel Dusk junit doesn't log to file

查看:97
本文介绍了Laravel Dusk Junit未登录到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Laravel Dusk编写了一些自动化测试,运行它们时出现一些错误,但是似乎无法滚动查看整个输出.首先,我尝试将输出传递给less,但是由于某些原因,less无法正常工作.然后我尝试做:

I've written some automated tests using Laravel Dusk and when I run them I get some errors, however I can't seem to scroll through the whole output. First I tried to pipe the output to less but less doesn't work properly for some reason. Then I tried doing:

php artisan dusk --log-junit /path/to/log/file.log

但是由于某种原因,日志文件仍然为空.日志的teamcity版本有效,但是未描述错误.

however the log file keeps empty for some reason. The teamcity version of the log works but there the errors are not described.

此外,当我只运行Dusk附带的基本测试时,它会正确记录.

Also, when I run only the basic test, which comes with Dusk, it logs properly.

Google搜索没有显示任何内容.

Googling doesn't reveal anything.

有什么想法吗?

我将问题缩小到此测试范围:

I've narrowed down the problem to this test:

<?php

namespace Tests\Browser;

use App\Logic\Dates\Transform;
use Tests\DuskTestCase;

class DatesTransforms extends DuskTestCase
{
    /**
     * A Dusk test example.
     *
     * @return void
     */
    public function testMonthEnd()
    {
        $this->assertEquals('2018-01-31 23:59:59', Transform::monthEnd('2018-01'));
        $this->assertEquals('2018-02-28 23:59:59', Transform::monthEnd('2018-02'));
        $this->assertEquals('2018-03-31 23:59:59', Transform::monthEnd('2018-03'));
        $this->assertEquals('2018-04-30 23:59:59', Transform::monthEnd('2018-04'));
        $this->assertEquals('2018-05-31 23:59:59', Transform::monthEnd('2018-05'));
        $this->assertEquals('2018-06-30 23:59:59', Transform::monthEnd('2018-06'));
        $this->assertEquals('2018-07-31 23:59:59', Transform::monthEnd('2018-07'));
        $this->assertEquals('2018-08-31 23:59:59', Transform::monthEnd('2018-08'));
        $this->assertEquals('2018-09-30 23:59:59', Transform::monthEnd('2018-09'));
        $this->assertEquals('2018-10-31 23:59:59', Transform::monthEnd('2018-10'));
        $this->assertEquals('2018-11-30 23:59:59', Transform::monthEnd('2018-11'));
        $this->assertEquals('2018-12-31 23:59:59', Transform::monthEnd('2018-12'));

        $this->assertEquals('2016-02-29 23:59:59', Transform::monthEnd('2016-02'));
    }

    public function testMonthStart()
    {
        $this->assertEquals('2018-01-01 00:00:00', Transform::monthStart('2018-01'));
        $this->assertEquals('2018-02-01 00:00:00', Transform::monthStart('2018-02'));
        $this->assertEquals('2018-03-01 00:00:00', Transform::monthStart('2018-03'));
        $this->assertEquals('2018-04-01 00:00:00', Transform::monthStart('2018-04'));
        $this->assertEquals('2018-05-01 00:00:00', Transform::monthStart('2018-05'));
    }
}

运行完整测试时,出现此错误:

when I run the full test I get this error:

lluminate\\Cont...', Array)
#3 /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(759): Illuminate\Container\Container->make('Illuminate\\Cont...', Array)
#4 /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleEx in /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 945
PHP Stack trace:
PHP   1. {main}() /var/www/domovakniga.local/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /var/www/domovakniga.local/vendor/phpunit/phpunit/phpunit:61
PHP   3. PHPUnit\TextUI\Command->run() /var/www/domovakniga.local/vendor/phpunit/phpunit/src/TextUI/Command.php:162
PHP   4. PHPUnit\TextUI\TestRunner->doRun() /var/www/domovakniga.local/vendor/phpunit/phpunit/src/TextUI/Command.php:206
PHP   5. PHPUnit\Framework\TestSuite->run() /var/www/domovakniga.local/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:652
PHP   6. Tests\Browser\DatesTransforms->run() /var/www/domovakniga.local/vendor/phpunit/phpunit/src/Framework/TestSuite.php:746
PHP   7. PHPUnit\Framework\TestResult->run() /var/www/domovakniga.local/vendor/phpunit/phpunit/src/Framework/TestCase.php:796
PHP   8. Tests\Browser\DatesTransforms->runBare() /var/www/domovakniga.local/vendor/phpunit/phpunit/src/Framework/TestResult.php:693
PHP   9. Tests\Browser\DatesTransforms->setUp() /var/www/domovakniga.local/vendor/phpunit/phpunit/src/Framework/TestCase.php:838
PHP  10. Tests\Browser\DatesTransforms->setUp() /var/www/domovakniga.local/vendor/laravel/dusk/src/TestCase.php:23
PHP  11. Tests\Browser\DatesTransforms->refreshApplication() /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:68
PHP  12. Tests\Browser\DatesTransforms->createApplication() /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:91
PHP  13. App\Console\Kernel->bootstrap() /var/www/domovakniga.local/tests/CreatesApplication.php:19
PHP  14. Illuminate\Foundation\Application->bootstrapWith() /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:297
PHP  15. Illuminate\Foundation\Bootstrap\BootProviders->bootstrap() /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:211
PHP  16. Illuminate\Foundation\Application->boot() /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
PHP  17. Illuminate\Foundation\Application->fireAppCallbacks() /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:807
PHP  18. call_user_func:{/var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:858}() /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:858
PHP  19. App\Console\Kernel->Illuminate\Foundation\Console\{closure}() /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:858
PHP  20. App\Console\Kernel->defineConsoleSchedule() /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:90
PHP  21. App\Console\Kernel->schedule() /var/www/domovakniga.local/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php:107

请注意,由于滚动问题,我看不到最上面的部分.

note that I can't see the top most part due to scrolling issues.

此外,请注意,当我使用filter运行该测试的每个方法时,一切正常.哪个令人困惑.

Also, note that when I run each of the methods of that test using filter everything works properly. Which is baffling.

这是测试中使用的Transform类:

Here is the Transform class used in the test:

<?php

namespace App\Logic\Dates;

class Transform {
    /**
     * Given a month in the following format: YYYY-MM
     * it returns datetime for the last second of the month
     *
     * @param $year_and_month
     * @return string
     */
    static function monthEnd($year_and_month) {
        $datetime = $year_and_month . '-01 00:00:00';
        $time = strtotime($datetime);

        $month_end = date('Y-m-t', $time) . ' 23:59:59';

        return $month_end;
    }

    /**
     * Given a month in the following manner: YYYY-MM
     * it returns a datetime for the first second of that month
     *
     * @param $year_and_month
     * @return string
     */
    static function monthStart($year_and_month) {
        $month_start = $year_and_month . '-01 00:00:00';

        return $month_start;
    }
}

所以我已经删除了有问题的测试DatesTransform,并使用香草phpunit进行了重写,但是在运行phpunit时出现错误,我再次无法记录它,仅记录以下内容:

So I've deleted the problematic test DatesTransform and rewritten it using vanilla phpunit, however when running phpunit I get an error which I again can't log it just logs the following:

PHPUnit 7.5.13 by Sebastian Bergmann and contributors.

.

这是我的phpunit命令:

here is my phpunit command:

vendor/bin/phpunit > /path/phpunit.log

这是新的phpunit DatesTransformationsTest:

Here is the new phpunit DatesTransformationsTest:

<?php

namespace Tests\Unit;

use App\Logic\Dates\Transform;
use Tests\TestCase;

class DatesTransformationsTest extends TestCase
{
    public function testMonthEnd()
    {
        self::assertEquals('2018-01-31 23:59:59', Transform::monthEnd('2018-01'));
        self::assertEquals('2018-02-28 23:59:59', Transform::monthEnd('2018-02'));
        self::assertEquals('2018-03-31 23:59:59', Transform::monthEnd('2018-03'));
        self::assertEquals('2018-04-30 23:59:59', Transform::monthEnd('2018-04'));
        self::assertEquals('2018-05-31 23:59:59', Transform::monthEnd('2018-05'));
        self::assertEquals('2018-06-30 23:59:59', Transform::monthEnd('2018-06'));
        self::assertEquals('2018-07-31 23:59:59', Transform::monthEnd('2018-07'));
        self::assertEquals('2018-08-31 23:59:59', Transform::monthEnd('2018-08'));
        self::assertEquals('2018-09-30 23:59:59', Transform::monthEnd('2018-09'));
        self::assertEquals('2018-10-31 23:59:59', Transform::monthEnd('2018-10'));
        self::assertEquals('2018-11-30 23:59:59', Transform::monthEnd('2018-11'));
        self::assertEquals('2018-12-31 23:59:59', Transform::monthEnd('2018-12'));

        self::assertEquals('2016-02-29 23:59:59', Transform::monthEnd('2016-02'));
    }

    public function testMonthStart()
    {
        self::assertEquals('2018-01-01 00:00:00', Transform::monthStart('2018-01'));
        self::assertEquals('2018-02-01 00:00:00', Transform::monthStart('2018-02'));
        self::assertEquals('2018-03-01 00:00:00', Transform::monthStart('2018-03'));
        self::assertEquals('2018-04-01 00:00:00', Transform::monthStart('2018-04'));
        self::assertEquals('2018-05-01 00:00:00', Transform::monthStart('2018-05'));
    }
}

推荐答案

解决了这个问题,原来我已经在控制台的Kernel.php的schedule方法内定义了一个方法,并且由于重复定义而引发错误由于某种原因,不知道为什么.一旦将其移入自己的班级,问题就消失了!

Solved it, it turns out I've defined a method inside the schedule method of the Console's Kernel.php and that was raising errors as a duplicate definition for some reason, no idea why. Once I moved it into its own class problems disappeared!

这篇关于Laravel Dusk Junit未登录到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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