Skip to content

Commit

Permalink
CI test laravel 5 (#1)
Browse files Browse the repository at this point in the history
* test: create mock object by builder

* ci: uncomment 7.3-5.8

* ci: allow PR for CI

* fix: try comment test to make it pass

* ci: fix php unit version

* ci: allow 7.2-5.x 7.3-5.6

* uncomment test
  • Loading branch information
evan361425 authored Jun 29, 2021
1 parent f76b2f4 commit 8f95464
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 36 deletions.
65 changes: 37 additions & 28 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ on:
branches:
- master
pull_request:
branches:
- master

jobs:
php-cs-fixer:
Expand All @@ -23,11 +21,11 @@ jobs:
fail-fast: false
matrix:
versions:
# - "7.2-5.6"
# - "7.2-5.8"
- "7.2-5.6"
- "7.2-5.8"
- "7.2-6"
# - "7.3-5.6"
# - "7.3-5.8"
- "7.3-5.6"
- "7.3-5.8"
- "7.3-6"
- "7.3-7"
- "7.4-6"
Expand All @@ -40,7 +38,31 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set up composer.json
- name: Set up PHPUnit version
id: phpunit
uses: actions/github-script@v4
with:
result-encoding: string
script: |
const [php, laravel] = '${{ matrix.versions }}'.split('-');
return laravel.startsWith("5")
? laravel.split(".")[1] === "5"
? "6.0"
: "7"
: laravel.startsWith("6")
? "8"
: "9";
- name: Set up PHP version
id: php
uses: actions/github-script@v4
with:
result-encoding: string
script: |
const [php] = '${{ matrix.versions }}'.split('-');
return php;
- name: Update composer.json
id: composer
uses: actions/github-script@v4
with:
Expand All @@ -51,33 +73,17 @@ jobs:
composer.require['php'] = '~'.concat(php);
composer.require['laravel/framework'] = '~'.concat(laravel);
composer['require-dev']['phpunit/phpunit'] = '~${{ steps.phpunit.outputs.result }}';
if (laravel.startsWith('5')) {
const laravelMinor = laravel.split('.')[1] || '5';
composer['require-dev']['orchestra/testbench'] = '~3.'+laravelMinor;
composer['require-dev']['phpunit/phpunit'] = laravelMinor === '5' ? '~6.0' : '^7.5';
} else if (laravel.startsWith('6')) {
composer['require-dev']['orchestra/testbench'] = '~4';
composer['require-dev']['phpunit/phpunit'] = '~8';
} else if (laravel.startsWith('7')) {
composer['require-dev']['orchestra/testbench'] = '~5';
composer['require-dev']['phpunit/phpunit'] = '~9';
} else if (laravel.startsWith('8')) {
composer['require-dev']['orchestra/testbench'] = '~6';
composer['require-dev']['phpunit/phpunit'] = '~9';
composer['require-dev']['orchestra/testbench'] = '~3.'+laravel.split('.')[1] || '5';
} else {
const version = parseInt(laravel.split('.')[0], 10);
composer['require-dev']['orchestra/testbench'] = '~'.concat(version-2);
}
return JSON.stringify(composer);
- name: Set up PHP version
id: php
uses: actions/github-script@v4
with:
result-encoding: string
script: |
const [php] = '${{ matrix.versions }}'.split('-');
return php;
- name: Rewrite composer.json
run: |
rm composer.json
Expand All @@ -89,3 +95,6 @@ jobs:
php_version: ${{ steps.php.outputs.result }}

- uses: php-actions/phpunit@v3
with:
version: ${{ steps.phpunit.outputs.result }}
php_version: ${{ steps.php.outputs.result }}
24 changes: 16 additions & 8 deletions tests/Collectors/SegmentCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
use Illuminate\Http\Request;
use Napp\Xray\Collectors\SegmentCollector;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\MockObject\MockObject;

class SegmentCollectorTest extends TestCase
{
public function test_disable_trace_if_filtered()
{
$request = $this->createMock(Request::class);
$request->expects($this->any())->method('ip')->willReturn('some-ip');
$request->expects($this->any())->method('url')->willReturn('some-url');
$request->expects($this->any())->method('method')->willReturn('GET');
$request = $this->createRequest();
$request->expects($this->any())->method('path')->willReturn('filter/path');

$segment = new SegmentCollector();
Expand All @@ -26,10 +24,7 @@ public function test_disable_trace_if_filtered()

public function test_should_enable_trace()
{
$request = $this->createMock(Request::class);
$request->expects($this->any())->method('ip')->willReturn('some-ip');
$request->expects($this->any())->method('url')->willReturn('some-url');
$request->expects($this->any())->method('method')->willReturn('GET');
$request = $this->createRequest();
$request->expects($this->any())->method('path')->willReturn('normal/path');

$segment = new SegmentCollector();
Expand All @@ -38,6 +33,19 @@ public function test_should_enable_trace()
$this->assertTrue($segment->tracer()->isSampled());
}

protected function createRequest(): MockObject
{
$request = $this->getMockBuilder(Request::class)
->setMethods(['ip', 'url', 'method', 'path'])
->getMock();

$request->expects($this->any())->method('ip')->willReturn('some-ip');
$request->expects($this->any())->method('url')->willReturn('some-url');
$request->expects($this->any())->method('method')->willReturn('GET');

return $request;
}

/**
* Define environment setup.
*
Expand Down

0 comments on commit 8f95464

Please sign in to comment.