назар-пк/пхпт-тесты-раннер

Раннер для тестов PHPT (с несколькими различиями по сравнению с оригинальным форматом PHPT)

1.4.1 2018-01-30 07:48 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:53:10 UTC


README

PHPT Tests runner

Usage:
  phpt-tests-runner [-h] [-c] [-C] [-b binary] [files] [directories]

Arguments:
  -h Print this help message
  -b Specify custom PHP binary to be used (current is used by default)
  -c Force colored output
  -C Force no colored output

Examples:
  Execute tests from tests directory:
    phpt-tests-runner tests
  Execute tests single test:
    phpt-tests-runner tests/sample.phpt
  Execute tests from tests directory, but skip slow tests using environment variable:
    SKIP_SLOW_TESTS=1 phpt-tests-runner tests

PHPT Format:
  This runner uses modification of PHPT format used by PHP itself, so that it can run many original PHPT tests without any changes.

  PHPT test if text file with *.phpt extension.
  Each file contains sections followed by section contents, everything before first section is ignored, you can use it for storing test description.

  Required sections are --FILE-- and one of [--EXPECT--, --EXPECTF--, --EXPECTREGEX--].

PHPT sections supported:
  --FILE--        The test source code
  --EXPECT--      The expected output from the test script (will be executed as PHP script, so it might be code as well as plain text)
  --EXPECTF--     Similar to --EXPECT--, but it uses substitution tags for strings, spaces, digits, which may vary between test runs
    The following is a list of all tags and what they are used to represent:
      %s One or more of anything (character or white space) except the end of line character
      %S Zero or more of anything (character or white space) except the end of line character
      %a One or more of anything (character or white space) including the end of line character
      %A Zero or more of anything (character or white space) including the end of line character
      %w Zero or more white space characters
      %i A signed integer value, for example +3142, -3142
      %d An unsigned integer value, for example 123456
      %x One or more hexadecimal character. That is, characters in the range 0-9, a-f, A-F
      %f A floating point number, for example: 3.142, -3.142, 3.142E-10, 3.142e+10
      %c A single character of any sort (.)
  --EXPECTREGEX-- Similar to --EXPECT--, but is treated as regular expression
  --SKIPIF--      If output of execution starts with `skip` then test will be skipped
  --INI--         Specific php.ini setting for the test, one per line
  --ARGS--        A single line defining the arguments passed to php
  --CLEAN--       Code that is executed after a test completes

PHPT tests examples:
  Examples can be found at <https://qa.php.net/phpt_details.php> (taking into account differences here)

Main differences from original PHPT tests files:
  1. --TEST-- is not required and not even used (files names are used instead)
  2. Only sub-set of sections supported and only sub-set of --EXPECTF-- tags
  3. --EXPECT*-- sections are interpreted as code and its output is used as expected result

Требования

  • PHP 7.0+

Как использовать?

Просто добавьте зависимость nazar-pc/phpt-tests-runner в ваш файл composer.json

{
    "require-dev": {
        "nazar-pc/phpt-tests-runner": "1.*"
    }
}

Затем выполните тесты следующим образом

vendor/bin/phpt-tests-runner tests

Или если вам нужны переменные окружения для пропагации в тесты

php -d variables_order=EGPCS vendor/bin/phpt-tests-runner tests

Альтернативно вы можете установить его глобально с помощью Composer, например

sudo COMPOSER_BIN_DIR=/usr/local/bin composer global require nazar-pc/phpt-tests-runner

COMPOSER_BIN_DIR=/usr/local/bin даст команду Composer устанавливать бинарный файл в /usr/local/bin, чтобы вы могли вызывать phpt-tests-runner после установки. Альтернативно вы можете пропустить это и добавить ~/.composer/vendor/bin/ в ваш PATH.

Вклад

Не стесняйтесь создавать вопросы и отправлять запросы на добавление, они высоко ценились!

Лицензия

Свободная общественная лицензия 1.0.0 / Лицензия BSD с нулевым пунктом

https://open-source.org.cn/licenses/FPL-1.0.0

https://tldrlegal.com/license/bsd-0-clause-license