示例#1
0
    public function setUp()
    {
        $this->db = Database::connect("sqlite::memory:");
        $this->db->getAdapter()->connect();
        /** @var \PDO $pdo */
        $pdo = $this->db->getAdapter()->getConnection();
        $sql = <<<SQL
CREATE TABLE [Album]
(
    [AlbumId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    [Title] NVARCHAR(160)  NOT NULL,
    [ArtistId] INTEGER  NOT NULL,
    FOREIGN KEY ([ArtistId]) REFERENCES [Artist] ([ArtistId])
\t\tON DELETE NO ACTION ON UPDATE NO ACTION
);

CREATE TABLE [Artist]
(
    [ArtistId] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    [Name] NVARCHAR(120)
);

INSERT INTO [Artist] ([Name]) VALUES ('AC/DC');
INSERT INTO [Artist] ([Name]) VALUES ('Accept');
INSERT INTO [Artist] ([Name]) VALUES ('Aerosmith');
INSERT INTO [Artist] ([Name]) VALUES ('Alanis Morissette');

INSERT INTO [Album] ([Title], [ArtistId]) VALUES ('For Those About To Rock We Salute You', 1);
INSERT INTO [Album] ([Title], [ArtistId]) VALUES ('Balls to the Wall', 2);
INSERT INTO [Album] ([Title], [ArtistId]) VALUES ('Restless and Wild', 2);
INSERT INTO [Album] ([Title], [ArtistId]) VALUES ('Let There Be Rock', 1);
INSERT INTO [Album] ([Title], [ArtistId]) VALUES ('Big Ones', 3);

CREATE TABLE [x?[x]
(
    [id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
    [value] NVARCHAR(120)
);

INSERT INTO [x?[x] ([value], [id]) VALUES ('SomeValue', 3);
SQL;
        if ($pdo->exec($sql) === false) {
            $this->fail(var_export($pdo->errorInfo()));
        }
    }
示例#2
0
 public function testAddCustomPlaceholder_setCustomsPlaceholdersSetCustomAdapter()
 {
     $db = new Database(new DSN('mysql:'));
     $myPlaceholderOne = Helper::getMockCustomPlaceholder('?x');
     $db->addCustomPlaceholder($myPlaceholderOne);
     $myAdapter = Helper::getMockCustomAdapter();
     $db->setAdapter($myAdapter);
     $myPlaceholderTwo = Helper::getMockCustomPlaceholder('?y');
     $db->addCustomPlaceholder($myPlaceholderTwo);
     $this->assertEquals($myAdapter, $db->getAdapter());
     $placeholders = $db->getPlaceholders();
     foreach ($db->getPlaceholders()->getAllPlaceholdersAsArray() as $placeholder) {
         $this->assertEquals($myAdapter, $placeholder->getQuotePerformer());
     }
     $this->assertEquals('f#_nadxy', $placeholders->getAllPlaceholdersAsString());
 }