Skip to content

Commit bda7299

Browse files
committed
Add gitlab workflow to test library in different environments
1 parent 0e1fc5d commit bda7299

File tree

6 files changed

+113
-8
lines changed

6 files changed

+113
-8
lines changed

.github/workflows/ci.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Tests
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
7+
tests:
8+
name: Tests
9+
runs-on: ubuntu-latest
10+
env:
11+
MOCKSERVER_URL: 'http://localhost:1080'
12+
services:
13+
mockserver:
14+
image: mockserver/mockserver
15+
ports:
16+
- "1080:1080"
17+
volumes:
18+
- /docker/mockserver/expectations:/expectations
19+
env:
20+
MOCKSERVER_INITIALIZATION_JSON_PATH: /docker/mockserver/expectations/**.json
21+
MOCKSERVER_LOG_LEVEL: WARN
22+
continue-on-error: ${{ matrix.experimental }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
dependencies:
27+
- "lowest"
28+
- "highest"
29+
php:
30+
- '7.4'
31+
- '8.0'
32+
experimental:
33+
- false
34+
include:
35+
- php: "8.1"
36+
composer-options: "--ignore-platform-reqs"
37+
experimental: true
38+
dependencies: "highest"
39+
- php: "8.2"
40+
composer-options: "--ignore-platform-reqs"
41+
experimental: true
42+
dependencies: "highest"
43+
steps:
44+
- name: Set up PHP
45+
uses: shivammathur/setup-php@2.24.0
46+
with:
47+
php-version: ${{ matrix.php }}
48+
extensions: intl, mbstring
49+
tools: "composer:v2"
50+
51+
- name: Checkout code
52+
uses: actions/checkout@v2
53+
54+
- name: "Install lowest dependencies"
55+
if: ${{ matrix.dependencies == 'lowest' }}
56+
run: composer update --prefer-lowest --no-interaction --no-progress --no-suggest ${{ matrix.composer-options }}
57+
58+
- name: "Install highest dependencies"
59+
if: ${{ matrix.dependencies == 'highest' }}
60+
run: composer update --no-interaction --no-progress --no-suggest ${{ matrix.composer-options }}
61+
62+
- name: "Run unit tests"
63+
run: ./vendor/bin/phpunit -c phpunit.xml
64+
65+
cs:
66+
name: Codestyle check on PHP 7.4
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: Set up PHP
70+
uses: shivammathur/setup-php@2.24.0
71+
with:
72+
php-version: 7.4
73+
74+
- name: Checkout code
75+
uses: actions/checkout@v2
76+
77+
- name: Download dependencies
78+
run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable
79+
80+
- name: Run tests
81+
run: ./vendor/bin/phpcs
82+
83+
static-analysis:
84+
name: Static analysis
85+
runs-on: ubuntu-latest
86+
strategy:
87+
matrix:
88+
php:
89+
- '7.4'
90+
steps:
91+
- name: Set up PHP
92+
uses: shivammathur/setup-php@2.24.0
93+
with:
94+
php-version: ${{ matrix.php }}
95+
96+
- name: Checkout code
97+
uses: actions/checkout@v2
98+
99+
- name: Download dependencies
100+
run: composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable
101+
102+
- name: Run PHPStan
103+
run: ./vendor/bin/phpstan analyse --memory-limit 512M

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ services:
55
build:
66
dockerfile: docker/php/Dockerfile
77
context: .
8+
environment:
9+
MOCKSERVER_URL: 'http://mockserver:1080'
810
volumes:
911
- .:/app
1012
tty: true

tests/Integration/NotMatchedRequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ private function initialize(string $notMatchedRequestConfig): void
2121
$this->sot = new MockServerHelper(
2222
$moduleContainer,
2323
[
24-
'url' => 'http://mockserver:1080',
24+
'url' => getenv('MOCKSERVER_URL'),
2525
'notMatchedRequest' => $notMatchedRequestConfig,
2626
'expectationsPath' => __DIR__ . '/../../docker/mockserver/expectations',
2727
]
2828
);
2929
$this->sot->_initialize();
3030
$this->sot->_beforeSuite();
31-
$this->client = new Client(['proxy' => 'http://mockserver:1080', 'verify' => false]);
31+
$this->client = new Client(['proxy' => getenv('MOCKSERVER_URL'), 'verify' => false]);
3232
$this->sot->clearMockServerLogs();
3333
}
3434

tests/Integration/SeeAllRequestWereMatchedTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ protected function initialize(string $notMatchedRequest): void
1818
{
1919
$moduleContainer = $this->createMock(ModuleContainer::class);
2020
$config = [
21-
'url' => 'http://mockserver:1080',
21+
'url' => getenv('MOCKSERVER_URL'),
2222
'notMatchedRequest' => $notMatchedRequest,
2323
'expectationsPath' => __DIR__ . '/../../docker/mockserver/expectations',
2424
];
2525
$this->sot = new MockServerHelper($moduleContainer, $config);
2626
$this->sot->_initialize();
2727
$this->sot->_beforeSuite();
28-
$this->client = new Client(['proxy' => 'http://mockserver:1080', 'verify' => false]);
28+
$this->client = new Client(['proxy' => getenv('MOCKSERVER_URL'), 'verify' => false]);
2929
$this->sot->clearMockServerLogs();
3030
}
3131

tests/Integration/SeeMockRequestWasCalledTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ protected function setUp(): void
1818
parent::setUp();
1919
$moduleContainer = $this->createMock(ModuleContainer::class);
2020
$config = [
21-
'url' => 'http://mockserver:1080',
21+
'url' => getenv('MOCKSERVER_URL'),
2222
'expectationsPath' => __DIR__ . '/../../docker/mockserver/expectations',
2323
];
2424
$this->sot = new MockServerHelper($moduleContainer, $config);
2525
$this->sot->_initialize();
2626
$this->sot->_beforeSuite();
27-
$this->client = new Client(['proxy' => 'http://mockserver:1080', 'verify' => false]);
27+
$this->client = new Client(['proxy' => getenv('MOCKSERVER_URL'), 'verify' => false]);
2828
$this->sot->clearMockServerLogs();
2929
}
3030

tests/Integration/SeeMockRequestWasNotCalledTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ protected function setUp(): void
1717
{
1818
parent::setUp();
1919
$config = [
20-
'url' => 'http://mockserver:1080',
20+
'url' => getenv('MOCKSERVER_URL'),
2121
'expectationsPath' => __DIR__ . '/../../docker/mockserver/expectations',
2222
];
2323
$moduleContainer = $this->createMock(ModuleContainer::class);
2424
$this->sot = new MockServerHelper($moduleContainer, $config);
2525
$this->sot->_initialize();
2626
$this->sot->_beforeSuite();
27-
$this->client = new Client(['proxy' => 'http://mockserver:1080', 'verify' => false]);
27+
$this->client = new Client(['proxy' => getenv('MOCKSERVER_URL'), 'verify' => false]);
2828
$this->sot->clearMockServerLogs();
2929
}
3030

0 commit comments

Comments
 (0)