Skip to content

Commit 3ac4c89

Browse files
authored
Merge pull request #1888 from teohhanhui/ci/parallel-jobs
Move coverage jobs to CircleCI
2 parents 6ae3583 + a4825cc commit 3ac4c89

File tree

13 files changed

+225
-51
lines changed

13 files changed

+225
-51
lines changed

.circleci/config.yml

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
version: 2
2+
3+
reusable-steps:
4+
- &clear-test-app-cache
5+
run:
6+
name: Clear test app cache
7+
command: tests/Fixtures/app/console cache:clear
8+
- &disable-php-memory-limit
9+
run:
10+
name: Disable PHP memory limit
11+
command: echo 'memory_limit=-1' | sudo tee -a /usr/local/etc/php/php.ini
12+
- &disable-xdebug-php-extension
13+
run:
14+
name: Disable Xdebug PHP extension
15+
command: sudo rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
16+
- &restore-composer-cache
17+
restore_cache:
18+
keys:
19+
- composer-cache-{{ .Revision }}
20+
- composer-cache-{{ .Branch }}
21+
- composer-cache
22+
- &restore-npm-cache
23+
restore_cache:
24+
keys:
25+
- npm-cache-{{ .Revision }}
26+
- npm-cache-{{ .Branch }}
27+
- npm-cache
28+
- &save-composer-cache-by-branch
29+
save_cache:
30+
paths:
31+
- ~/.composer/cache
32+
key: composer-cache-{{ .Branch }}-{{ .BuildNum }}
33+
- &save-composer-cache-by-revision
34+
save_cache:
35+
paths:
36+
- ~/.composer/cache
37+
key: composer-cache-{{ .Revision }}-{{ .BuildNum }}
38+
- &save-npm-cache-by-branch
39+
save_cache:
40+
paths:
41+
- ~/.npm
42+
key: npm-cache-{{ .Branch }}-{{ .BuildNum }}
43+
- &save-npm-cache-by-revision
44+
save_cache:
45+
paths:
46+
- ~/.npm
47+
key: npm-cache-{{ .Revision }}-{{ .BuildNum }}
48+
- &update-composer
49+
run:
50+
name: Update Composer
51+
command: composer self-update
52+
- &update-project-dependencies
53+
run:
54+
name: Update project dependencies
55+
command: composer update --prefer-dist --no-progress --no-suggest --ansi
56+
57+
jobs:
58+
phpunit-php-7.2-coverage:
59+
docker:
60+
- image: circleci/php:7.2-node-browsers
61+
environment:
62+
SYMFONY_DEPRECATIONS_HELPER: weak_vendors
63+
APP_ENV: test
64+
parallelism: 2
65+
working_directory: ~/api-platform/core
66+
steps:
67+
- checkout
68+
- *restore-composer-cache
69+
- *restore-npm-cache
70+
- *disable-xdebug-php-extension
71+
- *disable-php-memory-limit
72+
- *update-composer
73+
- *update-project-dependencies
74+
- *save-composer-cache-by-revision
75+
- *save-composer-cache-by-branch
76+
- *clear-test-app-cache
77+
- run:
78+
name: Run PHPUnit tests
79+
command: |-
80+
mkdir -p build/logs/tmp build/cov
81+
find tests -name '*Test.php' | circleci tests split --split-by=timings | parallel -j10% --rpl '{_} s/\//_/g;' \
82+
phpdbg -qrr vendor/bin/phpunit --coverage-php build/cov/coverage-{_}.cov --log-junit build/logs/tmp/{_}.xml --colors=always {}
83+
- run:
84+
name: Merge PHPUnit test reports
85+
command: |-
86+
mkdir -p build/logs/phpunit
87+
npx junit-merge --out build/logs/phpunit/junit.xml --dir build/logs/tmp
88+
rm -r build/logs/tmp
89+
- store_test_results:
90+
path: build/logs
91+
- store_artifacts:
92+
path: build/logs/phpunit/junit.xml
93+
destination: build/logs/phpunit/junit.xml
94+
- persist_to_workspace:
95+
root: build
96+
paths:
97+
- cov
98+
- *save-npm-cache-by-revision
99+
- *save-npm-cache-by-branch
100+
101+
behat-php-7.2-coverage:
102+
docker:
103+
- image: circleci/php:7.2-node-browsers
104+
environment:
105+
SYMFONY_DEPRECATIONS_HELPER: weak_vendors
106+
APP_ENV: test
107+
parallelism: 2
108+
working_directory: ~/api-platform/core
109+
steps:
110+
- checkout
111+
- *restore-composer-cache
112+
- *restore-npm-cache
113+
- *disable-xdebug-php-extension
114+
- *disable-php-memory-limit
115+
- *update-composer
116+
- *update-project-dependencies
117+
- *save-composer-cache-by-revision
118+
- *save-composer-cache-by-branch
119+
- *clear-test-app-cache
120+
- run:
121+
name: Run Behat tests
122+
command: |-
123+
mkdir -p build/logs/tmp build/cov
124+
for f in $(find features -name '*.feature' -not -path 'features/main/exposed_state.feature' | circleci tests split --split-by=timings); do
125+
_f=${f//\//_}
126+
FEATURE="${_f}" phpdbg -qrr vendor/bin/behat --profile=coverage --suite=default --tags=~@postgres --format=progress --out=std --format=junit --out=build/logs/tmp/"${_f}" "$f"
127+
done
128+
- run:
129+
name: Merge Behat test reports
130+
command: |-
131+
mkdir -p build/logs/behat
132+
npx junit-merge --out build/logs/behat/junit.xml --dir build/logs/tmp --recursive
133+
rm -r build/logs/tmp
134+
- store_test_results:
135+
path: build/logs
136+
- store_artifacts:
137+
path: build/logs/behat/junit.xml
138+
destination: build/logs/behat/junit.xml
139+
- persist_to_workspace:
140+
root: build
141+
paths:
142+
- cov
143+
- *save-npm-cache-by-revision
144+
- *save-npm-cache-by-branch
145+
146+
merge-and-upload-coverage:
147+
docker:
148+
- image: circleci/php:7.2-node-browsers
149+
working_directory: ~/api-platform/core
150+
steps:
151+
- checkout
152+
- *restore-npm-cache
153+
- *disable-xdebug-php-extension
154+
- *disable-php-memory-limit
155+
- run:
156+
name: Download phpcov
157+
command: wget https://phar.phpunit.de/phpcov.phar
158+
- attach_workspace:
159+
at: build
160+
- run:
161+
name: Merge code coverage reports
162+
command: |-
163+
mkdir -p build/logs
164+
phpdbg -qrr phpcov.phar merge --clover build/logs/clover.xml build/cov
165+
- store_artifacts:
166+
path: build/logs/clover.xml
167+
destination: build/logs/clover.xml
168+
- run:
169+
name: Upload code coverage report to Coveralls
170+
command: |-
171+
if [ ! -z "$COVERALLS_REPO_TOKEN" ]; then
172+
npx @cedx/coveralls build/logs/clover.xml
173+
else
174+
echo 'Skipped'
175+
fi
176+
- run:
177+
name: Upload code coverage report to Codecov
178+
command: npx codecov --file=build/logs/clover.xml --disable=gcov
179+
- *save-npm-cache-by-revision
180+
- *save-npm-cache-by-branch
181+
182+
workflows:
183+
version: 2
184+
test-with-coverage:
185+
jobs:
186+
- phpunit-php-7.2-coverage
187+
- behat-php-7.2-coverage
188+
- merge-and-upload-coverage:
189+
requires:
190+
- phpunit-php-7.2-coverage
191+
- behat-php-7.2-coverage

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ indent_style = space
3939
indent_size = 4
4040
trim_trailing_whitespace = false
4141

42+
[.circleci/config.yml]
43+
indent_style = space
44+
indent_size = 2
45+
4246
[.gitmodules]
4347
indent_style = tab
4448

.travis.yml

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
language: php
2-
32
sudo: false
43

54
cache:
@@ -17,8 +16,6 @@ matrix:
1716
- php: '7.0'
1817
- php: '7.1'
1918
- php: '7.2'
20-
- php: '7.2'
21-
env: coverage=1
2219
- php: '7.2'
2320
env: lint=1
2421
- php: '7.2'
@@ -43,18 +40,6 @@ matrix:
4340
before_install:
4441
- phpenv config-rm xdebug.ini || echo "xdebug not available"
4542
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
46-
- if [[ $coverage != 1 && $lint != 1 ]]; then
47-
npm install -g swagger-cli;
48-
fi
49-
- if [[ $coverage = 1 ]]; then
50-
mkdir -p build/logs build/cov;
51-
fi
52-
- if [[ $coverage = 1 ]]; then
53-
wget https://phar.phpunit.de/phpcov.phar;
54-
fi
55-
- if [[ $coverage = 1 ]]; then
56-
wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar;
57-
fi
5843
- if [[ $lint = 1 ]]; then
5944
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.8.4/php-cs-fixer.phar;
6045
fi
@@ -64,47 +49,36 @@ before_install:
6449
- export PATH="$PATH:$HOME/.composer/vendor/bin"
6550

6651
install:
67-
- if [[ $coverage = 1 ]]; then
68-
composer require --dev --no-update 'phpunit/php-code-coverage:^5.2.2';
69-
fi
7052
- if [[ $deps = 'low' ]]; then
7153
composer update --prefer-dist --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi;
7254
else
7355
composer update --prefer-dist --no-progress --no-suggest --ansi;
7456
fi
7557

7658
script:
77-
- if [[ $coverage = 1 ]]; then
78-
APP_ENV=test_phpunit phpdbg -qrr vendor/bin/phpunit --coverage-php build/cov/coverage-phpunit.cov;
79-
elif [[ $lint != 1 ]]; then
80-
APP_ENV=test_phpunit vendor/bin/phpunit;
59+
- if [[ $lint != 1 ]]; then
60+
tests/Fixtures/app/console cache:clear;
61+
fi
62+
- if [[ $lint != 1 ]]; then
63+
vendor/bin/phpunit;
64+
fi
65+
- if [[ $lint != 1 ]]; then
66+
tests/Fixtures/app/console cache:clear;
8167
fi
82-
- if [[ $coverage = 1 ]]; then
83-
for f in $(find features -name '*.feature' -not -path 'features/main/exposed_state.feature'); do
84-
FEATURE=${f//\//_} phpdbg -qrr vendor/bin/behat --profile=coverage --suite=default --tags=~@postgress --format=progress $f || exit $?;
85-
done;
86-
elif [[ $APP_ENV = 'postgres' ]]; then
68+
- if [[ $APP_ENV = 'postgres' ]]; then
8769
vendor/bin/behat --suite=postgres --format=progress;
8870
elif [[ $lint != 1 ]]; then
8971
vendor/bin/behat --suite=default --format=progress;
9072
fi
91-
- if [[ $coverage = 1 ]]; then
92-
phpdbg -qrr phpcov.phar merge --clover build/logs/clover.xml build/cov;
73+
- if [[ $lint != 1 ]]; then
74+
tests/Fixtures/app/console api:swagger:export > swagger.json && npx swagger-cli validate swagger.json && rm swagger.json;
9375
fi
94-
- if [[ $coverage != 1 && $lint != 1 ]]; then
95-
tests/Fixtures/app/console api:swagger:export > swagger.json && swagger-cli validate swagger.json && rm swagger.json;
96-
fi
97-
- if [[ $coverage != 1 && $lint != 1 ]]; then
98-
tests/Fixtures/app/console api:swagger:export --yaml > swagger.yaml && swagger-cli validate --no-schema swagger.yaml && rm swagger.yaml;
76+
- if [[ $lint != 1 ]]; then
77+
tests/Fixtures/app/console api:swagger:export --yaml > swagger.yaml && npx swagger-cli validate --no-schema swagger.yaml && rm swagger.yaml;
9978
fi
10079
- if [[ $lint = 1 ]]; then
10180
php php-cs-fixer.phar fix --dry-run --diff --no-ansi;
10281
fi
10382
- if [[ $lint = 1 ]]; then
10483
phpstan analyse -c phpstan.neon -l5 --ansi src tests;
10584
fi
106-
107-
after_success:
108-
- if [[ $coverage = 1 ]]; then
109-
travis_retry php coveralls.phar;
110-
fi

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<ini name="memory_limit" value="-1" />
1313
<server name="KERNEL_DIR" value="tests/Fixtures/app/" />
1414
<server name="KERNEL_CLASS" value="AppKernel" />
15-
<server name="APP_ENV" value="test_phpunit" />
15+
<server name="APP_ENV" value="test" />
1616
<server name="LEGACY" value="0" />
1717
</php>
1818

tests/Bridge/Doctrine/Orm/Filter/AbstractFilterTest.php renamed to src/Test/DoctrineOrmFilterTestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
declare(strict_types=1);
1313

14-
namespace ApiPlatform\Core\Tests\Bridge\Doctrine\Orm\Filter;
14+
namespace ApiPlatform\Core\Test;
1515

1616
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\FilterInterface;
1717
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
@@ -26,7 +26,7 @@
2626
/**
2727
* @author Kévin Dunglas <[email protected]>
2828
*/
29-
abstract class AbstractFilterTest extends KernelTestCase
29+
abstract class DoctrineOrmFilterTestCase extends KernelTestCase
3030
{
3131
/**
3232
* @var ManagerRegistry

tests/Bridge/Doctrine/Orm/Filter/BooleanFilterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
namespace ApiPlatform\Core\Tests\Bridge\Doctrine\Orm\Filter;
1515

1616
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
17+
use ApiPlatform\Core\Test\DoctrineOrmFilterTestCase;
1718
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
1819

1920
/**
2021
* @author Amrouche Hamza <[email protected]>
2122
*/
22-
class BooleanFilterTest extends AbstractFilterTest
23+
class BooleanFilterTest extends DoctrineOrmFilterTestCase
2324
{
2425
protected $filterClass = BooleanFilter::class;
2526

tests/Bridge/Doctrine/Orm/Filter/DateFilterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
1717
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
18+
use ApiPlatform\Core\Test\DoctrineOrmFilterTestCase;
1819
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
1920
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyDate;
2021
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\DummyImmutableDate;
@@ -25,7 +26,7 @@
2526
* @author Théo FIDRY <[email protected]>
2627
* @author Vincent CHALAMON <[email protected]>
2728
*/
28-
class DateFilterTest extends AbstractFilterTest
29+
class DateFilterTest extends DoctrineOrmFilterTestCase
2930
{
3031
protected $filterClass = DateFilter::class;
3132

tests/Bridge/Doctrine/Orm/Filter/ExistsFilterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
namespace ApiPlatform\Core\Tests\Bridge\Doctrine\Orm\Filter;
1515

1616
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
17+
use ApiPlatform\Core\Test\DoctrineOrmFilterTestCase;
1718
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
1819

1920
/**
2021
* @author Antoine Bluchet <[email protected]>
2122
*/
22-
class ExistsFilterTest extends AbstractFilterTest
23+
class ExistsFilterTest extends DoctrineOrmFilterTestCase
2324
{
2425
protected $filterClass = ExistsFilter::class;
2526

tests/Bridge/Doctrine/Orm/Filter/NumericFilterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
namespace ApiPlatform\Core\Tests\Bridge\Doctrine\Orm\Filter;
1515

1616
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\NumericFilter;
17+
use ApiPlatform\Core\Test\DoctrineOrmFilterTestCase;
1718
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
1819

1920
/**
2021
* @author Amrouche Hamza <[email protected]>
2122
*/
22-
class NumericFilterTest extends AbstractFilterTest
23+
class NumericFilterTest extends DoctrineOrmFilterTestCase
2324
{
2425
protected $filterClass = NumericFilter::class;
2526

0 commit comments

Comments
 (0)