Skip to content

Commit a803111

Browse files
committed
Move coverage jobs to CircleCI
1 parent 5e9d298 commit a803111

File tree

13 files changed

+228
-51
lines changed

13 files changed

+228
-51
lines changed

.circleci/config.yml

Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
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 build/cov
81+
for f in $(find tests -name '*Test.php' | circleci tests split --split-by=timings); do
82+
_f=${f//\//_}
83+
phpdbg -qrr vendor/bin/phpunit --coverage-php build/cov/coverage-"${_f}".cov --log-junit build/logs/"${_f}".xml "$f"
84+
done
85+
- run:
86+
name: Merge PHPUnit test reports
87+
command: |-
88+
mkdir -p build/logs/phpunit
89+
npx junit-merge --out build/logs/phpunit/junit.xml --dir build/logs
90+
rm build/logs/*.xml
91+
- store_test_results:
92+
path: build/logs
93+
- store_artifacts:
94+
path: build/logs/phpunit/junit.xml
95+
destination: build/logs/phpunit/junit.xml
96+
- persist_to_workspace:
97+
root: build
98+
paths:
99+
- cov
100+
- *save-npm-cache-by-revision
101+
- *save-npm-cache-by-branch
102+
103+
behat-php-7.2-coverage:
104+
docker:
105+
- image: circleci/php:7.2-node-browsers
106+
environment:
107+
SYMFONY_DEPRECATIONS_HELPER: weak_vendors
108+
APP_ENV: test
109+
parallelism: 2
110+
working_directory: ~/api-platform/core
111+
steps:
112+
- checkout
113+
- *restore-composer-cache
114+
- *restore-npm-cache
115+
- *disable-xdebug-php-extension
116+
- *disable-php-memory-limit
117+
- *update-composer
118+
- *update-project-dependencies
119+
- *save-composer-cache-by-revision
120+
- *save-composer-cache-by-branch
121+
- *clear-test-app-cache
122+
- run:
123+
name: Run Behat tests
124+
command: |-
125+
mkdir -p build/logs build/cov
126+
for f in $(find features -name '*.feature' -not -path 'features/main/exposed_state.feature' | circleci tests split --split-by=timings); do
127+
_f=${f//\//_}
128+
FEATURE="${_f}" phpdbg -qrr vendor/bin/behat --profile=coverage --suite=default --tags=~@postgres --format=progress --out=std --format=junit --out=build/logs "$f"
129+
mv build/logs/default.xml build/logs/"${_f}".xml
130+
done
131+
- run:
132+
name: Merge Behat test reports
133+
command: |-
134+
mkdir -p build/logs/behat
135+
npx junit-merge --out build/logs/behat/junit.xml --dir build/logs
136+
rm build/logs/*.xml
137+
- store_test_results:
138+
path: build/logs
139+
- store_artifacts:
140+
path: build/logs/behat/junit.xml
141+
destination: build/logs/behat/junit.xml
142+
- persist_to_workspace:
143+
root: build
144+
paths:
145+
- cov
146+
- *save-npm-cache-by-revision
147+
- *save-npm-cache-by-branch
148+
149+
merge-and-upload-coverage:
150+
docker:
151+
- image: circleci/php:7.2-node-browsers
152+
working_directory: ~/api-platform/core
153+
steps:
154+
- checkout
155+
- *restore-npm-cache
156+
- *disable-xdebug-php-extension
157+
- *disable-php-memory-limit
158+
- run:
159+
name: Download phpcov
160+
command: wget https://phar.phpunit.de/phpcov.phar
161+
- attach_workspace:
162+
at: build
163+
- run:
164+
name: Merge code coverage reports
165+
command: |-
166+
mkdir -p build/logs
167+
phpdbg -qrr phpcov.phar merge --clover build/logs/clover.xml build/cov
168+
- store_artifacts:
169+
path: build/logs/clover.xml
170+
destination: build/logs/clover.xml
171+
- run:
172+
name: Upload code coverage report to Coveralls
173+
command: |-
174+
if [[ "$CIRCLE_REPOSITORY_URL" =~ github\.com(/|:)api-platform/core($|\.git) ]]; then
175+
npx @cedx/coveralls build/logs/clover.xml
176+
else
177+
echo 'Skipping on forked repository'
178+
fi
179+
- run:
180+
name: Upload code coverage report to Codecov
181+
command: npx codecov --file=build/logs/clover.xml
182+
- *save-npm-cache-by-revision
183+
- *save-npm-cache-by-branch
184+
185+
workflows:
186+
version: 2
187+
test-with-coverage:
188+
jobs:
189+
- phpunit-php-7.2-coverage
190+
- behat-php-7.2-coverage
191+
- merge-and-upload-coverage:
192+
requires:
193+
- phpunit-php-7.2-coverage
194+
- 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)