Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ commands:
command: |
sudo pecl install mongodb-1.5.4
sudo docker-php-ext-enable mongodb
install-pcov-php-extension:
steps:
- run:
name: Install pcov PHP extension
command: |
sudo pecl install pcov-1.0.6
sudo docker-php-ext-enable pcov
merge-code-coverage-reports:
parameters:
dir:
Expand All @@ -51,14 +58,16 @@ commands:
- run:
name: Download phpcov
command: |
if [ ! -e phpcov.phar ]; then
if ! command -v phpcov; then
wget https://phar.phpunit.de/phpcov.phar
chmod +x phpcov.phar
sudo mv phpcov.phar /usr/local/bin/phpcov
fi
- run:
name: Merge code coverage reports
command: |
mkdir -p "$(dirname -- "<< parameters.out >>")"
phpdbg -qrr phpcov.phar merge --clover "<< parameters.out >>" "<< parameters.dir >>"
phpcov merge --clover "<< parameters.out >>" "<< parameters.dir >>"
merge-test-reports:
parameters:
dir:
Expand Down Expand Up @@ -263,6 +272,7 @@ jobs:
steps:
- checkout
- install-mongodb-php-extension
- install-pcov-php-extension
- disable-xdebug-php-extension
- disable-php-memory-limit
- update-composer
Expand All @@ -276,7 +286,7 @@ jobs:
mkdir -p build/logs/phpunit build/coverage
split_tests=$(find tests -name '*Test.php' | circleci tests split --split-by=timings)
export PARALLEL='-j10% --joblog build/logs/parallel.log --rpl {_}\ s/\\//_/g;'
phpunit_cmd='phpdbg -qrr vendor/bin/phpunit --coverage-php build/coverage/coverage-{_}.cov --log-junit build/logs/phpunit/{_}.xml --exclude-group mongodb,resource-hog --colors=always {}'
phpunit_cmd='vendor/bin/phpunit --coverage-php build/coverage/coverage-{_}.cov --log-junit build/logs/phpunit/{_}.xml --exclude-group mongodb,resource-hog --colors=always {}'
echo "$split_tests" | parallel "$phpunit_cmd" || echo "$split_tests" | parallel --retry-failed "$phpunit_cmd"
- restore-npm-cache
- merge-test-reports:
Expand Down Expand Up @@ -310,6 +320,7 @@ jobs:
steps:
- checkout
- install-mongodb-php-extension
- install-pcov-php-extension
- disable-xdebug-php-extension
- disable-php-memory-limit
- update-composer
Expand All @@ -323,7 +334,7 @@ jobs:
mkdir -p build/logs/behat build/coverage
for f in $(find features -name '*.feature' -not -path 'features/main/exposed_state.feature' -not -path 'features/elasticsearch/*' -not -path 'features/mongodb/*' | circleci tests split --split-by=timings); do
_f=$(echo "$f" | tr / _)
FEATURE="${_f}" phpdbg -qrr vendor/bin/behat --format=progress --out=std --format=junit --out=build/logs/behat/"${_f}" --profile=default-coverage --no-interaction "$f"
FEATURE="${_f}" vendor/bin/behat --format=progress --out=std --format=junit --out=build/logs/behat/"${_f}" --profile=default-coverage --no-interaction "$f"
done
- restore-npm-cache
- merge-test-reports:
Expand Down Expand Up @@ -355,6 +366,7 @@ jobs:
steps:
- checkout
- install-mongodb-php-extension
- install-pcov-php-extension
- disable-xdebug-php-extension
- disable-php-memory-limit
- update-composer
Expand All @@ -367,7 +379,7 @@ jobs:
name: Run PHPUnit tests
command: |
mkdir -p build/logs/phpunit
phpdbg -qrr vendor/bin/phpunit --coverage-clover build/logs/clover.xml --log-junit build/logs/phpunit/junit.xml --exclude-group resource-hog --colors=always --configuration phpunit_mongodb.xml
vendor/bin/phpunit --coverage-clover build/logs/clover.xml --log-junit build/logs/phpunit/junit.xml --exclude-group resource-hog --colors=always --configuration phpunit_mongodb.xml
- store_test_results:
path: build/logs
- store_artifacts:
Expand All @@ -392,6 +404,7 @@ jobs:
steps:
- checkout
- install-mongodb-php-extension
- install-pcov-php-extension
- disable-xdebug-php-extension
- disable-php-memory-limit
- update-composer
Expand All @@ -404,7 +417,7 @@ jobs:
name: Run Behat tests
command: |
mkdir -p build/logs/behat
phpdbg -qrr vendor/bin/behat --format=progress --out=std --format=junit --out=build/logs/behat --profile=mongodb-coverage --no-interaction
vendor/bin/behat --format=progress --out=std --format=junit --out=build/logs/behat --profile=mongodb-coverage --no-interaction
- restore-npm-cache
- merge-test-reports:
dir: build/logs/behat
Expand Down Expand Up @@ -435,6 +448,7 @@ jobs:
steps:
- checkout
- install-mongodb-php-extension
- install-pcov-php-extension
- disable-xdebug-php-extension
- disable-php-memory-limit
- update-composer
Expand All @@ -447,7 +461,7 @@ jobs:
name: Run Behat tests
command: |
mkdir -p build/logs/behat
phpdbg -qrr vendor/bin/behat --format=progress --out=std --format=junit --out=build/logs/behat --profile=elasticsearch-coverage --no-interaction
vendor/bin/behat --format=progress --out=std --format=junit --out=build/logs/behat --profile=elasticsearch-coverage --no-interaction
- restore-npm-cache
- merge-test-reports:
dir: build/logs/behat
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.php_cs
/.php_cs.cache
/.phpunit.result.cache
/build/
/composer.lock
/composer.phar
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"phpstan/phpstan-doctrine": "^0.11",
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-symfony": "^0.11",
"phpunit/phpunit": "^7.5.2",
"phpunit/phpunit": "^7.5.2 || ^8.0",
"psr/log": "^1.0",
"ramsey/uuid": "^3.7",
"ramsey/uuid-doctrine": "^1.4",
Expand Down
14 changes: 13 additions & 1 deletion features/json/input_output.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Feature: JSON DTO input and output
Given I add "Accept" header equal to "application/json"
And I add "Content-Type" header equal to "application/json"

