Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: php-enqueue/mongodb
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.8.0
Choose a base ref
...
head repository: php-enqueue/mongodb
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Loading
Showing with 847 additions and 1,316 deletions.
  1. +5 −0 .gitattributes
  2. +30 −0 .github/workflows/ci.yml
  3. +0 −186 Client/MongodbDriver.php
  4. +7 −20 JSON.php
  5. +24 −13 MongodbConnectionFactory.php
  6. +29 −60 MongodbConsumer.php
  7. +79 −23 MongodbContext.php
  8. +10 −21 MongodbDestination.php
  9. +38 −126 MongodbMessage.php
  10. +26 −52 MongodbProducer.php
  11. +133 −0 MongodbSubscriptionConsumer.php
  12. +16 −7 README.md
  13. +0 −119 Symfony/MongodbTransportFactory.php
  14. +0 −351 Tests/Client/MongodbDriverTest.php
  15. +2 −2 Tests/Functional/MongodbConsumerTest.php
  16. +20 −5 Tests/MongodbConnectionFactoryTest.php
  17. +41 −34 Tests/MongodbConsumerTest.php
  18. +39 −15 Tests/MongodbContextTest.php
  19. +9 −8 Tests/MongodbDestinationTest.php
  20. +2 −1 Tests/MongodbMessageTest.php
  21. +8 −26 Tests/MongodbProducerTest.php
  22. +178 −0 Tests/MongodbSubscriptionConsumerTest.php
  23. +2 −5 Tests/Spec/MongodbConnectionFactoryTest.php
  24. +2 −5 Tests/Spec/MongodbContextTest.php
  25. +2 −5 Tests/Spec/MongodbMessageTest.php
  26. +2 −5 Tests/Spec/MongodbProducerTest.php
  27. +2 −5 Tests/Spec/MongodbQueueTest.php
  28. +0 −3 Tests/Spec/MongodbRequeueMessageTest.php
  29. +0 −3 Tests/Spec/MongodbSendAndReceiveDelayedMessageFromQueueTest.php
  30. +4 −6 Tests/Spec/MongodbSendAndReceivePriorityMessagesFromQueueTest.php
  31. +0 −3 Tests/Spec/MongodbSendAndReceiveTimeToLiveMessagesFromQueueTest.php
  32. +0 −3 Tests/Spec/MongodbSendToAndReceiveFromQueueTest.php
  33. +0 −3 Tests/Spec/MongodbSendToAndReceiveFromTopicTest.php
  34. +0 −3 Tests/Spec/MongodbSendToAndReceiveNoWaitFromQueueTest.php
  35. +0 −3 Tests/Spec/MongodbSendToAndReceiveNoWaitFromTopicTest.php
  36. +40 −0 Tests/Spec/MongodbSubscriptionConsumerConsumeFromAllSubscribedQueuesTest.php
  37. +40 −0 Tests/Spec/MongodbSubscriptionConsumerConsumeUntilUnsubscribedTest.php
  38. +40 −0 Tests/Spec/MongodbSubscriptionConsumerStopOnFalseTest.php
  39. +2 −5 Tests/Spec/MongodbTopicTest.php
  40. +0 −164 Tests/Symfony/MongodbTransportFactoryTest.php
  41. +9 −15 composer.json
  42. +6 −11 phpunit.xml.dist
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/Tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
phpunit.xml.dist export-ignore
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI
on:
pull_request:
push:
branches:
- master
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['7.4', '8.0', '8.1', '8.2']

name: PHP ${{ matrix.php }} tests

steps:
- uses: actions/checkout@v2

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
extensions: mongodb

- uses: "ramsey/composer-install@v1"
with:
composer-options: "--prefer-source"

- run: vendor/bin/phpunit --exclude-group=functional
186 changes: 0 additions & 186 deletions Client/MongodbDriver.php

This file was deleted.

27 changes: 7 additions & 20 deletions JSON.php
Original file line number Diff line number Diff line change
@@ -14,10 +14,7 @@ class JSON
public static function decode($string)
{
if (!is_string($string)) {
throw new \InvalidArgumentException(sprintf(
'Accept only string argument but got: "%s"',
is_object($string) ? get_class($string) : gettype($string)
));
throw new \InvalidArgumentException(sprintf('Accept only string argument but got: "%s"', is_object($string) ? $string::class : gettype($string)));
}

// PHP7 fix - empty string and null cause syntax error
@@ -26,32 +23,22 @@ public static function decode($string)
}

$decoded = json_decode($string, true);
if (JSON_ERROR_NONE !== json_last_error()) {
throw new \InvalidArgumentException(sprintf(
'The malformed json given. Error %s and message %s',
json_last_error(),
json_last_error_msg()
));
if (\JSON_ERROR_NONE !== json_last_error()) {
throw new \InvalidArgumentException(sprintf('The malformed json given. Error %s and message %s', json_last_error(), json_last_error_msg()));
}

return $decoded;
}

/**
* @param mixed $value
*
* @return string
*/
public static function encode($value)
{
$encoded = json_encode($value, JSON_UNESCAPED_UNICODE);

if (JSON_ERROR_NONE !== json_last_error()) {
throw new \InvalidArgumentException(sprintf(
'Could not encode value into json. Error %s and message %s',
json_last_error(),
json_last_error_msg()
));
$encoded = json_encode($value, \JSON_UNESCAPED_UNICODE);

if (\JSON_ERROR_NONE !== json_last_error()) {
throw new \InvalidArgumentException(sprintf('Could not encode value into json. Error %s and message %s', json_last_error(), json_last_error_msg()));
}

return $encoded;
37 changes: 24 additions & 13 deletions MongodbConnectionFactory.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

declare(strict_types=1);

namespace Enqueue\Mongodb;

use Interop\Queue\PsrConnectionFactory;
use Interop\Queue\ConnectionFactory;
use Interop\Queue\Context;
use MongoDB\Client;

class MongodbConnectionFactory implements PsrConnectionFactory
class MongodbConnectionFactory implements ConnectionFactory
{
/**
* @var array
@@ -24,7 +27,7 @@ class MongodbConnectionFactory implements PsrConnectionFactory
*
* or
*
* mongodb://127.0.0.1:27017/dbname?polling_interval=1000&enqueue_collection=enqueue
* mongodb://127.0.0.1:27017/defaultauthdb?polling_interval=1000&enqueue_database=enqueue&enqueue_collection=enqueue
*
* @param array|string|null $config
*/
@@ -35,6 +38,10 @@ public function __construct($config = 'mongodb:')
} elseif (is_string($config)) {
$config = $this->parseDsn($config);
} elseif (is_array($config)) {
$config = array_replace(
$config,
$this->parseDsn(empty($config['dsn']) ? 'mongodb:' : $config['dsn'])
);
} else {
throw new \LogicException('The config must be either an array of options, a DSN string or null');
}
@@ -47,14 +54,17 @@ public function __construct($config = 'mongodb:')
$this->config = $config;
}

public function createContext()
/**
* @return MongodbContext
*/
public function createContext(): Context
{
$client = new Client($this->config['dsn']);

return new MongodbContext($client, $this->config);
}

public static function parseDsn($dsn)
public static function parseDsn(string $dsn): array
{
$parsedUrl = parse_url($dsn);
if (false === $parsedUrl) {
@@ -67,35 +77,36 @@ public static function parseDsn($dsn)
'mongodb' => true,
];
if (false == isset($parsedUrl['scheme'])) {
throw new \LogicException(sprintf(
'The given DSN schema "%s" is not supported. There are supported schemes: "%s".',
$parsedUrl['scheme'],
implode('", "', array_keys($supported))
));
throw new \LogicException(sprintf('The given DSN schema "%s" is not supported. There are supported schemes: "%s".', $parsedUrl['scheme'], implode('", "', array_keys($supported))));
}
if ('mongodb:' === $dsn) {
return [
'dsn' => 'mongodb://127.0.0.1/',
];
}
$config['dsn'] = $dsn;
// FIXME this is NOT a dbname but rather authdb. But removing this would be a BC break.
// see: https://github.com/php-enqueue/enqueue-dev/issues/1027
if (isset($parsedUrl['path']) && '/' !== $parsedUrl['path']) {
$pathParts = explode('/', $parsedUrl['path']);
//DB name
// DB name
if ($pathParts[1]) {
$config['dbname'] = $pathParts[1];
}
}
if (isset($parsedUrl['query'])) {
$queryParts = null;
parse_str($parsedUrl['query'], $queryParts);
//get enqueue attributes values
// get enqueue attributes values
if (!empty($queryParts['polling_interval'])) {
$config['polling_interval'] = $queryParts['polling_interval'];
$config['polling_interval'] = (int) $queryParts['polling_interval'];
}
if (!empty($queryParts['enqueue_collection'])) {
$config['collection_name'] = $queryParts['enqueue_collection'];
}
if (!empty($queryParts['enqueue_database'])) {
$config['dbname'] = $queryParts['enqueue_database'];
}
}

return $config;
Loading