Hướng dẫn phpunit fail-on warning - cảnh báo lỗi phpunit

Tôi đang chạy tích hợp liên tục cho một dự án PHP với Jenkins, ANT và PHPUNIT 4.5.0. Plugin Xunit của Jenkins sẽ xử lý các bản ghi XML được sản xuất bởi PHPUNIT.

Một số lỗi đáng kể (ví dụ, đề cập đến một tệp không được đẩy sang VCS) chỉ đưa ra cảnh báo PHP trong PHPUNIT và cảnh báo không được đưa vào nhật ký. Do đó, bản dựng được đánh dấu là thành công mặc dù nó cần sửa chữa.

Làm thế nào tôi có thể làm cho các cảnh báo PHP thất bại trong việc xây dựng, ví dụ bằng cách tăng một ngoại lệ cho một bài kiểm tra tạo ra các cảnh báo?

Khi được hỏi ngày 27 tháng 2 năm 2015 lúc 14:37Feb 27, 2015 at 14:37

Hướng dẫn phpunit fail-on warning - cảnh báo lỗi phpunit

Chúng tôi phải thêm


0 để coi các cảnh báo như lỗi:

There was 1 warning:
1) The data provider specified for Tests\CreateSomethingTest::testCreateSomething is invalid.
FAILURES!
Tests: 841, Assertions: 2493, Failures: 1, Errors: 0.

Vì vậy, cấu hình của chúng tôi trông giống như:


Đã trả lời ngày 20 tháng 11 năm 2019 lúc 6:23Nov 20, 2019 at 6:23

Oleg Neumyvakinoleg NeumyvakinOleg Neumyvakin

9.2513 huy hiệu vàng58 Huy hiệu bạc59 Huy hiệu đồng3 gold badges58 silver badges59 bronze badges

1

Đảm bảo rằng các tùy chọn


1 được đặt thành

2. Thật không may, các tùy chọn không có sẵn trong dòng lệnh, vì vậy bạn phải tạo

3:




Đã trả lời ngày 28 tháng 2 năm 2015 lúc 9:36Feb 28, 2015 at 9:36

Hướng dẫn phpunit fail-on warning - cảnh báo lỗi phpunit

Tôi nhận thấy vấn đề tương tự. Tôi đã truy tìm nó đến bit mã này (v5.6.3):

// \PHPUnit_TextUI_TestRunner line 595
if ($result->wasSuccessful()) {
    if ($arguments['failOnRisky'] && !$result->allHarmless()) {
        exit(self::FAILURE_EXIT);
    }

    if ($arguments['failOnWarning'] && $result->warningCount() > 0) {
        exit(self::FAILURE_EXIT);
    }

    exit(self::SUCCESS_EXIT);
}

// \PHPUnit_Framework_TestResult line 1231
public function wasSuccessful()
{
    return empty($this->errors) && empty($this->failures) && empty($this->warnings);
}

Dường như với tôi rằng câu lệnh IF (về


4) sẽ không bao giờ đạt được do phương pháp

5 cũng kiểm tra xem có bất kỳ cảnh báo nào không.

Rolfbabijn đã thêm một cam kết với rolfbabijn/phpunit đã đề cập đến vấn đề này

Ngày 15 tháng 11 năm 2016

Hướng dẫn phpunit fail-on warning - cảnh báo lỗi phpunit

 * Moved unreachable warnings check.

Tôi không thể sao chép điều này với


6 hiện tại:


class Test extends PHPUnit\Framework\TestCase
{
    /**
     * @dataProvider invalid
     */
    public function testOne()
    {
    }
}

$ phpunit Test
PHPUnit 5.7.6-51-gb9287cb by Sebastian Bergmann and contributors.

W                                                                   1 / 1 (100%)

Time: 35 ms, Memory: 4.00MB

There was 1 warning:

1) Warning
The data provider specified for Test::testOne is invalid.
Method invalid does not exist

WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.

$ phpunit --fail-on-warning Test
PHPUnit 5.7.6-51-gb9287cb by Sebastian Bergmann and contributors.

W                                                                   1 / 1 (100%)

Time: 35 ms, Memory: 4.00MB

There was 1 warning:

1) Warning
The data provider specified for Test::testOne is invalid.
Method invalid does not exist

WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.

phpunit --fail-on-warning Test.php && echo "OK"
PHPUnit 5.6.4 by Sebastian Bergmann and contributors.

W                                                                   1 / 1 (100%)

Time: 161 ms, Memory: 16.00MB

There was 1 warning:

1) Warning
The data provider specified for Test::testOne is invalid.
Method invalid does not exist

/monamour/home/rumyantsev/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:188
/monamour/home/rumyantsev/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:118

WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.
OK

Vấn đề vẫn tồn tại

Trong PHPUNIT 5.7.6-51-GB9287CB (sớm được phát hành dưới dạng PHPUNIT 5.7.7), vấn đề không còn tồn tại nữa.

@Sebastianbergmann Đó là tác dụng phụ của cam kết này: F4CF4D1.

Nhưng


7 không hoạt động bây giờ.

Nó trả về


8 trong trường hợp

7 luôn luôn.

➜  phpunit git:(5.7) ✗ ./phpunit Test && echo OK
PHPUnit 5.7.6-51-gb9287cb by Sebastian Bergmann and contributors.

Runtime:       PHP 7.0.14 with Xdebug 2.5.0
Configuration: /Users/aivus/projects/phpunit/phpunit.xml

W                                                                   1 / 1 (100%)

Time: 72 ms, Memory: 2.00MB

There was 1 warning:

1) Warning
The data provider specified for Test::testOne is invalid.
Method invalid does not exist

/Users/aivus/projects/phpunit/src/Framework/WarningTestCase.php:57
/Users/aivus/projects/phpunit/src/Framework/TestCase.php:962
/Users/aivus/projects/phpunit/src/Framework/TestResult.php:709
/Users/aivus/projects/phpunit/src/Framework/TestCase.php:917
/Users/aivus/projects/phpunit/src/Framework/TestSuite.php:728
/Users/aivus/projects/phpunit/src/Framework/TestSuite.php:728
/Users/aivus/projects/phpunit/src/TextUI/TestRunner.php:487
/Users/aivus/projects/phpunit/src/TextUI/Command.php:188
/Users/aivus/projects/phpunit/src/TextUI/Command.php:118

WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.
➜  phpunit git:(5.7) ✗ echo $?
1