Scenario: Messenger handler returning output object
Scenario: Request a password reset
And I send a "POST" request to "/users/password_reset_request" with body:
"""
{
Expand All @@ -23,3 +23,15 @@ Feature: JSON DTO input and output
"emailSentAt": "2019-07-05T15:44:00+00:00"
}
"""

Scenario: Request a password reset for a non-existent user
And I send a "POST" request to "/users/password_reset_request" with body:
"""
{
"email": "does-not-exist@example.com"
}
"""
Then the response status code should be 404
And the response should be in JSON
And the header "Content-Type" should be equal to "application/problem+json; charset=utf-8"
And the JSON node "detail" should be equal to "User does not exist."
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\Finder\Finder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\Yaml\Yaml;
Expand Down Expand Up @@ -526,7 +526,7 @@ private function registerMercureConfiguration(ContainerBuilder $container, array
$loader->load('doctrine_orm_mercure_publisher.xml');

// BC for Symfony Messenger 4.2
if (interface_exists(MessageBusInterface::class) && !class_exists(UnrecoverableMessageHandlingException::class)) {
if (interface_exists(MessageBusInterface::class) && !class_exists(HandlerFailedException::class)) {
$container->getDefinition('api_platform.doctrine.listener.mercure.publish')->replaceArgument(5, new Reference('message_bus', ContainerInterface::IGNORE_ON_INVALID_REFERENCE));
}
}
Expand All @@ -541,7 +541,7 @@ private function registerMessengerConfiguration(ContainerBuilder $container, arr
$loader->load('messenger.xml');

// BC for Symfony Messenger 4.2
if (interface_exists(MessageBusInterface::class) && !class_exists(UnrecoverableMessageHandlingException::class)) {
if (interface_exists(MessageBusInterface::class) && !class_exists(HandlerFailedException::class)) {
$container->setAlias('api_platform.message_bus', 'message_bus');
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\EventListener\ExceptionListener as BaseExceptionListener;
use Symfony\Component\Messenger\Exception\HandlerFailedException;

/**
* Handles requests errors.
Expand Down Expand Up @@ -44,6 +45,18 @@ public function onKernelException(GetResponseForExceptionEvent $event): void
return;
}

// unwrap the exception thrown in handler for Symfony Messenger >= 4.3
$exception = $event->getException();
if ($exception instanceof HandlerFailedException) {
/** @var \Throwable $previousException */
$previousException = $exception->getPrevious();
if (!$previousException instanceof \Exception) {
throw $previousException;
}

$event->setException($previousException);
}

$this->exceptionListener->onKernelException($event);
}
}
4 changes: 3 additions & 1 deletion src/Test/DoctrineMongoDbOdmFilterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

/**
* @internal
*
* @author Alan Poulain <contact@alanpoulain.eu>
*/
abstract class DoctrineMongoDbOdmFilterTestCase extends KernelTestCase
Expand All @@ -45,7 +47,7 @@ abstract class DoctrineMongoDbOdmFilterTestCase extends KernelTestCase
*/
protected $filterClass;

protected function setUp()
protected function setUp(): void
{
self::bootKernel();

Expand Down
2 changes: 2 additions & 0 deletions src/Test/DoctrineMongoDbOdmSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
/**
* Convenience class for setting up Doctrine from different installations and configurations.
*
* @internal
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Alan Poulain <contact@alanpoulain.eu>
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Test/DoctrineOrmFilterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use Symfony\Component\HttpFoundation\RequestStack;

/**
* @internal
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
abstract class DoctrineOrmFilterTestCase extends KernelTestCase
Expand Down Expand Up @@ -53,7 +55,7 @@ abstract class DoctrineOrmFilterTestCase extends KernelTestCase
*/
protected $filterClass;

protected function setUp()
protected function setUp(): void
{
self::bootKernel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PaginationExtensionTest extends TestCase
{
private $managerRegistryProphecy;

protected function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/Bridge/Elasticsearch/DataProvider/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ function (array $document): Foo {
);
}

protected function setUp()
protected function setUp(): void
{
$this->paginator = $this->getPaginator(4, 4);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SwaggerCommandTest extends KernelTestCase
*/
private $tester;

protected function setUp()
protected function setUp(): void
{
self::bootKernel();

Expand Down Expand Up @@ -70,7 +70,7 @@ public function testExecuteWithYamlVersion3()
operationId: getDummyCarCollection
YAML;

$this->assertContains($expected, $result, 'nested object should be present.');
$this->assertStringContainsString($expected, $result, 'nested object should be present.');

$expected = <<<YAML
'/dummy_cars/{id}':
Expand All @@ -79,8 +79,8 @@ public function testExecuteWithYamlVersion3()
operationId: getDummyCarItem
YAML;

$this->assertContains($expected, $result, 'arrays should be correctly formatted.');
$this->assertContains('openapi: 3.0.2', $result);
$this->assertStringContainsString($expected, $result, 'arrays should be correctly formatted.');
$this->assertStringContainsString('openapi: 3.0.2', $result);

$expected = <<<YAML
info:
Expand All @@ -90,7 +90,7 @@ public function testExecuteWithYamlVersion3()
This is a test API.
Made with love
YAML;
$this->assertContains($expected, $result, 'multiline formatting must be preserved (using literal style).');
$this->assertStringContainsString($expected, $result, 'multiline formatting must be preserved (using literal style).');
}

public function testExecuteOpenApiVersion2WithYaml()
Expand All @@ -99,7 +99,7 @@ public function testExecuteOpenApiVersion2WithYaml()

$result = $this->tester->getDisplay();
$this->assertYaml($result);
$this->assertContains("swagger: '2.0'", $result);
$this->assertStringContainsString("swagger: '2.0'", $result);
}

public function testExecuteWithBadArguments()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class RequestDataCollectorTest extends TestCase
private $metadataFactory;
private $filterLocator;

protected function setUp()
protected function setUp(): void
{
$this->response = $this->createMock(Response::class);
$this->attributes = $this->prophesize(ParameterBag::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
use Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\Exception\HandlerFailedException;
use Symfony\Component\Serializer\Exception\ExceptionInterface;

/**
Expand Down Expand Up @@ -138,13 +138,13 @@ class ApiPlatformExtensionTest extends TestCase
private $extension;
private $childDefinitionProphecy;

protected function setUp()
protected function setUp(): void
{
$this->extension = new ApiPlatformExtension();
$this->childDefinitionProphecy = $this->prophesize(ChildDefinition::class);
}

protected function tearDown()
protected function tearDown(): void
{
$this->extension = null;
}
Expand Down Expand Up @@ -494,7 +494,7 @@ public function testDisabledMessenger()
{
$containerBuilderProphecy = $this->getBaseContainerBuilderProphecy();
$containerBuilderProphecy->setAlias('api_platform.message_bus', 'messenger.default_bus')->shouldNotBeCalled();
if (!class_exists(UnrecoverableMessageHandlingException::class)) {
if (!class_exists(HandlerFailedException::class)) {
$containerBuilderProphecy->setAlias('api_platform.message_bus', 'message_bus')->shouldNotBeCalled();
}
$containerBuilderProphecy->setDefinition('api_platform.messenger.data_persister', Argument::type(Definition::class))->shouldNotBeCalled();
Expand Down Expand Up @@ -1175,7 +1175,7 @@ private function getBaseContainerBuilderProphecy(array $doctrineIntegrationsToLo
$containerBuilderProphecy->setAlias($alias, $service)->shouldBeCalled();
}

if (!class_exists(UnrecoverableMessageHandlingException::class)) {
if (!class_exists(HandlerFailedException::class)) {
$containerBuilderProphecy->setAlias('api_platform.message_bus', 'message_bus')->shouldBeCalled();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ConfigurationTest extends TestCase
*/
private $processor;

protected function setUp()
protected function setUp(): void
{
$this->configuration = new Configuration();
$this->processor = new Processor();
Expand Down
Loading