Skip to content

Commit cd602f1

Browse files
committed
feat: add coverage report at github action
1 parent cbf0de0 commit cd602f1

File tree

6 files changed

+53
-14
lines changed

6 files changed

+53
-14
lines changed

.github/workflows/php.yml

+21-12
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,27 @@ jobs:
5353
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
5454
# Docs: https://getcomposer.org/doc/articles/scripts.md
5555

56+
# phpunit -v --debug
5657
- name: Run test suite
5758
run: |
58-
phpunit -v --debug
59-
php example flags-demo.php
60-
php example sflags-demo.php
59+
php example/flags-demo.php
60+
php example/sflags-demo.php
61+
phpdbg -qrr $(which phpunit) --coverage-clover ./test/clover.info
6162
62-
# git status && git log -1 && git fetch --tags --force
63-
# git status && git log -1 && git fetch --prune --unshallow
64-
# git status && git log -1 && git fetch --depth=500 --tags --force
65-
# - name: Generate changelog
66-
# if: ${{ matrix.os == 'ubuntu-latest' && matrix.php == '7.4' }}
67-
# run: |
68-
# echo "changelog list by kite"
69-
# php bin/kite git chlog last head --style gh-release --no-merges --fetch-tags --unshallow --file tmp/changelog.md
70-
# cat tmp/changelog.md
63+
- name: Coveralls Parallel
64+
uses: coverallsapp/github-action@master
65+
with:
66+
github-token: ${{ secrets.github_token }}
67+
path-to-lcov: ./test/clover.info
68+
flag-name: run-${{ matrix.php }}
69+
parallel: true
70+
71+
finish:
72+
needs: test
73+
runs-on: ubuntu-latest
74+
steps:
75+
- name: Coveralls Finished
76+
uses: coverallsapp/github-action@master
77+
with:
78+
github-token: ${{ secrets.github_token }}
79+
parallel-finished: true

Makefile

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# 每行命令之前必须有一个tab键。如果想用其他键,可以用内置变量.RECIPEPREFIX 声明
44
# mac 下这条声明 没起作用 !!
55
.RECIPEPREFIX = >
6-
.PHONY: all usage help clean
6+
.PHONY: all usage help clean test
77

88
# 需要注意的是,每行命令在一个单独的shell中执行。这些Shell之间没有继承关系。
99
# - 解决办法是将两行命令写在一行,中间用分号分隔。
@@ -14,6 +14,7 @@
1414

1515
# 定义变量
1616
#SHELL := /bin/bash
17+
PHPUNIT =$(which phpunit)
1718

1819
# Full build flags used when building binaries. Not used for test compilation/execution.
1920
#BUILDFLAGS := -ldflags \
@@ -33,6 +34,12 @@ help:
3334
clean: ## Clean all created artifacts
3435
git clean --exclude=.idea/ -fdx
3536

37+
test: ## run phpunit tests with --debug
38+
phpunit --debug
39+
40+
cover-test: ## run phpunit tests with --coverage-text
41+
phpdbg -qrr $(PHPUNIT) --coverage-text
42+
3643
csfix: ## Fix code style for all files
3744
php-cs-fixer fix ./
3845

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![Actions Status](https://github.com/php-toolkit/pflag/workflows/Unit-Tests/badge.svg)](https://github.com/php-toolkit/pflag/actions)
66
[![Php Version Support](https://img.shields.io/packagist/php-v/toolkit/pflag)](https://packagist.org/packages/toolkit/pflag)
77
[![Latest Stable Version](http://img.shields.io/packagist/v/toolkit/pflag.svg)](https://packagist.org/packages/toolkit/pflag)
8+
[![Coverage Status](https://coveralls.io/repos/github/php-toolkit/pflag/badge.svg?branch=main)](https://coveralls.io/github/php-toolkit/pflag?branch=main)
89

910
Generic PHP command line flags parse library
1011

@@ -498,6 +499,7 @@ test with coverage:
498499

499500
```bash
500501
phpdbg -qrr $(which phpunit) --coverage-text
502+
phpdbg -qrr $(which phpunit) --coverage-clover ./test/clover.info
501503
```
502504

503505
## Project use

README.zh-CN.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
[![Actions Status](https://github.com/php-toolkit/pflag/workflows/Unit-Tests/badge.svg)](https://github.com/php-toolkit/pflag/actions)
66
[![Php Version Support](https://img.shields.io/packagist/php-v/toolkit/pflag)](https://packagist.org/packages/toolkit/pflag)
77
[![Latest Stable Version](http://img.shields.io/packagist/v/toolkit/pflag.svg)](https://packagist.org/packages/toolkit/pflag)
8+
[![Coverage Status](https://coveralls.io/repos/github/php-toolkit/pflag/badge.svg?branch=main)](https://coveralls.io/github/php-toolkit/pflag?branch=main)
89

910
`pflag` - PHP编写的,通用的命令行标志(选项和参数)解析库
1011

src/FlagsParser.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Toolkit\Cli\Cli;
66
use Toolkit\Cli\Helper\FlagHelper;
7+
use Toolkit\Cli\Util\LineParser;
78
use Toolkit\PFlag\Concern\HelperRenderTrait;
89
use Toolkit\PFlag\Concern\RuleParserTrait;
910
use Toolkit\PFlag\Contract\ParserInterface;
@@ -228,9 +229,22 @@ public function __construct(array $config = [])
228229
Obj::init($this, $config);
229230
}
230231

231-
public function parseFromString(string $cmdline): bool
232+
/**
233+
* @param string $cmdline
234+
* @param bool $hasBin
235+
*
236+
* @return bool
237+
*/
238+
public function parseCmdline(string $cmdline, bool $hasBin = true): bool
232239
{
240+
$flags = LineParser::parseIt($cmdline);
241+
242+
if ($hasBin && $flags) {
243+
$sFile = array_shift($flags);
244+
$this->setScriptFile($sFile);
245+
}
233246

247+
return $this->parse($flags);
234248
}
235249

236250
/**

test/FlagsParserTest.php

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ private function doCheckBasic(FlagsParser $fs): void
4545
$this->assertFalse($fs->hasInputOpt('name'));
4646
$this->assertFalse($fs->hasOpt('not-exist'));
4747
$this->assertNotEmpty($fs->getOptDefine('name'));
48+
49+
$fs->parseCmdline('bin/app --name inhere http://github.com/inhere');
50+
$this->assertSame('bin/app', $fs->getScriptFile());
51+
$this->assertSame('app', $fs->getScriptName());
52+
$this->assertSame('inhere', $fs->getOpt('name'));
53+
$this->assertSame('http://github.com/inhere', $fs->getArg('github'));
4854
}
4955

5056
public function testGetOptAndGetArg(): void

0 commit comments

Comments
 (0)