Skip to content

Commit

Permalink
Add test case and fixed Baidu accesstoken error fix#10 (#11)
Browse files Browse the repository at this point in the history
* Add test case and fixed Baidu accesstoken error fix#10

* Refine test cases

* Run php-cs-fixer

* Fixed test fail

* Add github action support

* Add github action support

* environment support

* environment support

* Add php8.0 support

* Update documentation

* Change codecov version to v0.1.15
  • Loading branch information
godruoyi authored May 3, 2022
1 parent 3106eee commit d6ab682
Show file tree
Hide file tree
Showing 61 changed files with 2,634 additions and 1,173 deletions.
95 changes: 95 additions & 0 deletions .github/workflows/php.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: php
on:
pull_request:
push:
jobs:
phptests:
runs-on: ${{ matrix.operating-system }}
environment: OCR
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: composer:v2
extensions: gd
coverage: none

- name: Install dependencies
uses: nick-invision/retry@v1
with:
timeout_minutes: 5
max_attempts: 5
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress

- name: PHPUnit Test
run: vendor/bin/phpunit --verbose
env:
BAIDU_ACCESS_KEY: ${{ secrets.BAIDU_ACCESS_KEY }}
BAIDU_SECRET_KEY: ${{ secrets.BAIDU_SECRET_KEY }}
ALIYUN_APPCODE: ${{ secrets.ALIYUN_APPCODE }}
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }}

code-coverage:
name: Code Coverage
runs-on: ubuntu-latest
environment: OCR
strategy:
fail-fast: false
matrix:
php-version:
- 8.0
dependencies:
- highest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
coverage: pcov
extensions: gd
tools: composer:v2, php-cs-fixer

- name: Coding Guidelines
run: php-cs-fixer fix --config=.php-cs-fixer.php

- name: Install lowest dependencies with composer
if: matrix.dependencies == 'lowest'
run: composer update --no-ansi --no-interaction --no-progress --prefer-lowest

- name: Install highest dependencies with composer
if: matrix.dependencies == 'highest'
run: composer update --no-ansi --no-interaction --no-progress

- name: Collect code coverage with phpunit
run: vendor/bin/phpunit --coverage-clover=coverage.xml
env:
BAIDU_ACCESS_KEY: ${{ secrets.BAIDU_ACCESS_KEY }}
BAIDU_SECRET_KEY: ${{ secrets.BAIDU_SECRET_KEY }}
ALIYUN_APPCODE: ${{ secrets.ALIYUN_APPCODE }}
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }}

