|
5 | 5 | use Bernard\Doctrine\MessagesSchema;
|
6 | 6 | use Bernard\Driver\DoctrineDriver;
|
7 | 7 | use Doctrine\DBAL\Platforms\MySqlPlatform;
|
| 8 | + |
| 9 | +use Doctrine\DBAL\Connection; |
| 10 | +use Doctrine\DBAL\DriverManager; |
| 11 | +use Doctrine\DBAL\Logging\DebugStack; |
8 | 12 | use Doctrine\DBAL\Schema\Schema;
|
9 | 13 |
|
10 | 14 | abstract class AbstractDoctrineDriverTest extends \PHPUnit_Framework_TestCase
|
11 | 15 | {
|
12 | 16 | /**
|
13 |
| - * @var \Doctrine\DBAL\Connection |
| 17 | + * @var Connection |
14 | 18 | */
|
15 | 19 | private $connection;
|
16 | 20 |
|
@@ -72,6 +76,64 @@ public function testCreateAndRemoveQueue()
|
72 | 76 | $this->assertEquals(array('send-newsletter'), $this->driver->listQueues());
|
73 | 77 | }
|
74 | 78 |
|
| 79 | + public function testCreateQueueWillNotAttemptDuplicateQueueCreation() |
| 80 | + { |
| 81 | + $logger = new DebugStack(); |
| 82 | + |
| 83 | + $this->connection->getConfiguration()->setSQLLogger($logger); |
| 84 | + |
| 85 | + $this->driver->createQueue('import-users'); |
| 86 | + $this->driver->createQueue('import-users'); |
| 87 | + |
| 88 | + self::assertCount(7, $logger->queries); |
| 89 | + self::assertStringMatchesFormat('%aSTART TRANSACTION%a', $logger->queries[1]['sql']); |
| 90 | + self::assertStringStartsWith('SELECT ', $logger->queries[2]['sql']); |
| 91 | + self::assertStringStartsWith('INSERT ', $logger->queries[3]['sql']); |
| 92 | + self::assertStringMatchesFormat('%aCOMMIT%a', $logger->queries[4]['sql']); |
| 93 | + self::assertStringMatchesFormat('%aSTART TRANSACTION%a', $logger->queries[5]['sql']); |
| 94 | + self::assertStringStartsWith('SELECT ', $logger->queries[6]['sql']); |
| 95 | + self::assertStringMatchesFormat('%aCOMMIT%a', $logger->queries[7]['sql']); |
| 96 | + } |
| 97 | + |
| 98 | + public function testGenericExceptionsBubbleUpWhenThrownOnQueueCreation() |
| 99 | + { |
| 100 | + $connection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); |
| 101 | + $exception = new \Exception(); |
| 102 | + $queryBuilder = $this->connection->createQueryBuilder(); |
| 103 | + |
| 104 | + $connection->expects(self::once())->method('transactional')->willReturnCallback('call_user_func'); |
| 105 | + $connection->expects(self::once())->method('insert')->willThrowException($exception); |
| 106 | + $connection->expects(self::any())->method('createQueryBuilder')->willReturn($queryBuilder); |
| 107 | + |
| 108 | + $driver = new DoctrineDriver($connection); |
| 109 | + |
| 110 | + try { |
| 111 | + $driver->createQueue('foo'); |
| 112 | + |
| 113 | + self::fail('An exception was supposed to be thrown'); |
| 114 | + } catch (\Exception $thrown) { |
| 115 | + self::assertSame($exception, $thrown); |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + public function testConstraintViolationExceptionsAreIgnored() |
| 120 | + { |
| 121 | + $connection = $this->getMockBuilder('Doctrine\DBAL\Connection')->disableOriginalConstructor()->getMock(); |
| 122 | + $queryBuilder = $this->connection->createQueryBuilder(); |
| 123 | + $exception = $this |
| 124 | + ->getMockBuilder('Doctrine\DBAL\Exception\ConstraintViolationException') |
| 125 | + ->disableOriginalConstructor() |
| 126 | + ->getMock(); |
| 127 | + |
| 128 | + $connection->expects(self::once())->method('transactional')->willReturnCallback('call_user_func'); |
| 129 | + $connection->expects(self::once())->method('insert')->willThrowException($exception); |
| 130 | + $connection->expects(self::any())->method('createQueryBuilder')->willReturn($queryBuilder); |
| 131 | + |
| 132 | + $driver = new DoctrineDriver($connection); |
| 133 | + |
| 134 | + $driver->createQueue('foo'); |
| 135 | + } |
| 136 | + |
75 | 137 | public function testPushMessageLazilyCreatesQueue()
|
76 | 138 | {
|
77 | 139 | $this->driver->pushMessage('send-newsletter', 'something');
|
|
0 commit comments