Skip to content

Commit 9e907a6

Browse files
committed
fix: Regression on the getter and setter for the custom slug generator
Fixes: #36 Signed-off-by: Bruno Gaspar <brunofgaspar1@gmail.com>
1 parent aa8962a commit 9e907a6

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

src/TaggableInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,18 @@ public static function setTagsModel(string $model): void;
6161
/**
6262
* Returns the slug generator.
6363
*
64-
* @return string
64+
* @return \Closure|string
6565
*/
66-
public static function getSlugGenerator(): string;
66+
public static function getSlugGenerator();
6767

6868
/**
6969
* Sets the slug generator.
7070
*
71-
* @param string $name
71+
* @param \Closure|string $name
7272
*
7373
* @return void
7474
*/
75-
public static function setSlugGenerator(string $name): void;
75+
public static function setSlugGenerator($name): void;
7676

7777
/**
7878
* Returns the entity Eloquent tag model object.

src/TaggableTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ public static function setTagsModel(string $model): void
8282
/**
8383
* {@inheritdoc}
8484
*/
85-
public static function getSlugGenerator(): string
85+
public static function getSlugGenerator()
8686
{
8787
return static::$slugGenerator;
8888
}
8989

9090
/**
9191
* {@inheritdoc}
9292
*/
93-
public static function setSlugGenerator(string $slugGenerator): void
93+
public static function setSlugGenerator($slugGenerator): void
9494
{
9595
static::$slugGenerator = $slugGenerator;
9696
}

tests/TaggableTraitTest.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,24 @@ public function it_can_get_and_set_the_tags_model()
172172
}
173173

174174
/** @test */
175-
public function it_can_get_and_set_the_slug_generator()
175+
public function it_can_get_and_set_the_slug_generator_as_a_string()
176176
{
177177
$post = new Post();
178178

179179
$post->setSlugGenerator('Illuminate\Support\Str::slug');
180180

181181
$this->assertSame('Illuminate\Support\Str::slug', $post->getSlugGenerator());
182182
}
183+
184+
/** @test */
185+
public function it_can_get_and_set_the_slug_generator_as_a_closure()
186+
{
187+
$post = new Post();
188+
189+
$post->setSlugGenerator(function ($value) {
190+
return str_replace(' ', '_', strtolower($value));
191+
});
192+
193+
$this->assertIsObject($post->getSlugGenerator());
194+
}
183195
}

0 commit comments

Comments
 (0)