function testRelations() { $m = $this->getManager('test_'); // Создание схем $authors = new Schema($m, 'authors'); $authors->addId()->addChar('name')->addDate('birthday'); $books = new Schema($m); $books->setName('Books')->addId()->addChar('name'); $tags = new Schema($m); $tags->setName('Tags')->addId()->addChar('name'); // Расстановка ключей $books_tags = new Schema($m); $books_tags->setTable('books_tags')->addOneToOne($books, null, null, Schema::FK_CASCADE)->addOneToOne($tags, 'tag_custom_id'); $authors->addOneToMany($books, null, null, 'MyBooks', 'MyBook'); $books->addOneToOne($authors, null, null, Schema::FK_RESTRICT, Schema::FK_CASCADE, 'MyAuthors', 'MyAuthor')->addOneToOne($authors, 'redactor_id', null, Schema::FK_RESTRICT, Schema::FK_CASCADE, 'Redactors', 'Redactor')->addManyToMany($tags, $books_tags, 'tag_custom_id', null, null, null, 'MyTags', 'MyTag'); $tags->addManyToMany($books, $books_tags, null, 'tag_custom_id'); // Генерация миграций // $this->saveMigr($authors, 'new authors'); // $this->saveMigr($books, 'new books'); // $this->saveMigr($tags, 'new tags'); // $this->saveMigr($books_tags, 'new books tags'); $exp = file_get_contents($this->temp . '/MigrationAuthors.php'); $res = $authors->makeMigration('new authors'); $this->assertEquals($exp, $res, 'Генерация миграции Authors'); $exp = file_get_contents($this->temp . '/MigrationBooks.php'); $res = $books->makeMigration('new books'); $this->assertEquals($exp, $res, 'Генерация миграции Books'); $exp = file_get_contents($this->temp . '/MigrationTags.php'); $res = $tags->makeMigration('new tags'); $this->assertEquals($exp, $res, 'Генерация миграции Tags'); $exp = file_get_contents($this->temp . '/MigrationBooksTags.php'); $res = $books_tags->makeMigration('new books tags'); $this->assertEquals($exp, $res, 'Генерация миграции BooksTags'); // Генерация модели // file_put_contents($this->temp . '/AuthorItem.php', $authors->makeItem()); // file_put_contents($this->temp . '/BookItem.php', $books->makeItem()); // file_put_contents($this->temp . '/TagItem.php', $tags->makeItem()); $exp = file_get_contents($this->temp . '/AuthorItem.php'); $this->assertEquals($exp, $authors->makeItem(), 'Author Item'); $exp = file_get_contents($this->temp . '/BookItem.php'); $this->assertEquals($exp, $books->makeItem(), 'Book Item'); $exp = file_get_contents($this->temp . '/TagItem.php'); $this->assertEquals($exp, $tags->makeItem(), 'Tag Item'); }