Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,41 @@ on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest


services:
mysql:
image: mysql:8.0
env:
MYSQL_DATABASE: ${{ secrets.DB_TEST_NAME }}
MYSQL_USER: ${{ secrets.DB_TEST_USER }}
MYSQL_PASSWORD: ${{ secrets.DB_TEST_PASS }}
MYSQL_ROOT_PASSWORD: ${{ secrets.DB_TEST_PASS }}
ports:
- 3306:3306
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=5

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.3'
tools: composer

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run Debbie tests
env:
DB_TEST_HOST: 127.0.0.1
DB_TEST_NAME: ${{ secrets.DB_TEST_NAME }}
DB_TEST_USER: ${{ secrets.DB_TEST_USER }}
DB_TEST_PASS: ${{ secrets.DB_TEST_PASS }}
run: |
# Run your test suite and generate JUnit XML
php cli.php tests -report=junit
Expand Down
26 changes: 25 additions & 1 deletion cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
* argv[3] -> case (optional)
* argv[4] -> -report=html (optional)
* argv[5] -> -output="./output/out.html" (optional), if no path is specified it will be saved in the root
* JUnit example -> php cli.php tests -report=junit reports/test-results.xml
* */

$output = '.'. DIRECTORY_SEPARATOR;
$report = 'html';
$output_index = 0;
$report_index = 0;
$junit_output = 'test-results.xml';
$junit_output_index = 0;
$test_start_time = 0;
$test_end_time = 0;
$test_time = 0;
Expand All @@ -33,6 +36,13 @@
$report = end($type_out);
$argc--;
$report_index = $i;

if ($report == 'junit' && isset($argv[$i + 1]) && substr($argv[$i + 1], 0, 1) != '-')
{
$junit_output = $argv[$i + 1];
$junit_output_index = $i + 1;
$argc--;
}
}

if ($search == '-output')
Expand All @@ -47,6 +57,7 @@
// remove output and report parameters, so the rest are in the same order for the execution (suite, class, function)
if ($output_index > 0) unset($argv[$output_index]);
if ($report_index > 0) unset($argv[$report_index]);
if ($junit_output_index > 0) unset($argv[$junit_output_index]);
$argv = array_values($argv);

if ($argc < 2)
Expand Down Expand Up @@ -105,7 +116,20 @@
}
else if ($report == 'junit')
{
$exit_code = $run->generate_junit_xml();
$builder = new \CaboLabs\Debbie\JunitXmlBuilder();
$generated = $builder->generateFromReports(
$run->get_reports(),
$junit_output
);

if (!$generated)
{
$exit_code = 1;
}
else
{
$exit_code = $builder->hasFailures() ? 1 : 0;
}
}
else
{
Expand Down
Loading
Loading