diff --git a/clover.xml b/clover.xml index 9eb0de9..d400672 100644 --- a/clover.xml +++ b/clover.xml @@ -1,6 +1,6 @@ - - + + @@ -671,7 +671,7 @@ - + @@ -706,11 +706,11 @@ - - - - - + + + + + @@ -767,20 +767,6 @@ - - - - - - - - - - - - - - @@ -1903,24 +1889,24 @@ - + - - - - - + + + + + - + - - - - - + + + + + @@ -1979,11 +1965,11 @@ - + - + @@ -2022,6 +2008,7 @@ + @@ -2039,25 +2026,25 @@ - - - - - - - + + + + + + + - - - - - - - - - - + + + + + + + + + + @@ -2066,8 +2053,8 @@ - - + + @@ -2082,95 +2069,104 @@ - - - - - - - + + + + + + + + + + + + + + + + - - - - - + + + + + - - - - + + + + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -2486,28 +2482,28 @@ - - - - - - - - - - + + + + + + + + + + - - - - - - + + + + + + @@ -2616,8 +2612,8 @@ - - + + @@ -2772,14 +2768,14 @@ - - - - - - - - + + + + + + + + @@ -2908,6 +2904,6 @@ - + diff --git a/src/blocks/Logger.php b/src/blocks/Logger.php deleted file mode 100644 index d040a1e..0000000 --- a/src/blocks/Logger.php +++ /dev/null @@ -1,15 +0,0 @@ -getModelEntity($relEntity, $rId); + // swap table and field trying to find rels with inverse + if (!property_exists($model, $lowEntity . PhpInterface::UNDERSCORE . RamlInterface::RAML_ID)) { + $ucTmp = $ucEntity; + $ucEntity = ucfirst($lowEntity); + $relEntity = Classes::getModelEntity($ucEntity); + $model = $this->getModelEntity($relEntity, $eId); + $lowEntity = strtolower($ucTmp); + $model->{$lowEntity . PhpInterface::UNDERSCORE . RamlInterface::RAML_ID} = $rId; + $model->save(); + return; + } $model->{$lowEntity . PhpInterface::UNDERSCORE . RamlInterface::RAML_ID} = $eId; $model->save(); } diff --git a/tests/_data/TagFixture.php b/tests/_data/TagFixture.php new file mode 100644 index 0000000..9f2b106 --- /dev/null +++ b/tests/_data/TagFixture.php @@ -0,0 +1,27 @@ +title = 'Foo Bar Baz'; + $user->save(); + + return $user; + } + + /** + * @param $id + */ + public static function delete($id) : void + { + Tag::destroy($id); + } +} \ No newline at end of file diff --git a/tests/_data/TopicFixture.php b/tests/_data/TopicFixture.php new file mode 100644 index 0000000..3550cc4 --- /dev/null +++ b/tests/_data/TopicFixture.php @@ -0,0 +1,28 @@ +title = 'Foo Bar Baz'; + $user->save(); + + return $user; + } + + /** + * @param $id + */ + public static function delete($id) : void + { + Topic::destroy($id); + } +} \ No newline at end of file diff --git a/tests/unit/extension/BaseRelationsTraitTest.php b/tests/unit/extension/BaseRelationsTraitTest.php new file mode 100644 index 0000000..a561e42 --- /dev/null +++ b/tests/unit/extension/BaseRelationsTraitTest.php @@ -0,0 +1,57 @@ +article = ArticleFixture::createAndGet(); + $this->topic = TopicFixture::createAndGet(); + $this->entity = 'Article'; + $this->modelEntity = Article::class; + } + + /** + * @test + */ + public function it_sets_relationships() + { + $this->setRelationships([ + RamlInterface::RAML_DATA => [ + 'type' => 'article', + 'id' => $this->article->id, + RamlInterface::RAML_RELATIONSHIPS => [ + 'topic' => [ + 'data' => ['type' => 'topic', 'id' => $this->topic->id] + ], + ], + ]], $this->article->id); + $article = $this->getEntity($this->article->id); + $this->assertEquals($this->topic->id, $article->topic_id); + } + + public function tearDown() + { + ArticleFixture::delete($this->article->id); + TopicFixture::delete($this->topic->id); + parent::tearDown(); + } +} \ No newline at end of file