Пример #1
0
 private function exportDao($intf, SQLLogger $logger = null)
 {
     if (!file_exists('tests/fixtures/exports')) {
         @mkdir('tests/fixtures/exports', 0777, true);
     }
     $config = new Configuration();
     $values = ['sqlRootDir' => 'tests/fixtures/sql', 'connectionString' => 'firebird:dbname=tests/fixtures/todo.fdb', 'dialect' => 'firebird', 'watchMode' => 'Always'];
     foreach ($values as $f => $v) {
         $config->{$f} = $v;
     }
     $context = new DaoBuilderContext($config);
     $builder = new DaoBuilder(new \ReflectionClass($intf), $context->getDaoClassName($intf));
     $builder->prepare();
     $c = $builder->export(true);
     $implClass = basename($builder->getClassName());
     $path = "tests/fixtures/exports/{$implClass}.php";
     file_put_contents($path, $c);
     require_once $path;
     $implClass = $builder->getClassName();
     $params = ['pdo' => new \PDO($context->getConfig()->connectionString, 'SYSDBA', 'masterkey'), 'driverClass' => FirebirdDriver::class];
     $conn = \Doctrine\DBAL\DriverManager::getConnection($params);
     $conn->getConfiguration()->setSQLLogger($logger);
     return new $implClass($conn, $context);
 }
Пример #2
0
 /**
  * @test
  */
 public function test_build_prepare_with_returning_case_sensitive()
 {
     $context = new DaoBuilderContext(new Configuration(function ($conf) {
         $conf->connectionString = 'sqlite:///:memory:';
     }));
     $builder = new DaoBuilder(new \ReflectionClass(TodoDao2::class), $context->getDaoClassName(TodoDao2::class));
     $factory = new DomainFactory();
     lowerSnake:
     $builder->prepare();
     $methods = $builder->getMethods();
     $info = $methods['findByIdReturningEditor'];
     $this->assertArrayHasKey('returnDomain', $info);
     $this->assertInstanceOf(Domain\ObjectDomain::class, $info['returnDomain']);
     $children = $info['returnDomain']->getChildren();
     $this->assertArrayHasKey('id', $children);
     $this->assertInstanceOf(Domain\NamedAliasDomain::class, $children['id']);
     $this->assertEquals('id', $children['id']->getName());
     $this->assertEquals(['todo_id'], $children['id']->getAlias());
     $this->assertArrayHasKey('creator', $children);
     $this->assertInstanceOf(Domain\NamedAliasDomain::class, $children['creator']);
     $this->assertEquals('creator', $children['creator']->getName());
     $this->assertEquals(['creator_id'], $children['creator']->getAlias());
     $this->assertEquals(['creator_name'], $children['creator']->getOptFields());
     upperSnake:
     $builder->setReturnCaseSensor(CaseSensor::UpperSnake());
     $builder->prepare();
     $methods = $builder->getMethods();
     $info = $methods['findByIdReturningEditor'];
     $this->assertArrayHasKey('returnDomain', $info);
     $this->assertInstanceOf(Domain\ObjectDomain::class, $info['returnDomain']);
     $children = $info['returnDomain']->getChildren();
     $this->assertArrayHasKey('id', $children);
     $this->assertInstanceOf(Domain\NamedAliasDomain::class, $children['id']);
     $this->assertEquals('ID', $children['id']->getName());
     $this->assertEquals(['TODO_ID'], $children['id']->getAlias());
     $this->assertArrayHasKey('creator', $children);
     $this->assertInstanceOf(Domain\NamedAliasDomain::class, $children['creator']);
     $this->assertEquals('CREATOR', $children['creator']->getName());
     $this->assertEquals(['CREATOR_ID'], $children['creator']->getAlias());
     $this->assertEquals(['CREATOR_NAME'], $children['creator']->getOptFields());
     lowerCamel:
     $builder->setReturnCaseSensor(CaseSensor::LowerCamel());
     $builder->prepare();
     $methods = $builder->getMethods();
     $info = $methods['findByIdReturningEditor'];
     $this->assertArrayHasKey('returnDomain', $info);
     $this->assertInstanceOf(Domain\ObjectDomain::class, $info['returnDomain']);
     $children = $info['returnDomain']->getChildren();
     $this->assertArrayHasKey('id', $children);
     $this->assertInstanceOf(Domain\NamedAliasDomain::class, $children['id']);
     $this->assertEquals('id', $children['id']->getName());
     $this->assertEquals(['todoId'], $children['id']->getAlias());
     $this->assertArrayHasKey('creator', $children);
     $this->assertInstanceOf(Domain\NamedAliasDomain::class, $children['creator']);
     $this->assertEquals('creator', $children['creator']->getName());
     $this->assertEquals(['creatorId'], $children['creator']->getAlias());
     $this->assertEquals(['creatorName'], $children['creator']->getOptFields());
     upperCamel:
     $builder->setReturnCaseSensor(CaseSensor::UpperCamel());
     $builder->prepare();
     $methods = $builder->getMethods();
     $info = $methods['findByIdReturningEditor'];
     $this->assertArrayHasKey('returnDomain', $info);
     $this->assertInstanceOf(Domain\ObjectDomain::class, $info['returnDomain']);
     $children = $info['returnDomain']->getChildren();
     $this->assertArrayHasKey('id', $children);
     $this->assertInstanceOf(Domain\NamedAliasDomain::class, $children['id']);
     $this->assertEquals('Id', $children['id']->getName());
     $this->assertEquals(['TodoId'], $children['id']->getAlias());
     $this->assertArrayHasKey('creator', $children);
     $this->assertInstanceOf(Domain\NamedAliasDomain::class, $children['creator']);
     $this->assertEquals('Creator', $children['creator']->getName());
     $this->assertEquals(['CreatorId'], $children['creator']->getAlias());
     $this->assertEquals(['CreatorName'], $children['creator']->getOptFields());
 }
Пример #3
0
 /**
  * @test
  */
 public function test_db_connection_string()
 {
     $context = new DaoBuilderContext(new Configuration(function ($conf) {
         $conf->connectionString = 'sqlite:///:memory:';
     }));
     $this->assertEquals('sqlite:///:memory:', $context->connectionString());
 }