-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSchemaConnectionTest.php
More file actions
94 lines (65 loc) · 2.99 KB
/
SchemaConnectionTest.php
File metadata and controls
94 lines (65 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
declare(strict_types=1);
namespace Macpaw\PostgresSchemaBundle\Tests\Doctrine;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection as DriverConnection;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Macpaw\PostgresSchemaBundle\Doctrine\SchemaConnection;
use Macpaw\PostgresSchemaBundle\Exception\UnsupportedPlatformException;
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
use PHPUnit\Framework\TestCase;
class SchemaConnectionTest extends TestCase
{
public function testConnectSetsSearchPath(): void
{
$driverConnection = $this->createMock(DriverConnection::class);
$driverConnection->expects($this->once())
->method('exec')
->with('SET search_path TO test_schema');
$driver = $this->createMock(Driver::class);
$driver->method('connect')->willReturn($driverConnection);
$platform = new PostgreSQLPlatform();
$connection = $this->getMockBuilder(SchemaConnection::class)
->setConstructorArgs([[], $driver, new Configuration(), new EventManager()])
->onlyMethods(['getDatabasePlatform', 'fetchOne'])
->getMock();
$connection->method('getDatabasePlatform')->willReturn($platform);
$connection->method('fetchOne')->willReturn(true);
$resolver = new BaggageSchemaResolver();
$resolver->setSchema('test_schema');
SchemaConnection::setSchemaResolver($resolver);
$result = $connection->connect();
self::assertTrue($result);
}
public function testConnectSkipsWhenNoSchema(): void
{
$driverConnection = $this->createMock(DriverConnection::class);
$driver = $this->createMock(Driver::class);
$driver->method('connect')->willReturn($driverConnection);
$connection = new SchemaConnection([], $driver, new Configuration());
$resolver = new BaggageSchemaResolver();
SchemaConnection::setSchemaResolver($resolver);
self::assertTrue($connection->connect());
}
public function testThrowsForUnsupportedPlatform(): void
{
$this->expectException(UnsupportedPlatformException::class);
$driverConnection = $this->createMock(DriverConnection::class);
$driver = $this->createMock(Driver::class);
$driver->method('connect')->willReturn($driverConnection);
$platform = new MySQLPlatform();
$connection = $this->getMockBuilder(SchemaConnection::class)
->setConstructorArgs([[], $driver, new Configuration(), new EventManager()])
->onlyMethods(['getDatabasePlatform'])
->getMock();
$connection->method('getDatabasePlatform')->willReturn($platform);
$resolver = new BaggageSchemaResolver();
$resolver->setSchema('test_schema');
SchemaConnection::setSchemaResolver($resolver);
$connection->connect();
}
}