Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Sharding / SQLAzure / AbstractTestCase.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Sharding\SQLAzure;
4
5 use Doctrine\DBAL\DriverManager;
6 use Doctrine\DBAL\Schema\Schema;
7 use Doctrine\DBAL\Sharding\SQLAzure\SQLAzureShardManager;
8
9 abstract class AbstractTestCase extends \PHPUnit_Framework_TestCase
10 {
11     protected $conn;
12     protected $sm;
13
14     public function setUp()
15     {
16         if (!isset($GLOBALS['db_type']) || strpos($GLOBALS['db_type'], "sqlsrv") === false) {
17             $this->markTestSkipped('No driver or sqlserver driver specified.');
18         }
19
20         $params = array(
21             'driver' => $GLOBALS['db_type'],
22             'dbname' => $GLOBALS['db_name'],
23             'user' => $GLOBALS['db_username'],
24             'password' => $GLOBALS['db_password'],
25             'host' => $GLOBALS['db_host'],
26             'sharding' => array(
27                 'federationName' => 'Orders_Federation',
28                 'distributionKey' => 'CustID',
29                 'distributionType' => 'integer',
30                 'filteringEnabled' => false,
31             ),
32             'driverOptions' => array('MultipleActiveResultSets' => false)
33         );
34         $this->conn = DriverManager::getConnection($params);
35         // assume database is created and schema is:
36         // Global products table
37         // Customers, Orders, OrderItems federation tables.
38         // See http://cloud.dzone.com/articles/using-sql-azure-federations
39         $this->sm = new SQLAzureShardManager($this->conn);
40     }
41
42     public function createShopSchema()
43     {
44         $schema = new Schema();
45
46         $products = $schema->createTable('Products');
47         $products->addColumn('ProductID', 'integer');
48         $products->addColumn('SupplierID', 'integer');
49         $products->addColumn('ProductName', 'string');
50         $products->addColumn('Price', 'decimal', array('scale' => 2, 'precision' => 12));
51         $products->setPrimaryKey(array('ProductID'));
52         $products->addOption('azure.federated', true);
53
54         $customers = $schema->createTable('Customers');
55         $customers->addColumn('CustomerID', 'integer');
56         $customers->addColumn('CompanyName', 'string');
57         $customers->addColumn('FirstName', 'string');
58         $customers->addColumn('LastName', 'string');
59         $customers->setPrimaryKey(array('CustomerID'));
60         $customers->addOption('azure.federated', true);
61         $customers->addOption('azure.federatedOnColumnName', 'CustomerID');
62
63         $orders = $schema->createTable('Orders');
64         $orders->addColumn('CustomerID', 'integer');
65         $orders->addColumn('OrderID', 'integer');
66         $orders->addColumn('OrderDate', 'datetime');
67         $orders->setPrimaryKey(array('CustomerID', 'OrderID'));
68         $orders->addOption('azure.federated', true);
69         $orders->addOption('azure.federatedOnColumnName', 'CustomerID');
70
71         $orderItems = $schema->createTable('OrderItems');
72         $orderItems->addColumn('CustomerID', 'integer');
73         $orderItems->addColumn('OrderID', 'integer');
74         $orderItems->addColumn('ProductID', 'integer');
75         $orderItems->addColumn('Quantity', 'integer');
76         $orderItems->setPrimaryKey(array('CustomerID', 'OrderID', 'ProductID'));
77         $orderItems->addOption('azure.federated', true);
78         $orderItems->addOption('azure.federatedOnColumnName', 'CustomerID');
79
80         return $schema;
81     }
82 }