public function testCanIterateOverResultsUsingRespository() { $pdoConfig = BookDao::getConfig('pdosqlite'); $strategyA = new \Octopus\Strategy\PdoSqlite($pdoConfig); $strategyB = new \Octopus\Strategy\PdoSqlite($pdoConfig); $this->createBookTestTableIWithPdoHandle($strategyA->getPdoHandle(), $pdoConfig); $this->createBookTestTableIWithPdoHandle($strategyB->getPdoHandle(), $pdoConfig); $w = array($strategyA, $strategyB); // Note how I'm only reading from strategyB. $r = array($strategyB); $bookDao = new BookDao($w, $r); // Save 7 models. for ($i = 0; $i < 7; $i++) { $bookDao->create(new Book()); } // Load a repository. $bookRepository = new BookRepository($bookDao); // Run a query which returns all of the books. $result = $bookRepository->getAllBooks($strategyA->getPdoHandle()); $this->assertTrue($result instanceof \Traversable); $this->assertTrue($result instanceof \Countable); $this->assertEquals(7, count($result)); foreach ($result as $thisBook) { $this->assertEquals(36, strlen($thisBook->getId())); } }
public function setUp() { $config = BookDao::getConfig('pdosqlite'); $this->_strategy = new PdoSqlite($config); $fieldDefinitions = ''; foreach ($config['columns'] as $field) { $fieldDefinitions .= "{$field} varchar(255), "; } $fieldDefinitions = rtrim($fieldDefinitions); $fieldDefinitions = substr($fieldDefinitions, 0, strlen($fieldDefinitions) - 1); $sql = "CREATE TABLE " . $config['table'] . " ({$fieldDefinitions});"; $handle = $this->_strategy->getPdoHandle()->exec($sql); }
public function testBackupStrategyNotTriggeredUnderNormalCircumstances() { $pdoConfig = BookDao::getConfig('pdosqlite'); // This one triggers an exception. $pdoSqliteStrategyMock = $this->getMock('\\Octopus\\Strategy\\PdoSqlite', array('create'), array($pdoConfig)); $pdoSqliteStrategyMock->expects($this->once())->method('create'); // This one should be used because there was an exception thrown. $pdoSqliteStrategyMockBackup = $this->getMock('\\Octopus\\Strategy\\PdoSqlite', array('create'), array($pdoConfig)); $pdoSqliteStrategyMockBackup->expects($this->never())->method('create'); $this->createBookTestTableIWithPdoHandle($pdoSqliteStrategyMock->getPdoHandle(), $pdoConfig); $w = array($pdoSqliteStrategyMock); $r = array($pdoSqliteStrategyMock); $bookDao = new BookDao($w, $r); $bookDao->setPrimaryWriteBackupStrategy($pdoSqliteStrategyMockBackup); $bookDao->create(new Book()); }
public function setUp() { $config = BookDao::getConfig('memcache'); $this->_strategy = new Memcache($config); }