From 2e60145343edc9d6e3e48551ca6fc3ad8be87eb6 Mon Sep 17 00:00:00 2001 From: Robert Conner Date: Sun, 11 Aug 2019 20:25:51 -0400 Subject: [PATCH] namespace the tests, also fix issue with model config strings --- composer.json | 6 +++--- src/Events/TagAdded.php | 4 +++- src/Taggable.php | 21 ++++++++++++++++----- tests/CommonUsageTest.php | 2 +- tests/ConfigTest.php | 2 +- tests/EventTests.php | 2 +- tests/TagGroupTest.php | 2 +- tests/TagTest.php | 2 +- tests/TaggableContractTest.php | 2 +- tests/TaggedTest.php | 2 +- tests/TaggingUtilityTest.php | 2 +- tests/TestCase.php | 2 +- 12 files changed, 31 insertions(+), 18 deletions(-) diff --git a/composer.json b/composer.json index 481d940..e26eabc 100644 --- a/composer.json +++ b/composer.json @@ -12,8 +12,8 @@ ], "require": { "php": ">= 7.0", - "illuminate/database": "^5.0", - "illuminate/support": "^5.0" + "illuminate/database": ">= 5.0", + "illuminate/support": ">= 5.0" }, "require-dev": { "orchestra/testbench": "~3.8", @@ -28,7 +28,7 @@ }, "autoload-dev": { "psr-4": { - "Tests\\": "tests/" + "ConnerTests\\": "tests/" } }, "extra": { diff --git a/src/Events/TagAdded.php b/src/Events/TagAdded.php index 7689402..d7cbfd6 100644 --- a/src/Events/TagAdded.php +++ b/src/Events/TagAdded.php @@ -1,4 +1,6 @@ -getModel()->getMorphClass(); foreach($tagNames as $tagSlug) { - $tags = Tagged::query() + + $model = TaggingUtility::taggedModelString(); + + $tags = $model::query() ->where('tag_slug', TaggingUtility::normalize($tagSlug)) ->where('taggable_type', $className) ->get() @@ -245,7 +248,9 @@ private function addTag($tagName) $previousCount = $this->tagged()->where('tag_slug', '=', $tagSlug)->take(1)->count(); if($previousCount >= 1) { return; } - $tagged = new Tagged([ + $model = TaggingUtility::taggedModelString(); + + $tagged = new $model([ 'tag_name' => TaggingUtility::displayize($tagName), 'tag_slug' => $tagSlug, ]); @@ -286,7 +291,9 @@ private function removeSingleTag($tagName) */ public static function existingTags(): Collection { - return Tagged::query() + $model = TaggingUtility::taggedModelString(); + + return $model::query() ->distinct() ->join('tagging_tags', 'tag_slug', '=', 'tagging_tags.slug') ->where('taggable_type', '=', (new static)->getMorphClass()) @@ -301,7 +308,9 @@ public static function existingTags(): Collection */ public static function existingTagsInGroups($groups): Collection { - return Tagged::query() + $model = TaggingUtility::taggedModelString(); + + return $model::query() ->distinct() ->join('tagging_tags', 'tag_slug', '=', 'tagging_tags.slug') ->join('tagging_tag_groups', 'tag_group_id', '=', 'tagging_tag_groups.id') @@ -372,7 +381,9 @@ private function assembleTagsForScoping($query, $tagNames) $tagNames = array_map($normalizer, $tagNames); $className = $query->getModel()->getMorphClass(); - $tags = Tagged::query() + $model = TaggingUtility::taggedModelString(); + + $tags = $model::query() ->whereIn('tag_slug', $tagNames) ->where('taggable_type', $className) ->get() diff --git a/tests/CommonUsageTest.php b/tests/CommonUsageTest.php index 4dc7c7b..d6e32a2 100644 --- a/tests/CommonUsageTest.php +++ b/tests/CommonUsageTest.php @@ -1,6 +1,6 @@