Skip to content

Commit

Permalink
namespace the tests, also fix issue with model config strings
Browse files Browse the repository at this point in the history
  • Loading branch information
rtconner committed Aug 12, 2019
1 parent 20339ec commit 2e60145
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 18 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -28,7 +28,7 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
"ConnerTests\\": "tests/"
}
},
"extra": {
Expand Down
4 changes: 3 additions & 1 deletion src/Events/TagAdded.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Conner\Tagging\Events;
<?php

namespace Conner\Tagging\Events;

use Conner\Tagging\Model\Tagged;
use Conner\Tagging\Taggable;
Expand Down
21 changes: 16 additions & 5 deletions src/Taggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ public function scopeWithAllTags(Builder $query, $tagNames): Builder
$className = $query->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()
Expand Down Expand Up @@ -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,
]);
Expand Down Expand Up @@ -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())
Expand All @@ -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')
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/CommonUsageTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests;
namespace ConnerTests;

use Illuminate\Support\Collection;

Expand Down
2 changes: 1 addition & 1 deletion tests/ConfigTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests;
namespace ConnerTests;

use Conner\Tagging\Model\Tag;

Expand Down
2 changes: 1 addition & 1 deletion tests/EventTests.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests;
namespace ConnerTests;

use Conner\Tagging\Events\TagAdded;
use Conner\Tagging\Events\TagRemoved;
Expand Down
2 changes: 1 addition & 1 deletion tests/TagGroupTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests;
namespace ConnerTests;

use Conner\Tagging\Model\Tag;
use Conner\Tagging\Model\TagGroup;
Expand Down
2 changes: 1 addition & 1 deletion tests/TagTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests;
namespace ConnerTests;

use Conner\Tagging\Model\Tag;

Expand Down
2 changes: 1 addition & 1 deletion tests/TaggableContractTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests;
namespace ConnerTests;

use Conner\Tagging\Contracts\TaggableContract;
use Conner\Tagging\Taggable;
Expand Down
2 changes: 1 addition & 1 deletion tests/TaggedTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests;
namespace ConnerTests;

use Conner\Tagging\Model\Tagged;

Expand Down
2 changes: 1 addition & 1 deletion tests/TaggingUtilityTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests;
namespace ConnerTests;

use Conner\Tagging\Model\Tag;
use Conner\Tagging\TaggingUtility;
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests;
namespace ConnerTests;

use Conner\Tagging\Contracts\TaggableContract;
use Conner\Tagging\Providers\TaggingServiceProvider;
Expand Down

0 comments on commit 2e60145

Please sign in to comment.