- name: Send code coverage report to Codecov.io
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
version: "v0.1.15"
env:
BAIDU_ACCESS_KEY: ${{ secrets.BAIDU_ACCESS_KEY }}
BAIDU_SECRET_KEY: ${{ secrets.BAIDU_SECRET_KEY }}
ALIYUN_APPCODE: ${{ secrets.ALIYUN_APPCODE }}
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }}
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
vendor
composer.lock
tests/stubs/*.jpg
tests/stubs/*.png
tests/stubs/*.jpeg
tests/stubs/config.php
.DS_Store
.php_cs.cache
.idea
*.DS_Store
composer.lock
*.log
/.php-cs-fixer.cache
/.phpunit.result.cache
30 changes: 30 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

$header = <<<EOF
This file is part of the godruoyi/ocr.
(c) Godruoyi <gmail@godruoyi.com>
This source file is subject to the MIT license that is bundled.
EOF;

use PhpCsFixer\Config;
use PhpCsFixer\Finder;

return (new Config())->setRules([
'@PSR2' => true,
'header_comment' => ['header' => $header],
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
])
->setFinder(
Finder::create()
->in(__DIR__)
->exclude('vendor')
->name('*.php')
->notName('*.blade.php')
)
->setUsingCache(false)
->setRiskyAllowed(true);
27 changes: 0 additions & 27 deletions .php_cs

This file was deleted.

14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

----

### [2.1.0](https://github.com/godruoyi/ocr/tree/2.0.0) - 2022-05-03

#### Breaking Changes

- PHP 最低版本支持 7.1.3

#### Fixed

- 支持新版百度 AccessToken
- 完善测试用例
- 支持 PHP7.1.3 及以上版本

### [2.0.0](https://github.com/godruoyi/ocr/tree/2.0.0) - 2020-11-12

- 重写整个 sdk
- 加入类 laravel container 支持
- 加入 easy container 支持
- 重新整理各平台目前支持的接口文档
- 返回标准的 Pse Response
- 不再对请求成功做判断
Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<div>
<p align="center">The Best Image Ocr SDK For BAT.</p>
<p align="center">
<a href="https://github.com/godruoyi/ocr/actions/workflows/php.yml">
<image src="https://github.com/godruoyi/ocr/actions/workflows/php.yaml/badge.svg" alt="build passed" />
</a>
<a href="https://codecov.io/gh/godruoyi/ocr">
<img src="https://codecov.io/gh/godruoyi/ocr/branch/master/graph/badge.svg?token=7AAOYCJK97"/>
</a>
<a href="https://github.com/godruoyi/ocr">
<image src="https://poser.pugx.org/godruoyi/ocr/license" alt="License">
<image src="https://poser.pugx.org/godruoyi/ocr/license" alt="License" />
</a>
<a href="https://packagist.org/packages/godruoyi/ocr">
<image src="https://poser.pugx.org/godruoyi/ocr/v/stable" alt="Packagist Version">
<image src="https://poser.pugx.org/godruoyi/ocr/v/stable" alt="Packagist Version" />
</a>
<a href="https://github.com/godruoyi/ocr">
<image src="https://poser.pugx.org/godruoyi/ocr/downloads" alt="Total Downloads">
<image src="https://poser.pugx.org/godruoyi/ocr/downloads" alt="Total Downloads" />
</a>
</p>
</div>
Expand All @@ -31,15 +37,15 @@

## Requirement

- PHP >= 7.0
- PHP >= 7.1
- composer

## Installation

> 注意此版本**不兼容** 1.x 版本,若你在寻在 1.x 版本,请查看 [这里](https://github.com/godruoyi/ocr/tree/1.1.4)
```
composer require "godruoyi/ocr:^2.0"
composer require "godruoyi/ocr:^2.1"
```

## Document
Expand Down
23 changes: 12 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@
"name": "godruoyi/ocr",
"description": "The Best Image Ocr SDK For BAT.",
"keywords": ["OCR", "文字识别", "百度 OCR", "腾讯 OCR", "阿里云 OCR"],
"homepage": "http://github.com/godruoyi/ocr",
"homepage": "https://github.com/godruoyi/ocr",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "godruoyi",
"email": "godruoyi@gmail.com"
}
],
"authors": [{
"name": "godruoyi",
"email": "godruoyi@gmail.com"
}],
"require": {
"php": ">=7.0",
"php": ">=7.1.3",
"guzzlehttp/guzzle": "^6.3 || ^7.0",
"monolog/monolog": "^1.22 || ^2.0",
"godruoyi/easy-container": "^1.1"
"psr/log": "^1.0",
"godruoyi/easy-container": "^1.1",
"symfony/cache": "^4.4 || ^5.0 || ^6.0"
},
"require-dev": {
"phpunit/phpunit": "^6",
"mockery/mockery": "^1.2"
"phpunit/phpunit": ">=6.0",
"mockery/mockery": "^1.0",
"ext-gd": "*"
},
"autoload": {
"psr-4": {
Expand Down
29 changes: 16 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</include>
</coverage>

<php>
<env name="ENVIRONMENT" value="" />
<env name="BAIDU_ACCESS_KEY" value="" />
<env name="BAIDU_SECRET_KEY" value="" />
<env name="ALIYUN_APPCODE" value="" />
<env name="TENCENT_SECRET_ID" value="" />
<env name="TENCENT_SECRET_KEY" value="" />
</php>

</phpunit>
Loading

0 comments on commit d6ab682

Please sign in to comment.