private function returningToDomain(array $returnTypes, array $attrs, AnnotationReader $reader) { if ($this->extractAnnotation($attrs, Select::class) !== null) { $returning = $this->extractAnnotation($attrs, Returning::class); return $this->factory->parse('', isset($returning) ? $returning->type : 'array[]', $this->returnCaseSensor); } elseif ($this->extractAnnotation($attrs, AbstractCommandAnnotation::class) !== null) { if (count($returnTypes) > 0) { return $this->factory->parse('', count($returnTypes) === 1 ? current($returnTypes)['typeName'] : 'array', $this->returnCaseSensor); } } // else return $this->factory->parse('', 'int', $this->returnCaseSensor); }
/** * @test */ public function test_build_prepare_with_returning() { $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(); $builder->prepare(); $methods = $builder->getMethods(); listById: $info = $methods['listById']; $this->assertArrayHasKey('returnDomain', $info); $this->assertInstanceOf(Domain\ArrayDomain::class, $info['returnDomain']); $this->assertInstanceOf(Domain\AnyArrayDomain::class, $info['returnDomain']->childDomain()); $this->assertInstanceOf(Domain\BuiltinDomain::class, $info['returnDomain']->childDomain()->childDomain()); $this->assertEquals(Type::STRING, $info['returnDomain']->childDomain()->childDomain()->getType()); listAll: $info = $methods['listAll']; $actial = $factory->parse('', Todo::class, CaseSensor::LowerSnake()); $this->assertArrayHasKey('returnDomain', $info); $this->assertInstanceOf(Domain\ArrayDomain::class, $info['returnDomain']); $this->assertInstanceOf(Domain\ObjectDomain::class, $info['returnDomain']->childDomain()); $this->assertEquals($actial, $info['returnDomain']->childDomain()); listAllAsRawArray: $info = $methods['listAllAsRawArray']; $actial = $factory->parse('', Todo::class, CaseSensor::LowerSnake()); $this->assertArrayHasKey('returnDomain', $info); $this->assertInstanceOf(Domain\AnyArrayDomain::class, $info['returnDomain']); $this->assertInstanceOf(Domain\BuiltinDomain::class, $info['returnDomain']->childDomain()); $this->assertEquals(Type::STRING, $info['returnDomain']->childDomain()->getType()); listByPub: $info = $methods['listByPub']; $actial = $factory->parse('', Todo::class, CaseSensor::LowerSnake()); $this->assertArrayHasKey('returnDomain', $info); $this->assertInstanceOf(Domain\ArrayDomain::class, $info['returnDomain']); $this->assertInstanceOf(Domain\ObjectDomain::class, $info['returnDomain']->childDomain()); $this->assertEquals($actial, $info['returnDomain']->childDomain()); findById: $info = $methods['findById']; $actial = $factory->parse('', Todo::class, CaseSensor::LowerSnake()); $this->assertArrayHasKey('returnDomain', $info); $this->assertInstanceOf(Domain\ObjectDomain::class, $info['returnDomain']); $this->assertEquals($actial, $info['returnDomain']); }
/** * @test */ public function test_built_complex_domain() { $factory = new DomainFactory(); $defs = new Domain\ComplexDomain(['obj' => $factory->parse('', '\\Omelet\\Tests\\Target\\Todo', CaseSensor::LowerSnake()), 'hoge' => $factory->parse('', 'int', CaseSensor::LowerSnake())]); $children = $defs->getChildren(); $this->assertCount(2, $children); $this->assertInstanceOf(Domain\ObjectDomain::class, $children['obj']); $this->assertInstanceOf(Domain\BuiltinDomain::class, $children['hoge']); $values = ['obj' => Todo::__set_state(['id' => 1024, 'todo' => 'test', 'created' => new \DateTime('2015/5/18 12:7:09'), 'hidden' => new Hidden(true)]), 'hoge' => 4096]; $this->assertEquals(['obj_id' => Type::getType(Type::INTEGER), 'obj_todo' => Type::getType(Type::STRING), 'obj_created' => Type::getType(Type::DATETIME), 'obj_hidden' => Type::getType(Type::BOOLEAN), 'obj_creator' => Type::getType(Type::STRING), 'hoge' => Type::getType(Type::INTEGER)], $defs->expandTypes(['obj_id', 'obj_todo', 'obj_created', 'obj_hidden', 'obj_creator', 'hoge'], '', $values, CaseSensor::LowerSnake())); $this->assertEquals(['obj_id' => 1024, 'obj_todo' => 'test', 'obj_created' => new \DateTime('2015/5/18 12:7:09'), 'obj_hidden' => true, 'obj_creator' => null, 'hoge' => 4096], $defs->expandValues(['obj_id', 'obj_todo', 'obj_created', 'obj_hidden', 'obj_creator', 'hoge'], '', $values, CaseSensor::LowerSnake())); }