简体   繁体   中英

Laravel Dusk junit doesn't log to file

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

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

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

Googling doesn't reveal anything.

Any ideas?

EDIT 1:

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.

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

EDIT 2:

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;
    }
}

EDIT 3:

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.

.

here is my phpunit command:

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

EDIT 4:

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'));
    }
}

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM