Skip to content

Commit 7d2ba0d

Browse files
committed
[dbal] Run functional tests with PostgresSQL
1 parent 6f891e2 commit 7d2ba0d

33 files changed

+435
-19
lines changed

docker-compose.yml

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ services:
66
depends_on:
77
- rabbitmq
88
- mysql
9+
- postgres
910
- redis
1011
- beanstalkd
1112
- gearmand
@@ -26,7 +27,9 @@ services:
2627
- RABITMQ_STOMP_DSN=stomp+rabbitmq://guest:guest@rabbitmq:61613/mqdev
2728
- RABBITMQ_MANAGMENT_DSN=http://guest:guest@rabbitmq:15672/mqdev
2829
- DOCTRINE_DSN=mysql://root:rootpass@mysql/mqdev
30+
- DOCTRINE_POSTGRES_DSN=postgres://postgres:pass@postgres/template1
2931
- MYSQL_DSN=mysql://root:rootpass@mysql/mqdev
32+
- POSTGRES_DSN=postgres://postgres:pass@postgres/postgres
3033
- PREDIS_DSN=redis+predis://redis
3134
- PHPREDIS_DSN=redis+phpredis://redis
3235
- GPS_DSN=gps:?projectId=mqdev&emulatorHost=http://google-pubsub:8085
@@ -77,6 +80,13 @@ services:
7780
MYSQL_ROOT_PASSWORD: rootpass
7881
MYSQL_DATABASE: mqdev
7982

83+
postgres:
84+
image: postgres
85+
environment:
86+
POSTGRES_PASSWORD: pass
87+
ports:
88+
- "5432:5432"
89+
8090
generate-changelog:
8191
image: enqueue/generate-changelog:latest
8292
# build: { context: docker, dockerfile: Dockerfile.generate-changelog }

docker/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM formapro/nginx-php-fpm:latest-all-exts
33
## libs
44
RUN set -x && \
55
apt-get update && \
6-
apt-get install -y --no-install-recommends --no-install-suggests wget curl openssl ca-certificates nano netcat php-dev php-redis git python
6+
apt-get install -y --no-install-recommends --no-install-suggests wget curl openssl ca-certificates nano netcat php-dev php-redis php-pgsql git python
77

88
RUN set -x && \
99
apt-get update && \
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use Enqueue\Dbal\DbalConnectionFactory;
4+
5+
require_once getcwd().'/vendor/autoload.php';
6+
7+
$dsn = getenv('DOCTRINE_POSTGRES_DSN');
8+
9+
$dbalContext = (new DbalConnectionFactory($dsn))->createContext();
10+
11+
$dbalContext->getDbalConnection()->getSchemaManager()->dropAndCreateDatabase('postgres');
12+
$dbalContext->createDataBaseTable();
13+
14+
echo 'Postgresql Database is updated'.PHP_EOL;

docker/bin/test.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ trap "FORCE_EXIT=true" SIGTERM SIGINT
3232
waitForService rabbitmq 5672 50
3333
waitForService rabbitmqssl 5671 50
3434
waitForService mysql 3306 50
35+
waitForService postgres 5432 50
3536
waitForService redis 6379 50
3637
waitForService beanstalkd 11300 50
3738
waitForService gearmand 4730 50
@@ -40,9 +41,10 @@ waitForService mongo 27017 50
4041
waitForService thruway 9090 50
4142
waitForService localstack 4576 50
4243

43-
php docker/bin/refresh-mysql-database.php
44-
php pkg/job-queue/Tests/Functional/app/console doctrine:database:create --if-not-exists
45-
php pkg/job-queue/Tests/Functional/app/console doctrine:schema:update --force
44+
php docker/bin/refresh-mysql-database.php || exit 1
45+
php docker/bin/refresh-postgres-database.php || exit 1
46+
php pkg/job-queue/Tests/Functional/app/console doctrine:database:create --if-not-exists || exit 1
47+
php pkg/job-queue/Tests/Functional/app/console doctrine:schema:update --force || exit 1
4648

4749
#php pkg/enqueue-bundle/Tests/Functional/app/console.php config:dump-reference enqueue
4850
bin/phpunit "$@"

pkg/dbal/Tests/Functional/DbalConsumerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Enqueue\Dbal\DbalContext;
88
use Enqueue\Dbal\DbalMessage;
9-
use Enqueue\Dbal\Tests\Spec\CreateDbalContextTrait;
9+
use Enqueue\Dbal\Tests\Spec\Mysql\CreateDbalContextTrait;
1010
use PHPUnit\Framework\TestCase;
1111

1212
/**

pkg/dbal/Tests/Spec/CreateDbalContextTrait.php renamed to pkg/dbal/Tests/Spec/Mysql/CreateDbalContextTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Dbal\Tests\Spec;
3+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
44

55
use Enqueue\Dbal\DbalConnectionFactory;
66

pkg/dbal/Tests/Spec/DbalContextTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalContextTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Dbal\Tests\Spec;
3+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
44

55
use Interop\Queue\Spec\ContextSpec;
66

pkg/dbal/Tests/Spec/DbalProducerTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalProducerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Dbal\Tests\Spec;
3+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
44

55
use Interop\Queue\Spec\ProducerSpec;
66

pkg/dbal/Tests/Spec/DbalRequeueMessageTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalRequeueMessageTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Dbal\Tests\Spec;
3+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
44

55
use Interop\Queue\Spec\RequeueMessageSpec;
66

pkg/dbal/Tests/Spec/DbalSendAndReceiveDelayedMessageFromQueueTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalSendAndReceiveDelayedMessageFromQueueTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Dbal\Tests\Spec;
3+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
44

55
use Interop\Queue\Spec\SendAndReceiveDelayedMessageFromQueueSpec;
66

pkg/dbal/Tests/Spec/DbalSendAndReceivePriorityMessagesFromQueueTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalSendAndReceivePriorityMessagesFromQueueTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Dbal\Tests\Spec;
3+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
44

55
use Enqueue\Dbal\DbalContext;
66
use Enqueue\Dbal\DbalMessage;

pkg/dbal/Tests/Spec/DbalSendAndReceiveTimeToLiveMessagesFromQueueTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalSendAndReceiveTimeToLiveMessagesFromQueueTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Dbal\Tests\Spec;
3+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
44

55
use Interop\Queue\Spec\SendAndReceiveTimeToLiveMessagesFromQueueSpec;
66

pkg/dbal/Tests/Spec/DbalSendToAndReceiveFromQueueTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalSendToAndReceiveFromQueueTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Dbal\Tests\Spec;
3+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
44

55
use Interop\Queue\Spec\SendToAndReceiveFromQueueSpec;
66

pkg/dbal/Tests/Spec/DbalSendToAndReceiveFromTopicTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalSendToAndReceiveFromTopicTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Dbal\Tests\Spec;
3+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
44

55
use Interop\Queue\Spec\SendToAndReceiveFromTopicSpec;
66

pkg/dbal/Tests/Spec/DbalSendToAndReceiveNoWaitFromQueueTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalSendToAndReceiveNoWaitFromQueueTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Dbal\Tests\Spec;
3+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
44

55
use Interop\Queue\Spec\SendToAndReceiveNoWaitFromQueueSpec;
66

pkg/dbal/Tests/Spec/DbalSendToAndReceiveNoWaitFromTopicTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalSendToAndReceiveNoWaitFromTopicTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Enqueue\Dbal\Tests\Spec;
3+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
44

55
use Interop\Queue\Spec\SendToAndReceiveNoWaitFromTopicSpec;
66

pkg/dbal/Tests/Spec/DbalSubscriptionConsumerConsumeFromAllSubscribedQueuesTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalSubscriptionConsumerConsumeFromAllSubscribedQueuesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Enqueue\Dbal\Tests\Spec;
5+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
66

77
use Enqueue\Dbal\DbalContext;
88
use Interop\Queue\Context;

pkg/dbal/Tests/Spec/DbalSubscriptionConsumerConsumeUntilUnsubscribedTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalSubscriptionConsumerConsumeUntilUnsubscribedTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Enqueue\Dbal\Tests\Spec;
5+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
66

77
use Enqueue\Dbal\DbalContext;
88
use Interop\Queue\Context;

pkg/dbal/Tests/Spec/DbalSubscriptionConsumerStopOnFalseTest.php renamed to pkg/dbal/Tests/Spec/Mysql/DbalSubscriptionConsumerStopOnFalseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Enqueue\Dbal\Tests\Spec;
5+
namespace Enqueue\Dbal\Tests\Spec\Mysql;
66

77
use Enqueue\Dbal\DbalContext;
88
use Interop\Queue\Context;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Enqueue\Dbal\Tests\Spec\Postgresql;
4+
5+
use Enqueue\Dbal\DbalConnectionFactory;
6+
7+
trait CreateDbalContextTrait
8+
{
9+
protected function createDbalContext()
10+
{
11+
if (false == $env = getenv('POSTGRES_DSN')) {
12+
$this->markTestSkipped('The POSTGRES_DSN env is not available. Skip tests');
13+
}
14+
15+
$factory = new DbalConnectionFactory($env);
16+
17+
$context = $factory->createContext();
18+
19+
if ($context->getDbalConnection()->getSchemaManager()->tablesExist([$context->getTableName()])) {
20+
$context->getDbalConnection()->getSchemaManager()->dropTable($context->getTableName());
21+
}
22+
23+
$context->createDataBaseTable();
24+
25+
return $context;
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Enqueue\Dbal\Tests\Spec\Postgresql;
4+
5+
use Interop\Queue\Spec\ContextSpec;
6+
7+
/**
8+
* @group functional
9+
*/
10+
class DbalContextTest extends ContextSpec
11+
{
12+
use CreateDbalContextTrait;
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected function createContext()
18+
{
19+
return $this->createDbalContext();
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Enqueue\Dbal\Tests\Spec\Postgresql;
4+
5+
use Interop\Queue\Spec\ProducerSpec;
6+
7+
/**
8+
* @group functional
9+
*/
10+
class DbalProducerTest extends ProducerSpec
11+
{
12+
use CreateDbalContextTrait;
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected function createProducer()
18+
{
19+
return $this->createDbalContext()->createProducer();
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Enqueue\Dbal\Tests\Spec\Postgresql;
4+
5+
use Interop\Queue\Spec\RequeueMessageSpec;
6+
7+
/**
8+
* @group functional
9+
*/
10+
class DbalRequeueMessageTest extends RequeueMessageSpec
11+
{
12+
use CreateDbalContextTrait;
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected function createContext()
18+
{
19+
return $this->createDbalContext();
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Enqueue\Dbal\Tests\Spec\Postgresql;
4+
5+
use Interop\Queue\Spec\SendAndReceiveDelayedMessageFromQueueSpec;
6+
7+
/**
8+
* @group functional
9+
*/
10+
class DbalSendAndReceiveDelayedMessageFromQueueTest extends SendAndReceiveDelayedMessageFromQueueSpec
11+
{
12+
use CreateDbalContextTrait;
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected function createContext()
18+
{
19+
return $this->createDbalContext();
20+
}
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Enqueue\Dbal\Tests\Spec\Postgresql;
4+
5+
use Enqueue\Dbal\DbalContext;
6+
use Enqueue\Dbal\DbalMessage;
7+
use Interop\Queue\Context;
8+
use Interop\Queue\Spec\SendAndReceivePriorityMessagesFromQueueSpec;
9+
10+
/**
11+
* @group functional
12+
*/
13+
class DbalSendAndReceivePriorityMessagesFromQueueTest extends SendAndReceivePriorityMessagesFromQueueSpec
14+
{
15+
use CreateDbalContextTrait;
16+
17+
private $publishedAt;
18+
19+
public function setUp()
20+
{
21+
parent::setUp();
22+
23+
$this->publishedAt = (int) (microtime(true) * 10000);
24+
}
25+
26+
/**
27+
* @return Context
28+
*/
29+
protected function createContext()
30+
{
31+
return $this->createDbalContext();
32+
}
33+
34+
/**
35+
* {@inheritdoc}
36+
*
37+
* @param DbalContext $context
38+
*
39+
* @return DbalMessage
40+
*/
41+
protected function createMessage(Context $context, $body)
42+
{
43+
/** @var DbalMessage $message */
44+
$message = parent::createMessage($context, $body);
45+
46+
// in order to test priorities correctly we have to make sure the messages were sent in the same time.
47+
$message->setPublishedAt($this->publishedAt);
48+
49+
return $message;
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Enqueue\Dbal\Tests\Spec\Postgresql;
4+
5+
use Interop\Queue\Spec\SendAndReceiveTimeToLiveMessagesFromQueueSpec;
6+
7+
/**
8+
* @group functional
9+
*/
10+
class DbalSendAndReceiveTimeToLiveMessagesFromQueueTest extends SendAndReceiveTimeToLiveMessagesFromQueueSpec
11+
{
12+
use CreateDbalContextTrait;
13+
14+
/**
15+
* {@inheritdoc}
16+
*/
17+
protected function createContext()
18+
{
19+
return $this->createDbalContext();
20+
}
21+
}

0 commit comments

Comments
 (0)