/** * @param Statement $statement */ public function __construct(Statement $statement) { $this->statement = $statement; if (Config::get('logging') === true) { $this->setLogger(Config::get('logger')); } }
/** * @param string $sql * @param string $schema * @param string $database */ public function __construct($sql, $schema = null, $database = null) { $schema = $schema ?: Config::get('default_schema'); $database = $database ?: Config::get('default_database'); $this->connection = new Connection($schema, $database); $this->statement = new Statement($sql, $this->connection); $this->loader = new LazyLoader($this->statement); }
public function testDefaultConnection() { $conn = new Connection(); $defaultSchema = Config::get('default_schema'); $defaultDatabase = Config::get('default_database'); $this->assertEquals($defaultSchema, $conn->getSchema()); $this->assertEquals($defaultDatabase, $conn->getDatabase()); }
public function testPut() { $config = Config::all(); $this->assertArrayNotHasKey('foo', $config); Config::put('foo', 'bar'); $config = Config::all(); $this->assertArrayHasKey('foo', $config); $this->assertEquals('bar', Config::get('foo')); }
/** * test that the query will still execute when logging is enabled * Testing of the Logger is done elsewhere */ public function testLogging() { \Oracle\Support\Config::put('logging', true); require_once realpath(__DIR__ . '/../../bootstrap.php'); // creates Logger and puts it in Config $executor = new Executor($this->statement); // logger gets attached on construction $executor->execute(); $this->assertTrue($executor->isExecuted()); \Oracle\Support\Config::put('logging', false); }
/** * open connection */ protected function connect() { $schema = strtoupper($this->schema); $database = strtoupper($this->database); $credentials = new Collection(Config::get('credentials')); $users = new Collection($credentials->get($database)); $connections = new Collection(Config::get('connections')); $password = $users->get($schema); $connection = $connections->get($database); $this->resource = oci_connect($schema, $password, $connection, 'UTF8'); $this->setDefaultDateFormat(); }
/** * parse the sql statement into an oci8 statement resource */ protected function parse() { if ($this->hasStatementResource()) { oci_free_statement($this->resource); } $this->resource = oci_parse($this->connection->getResource(), $this->sql); // unfortunately oci_parse cannot check the sql statement, so I am unsure when the resource would be false. if (!$this->resource) { throw new OracleException('Unable to parse sql statement.'); } // check sql syntax if this configuration is enabled if (Config::get('validate_sql_syntax') === true) { if (!$this->validateSqlSyntax()) { throw new OracleException('Invalid sql statement.'); } } }
<?php // Here you can initialize variables that will for your tests // force logging off \Oracle\Support\Config::put('logging', false);
<?php use Oracle\Connection; use Oracle\Support\Config; // setup QueryLogger implementation Config::put('logger', new \Oracle\Log\WebQueryLog(new Connection()));
public function tearDown() { Config::put('logging', false); unset($this->logger); }
/** * @expectedException \Oracle\OracleException */ public function testAutomaticallyValidateSql() { Config::put('validate_sql_syntax', true); new Statement("not a query", $this->connection); $this->fail('Invalid sql syntax should throw OracleException'); }