mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
fixed test service provider contextual binding
This commit is contained in:
parent
e79f3acc00
commit
39ab02e969
@ -3,6 +3,8 @@
|
||||
namespace App;
|
||||
|
||||
use App\Http\HttpHelper;
|
||||
use Database\Factories\AnimeFactory;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Jikan\Jikan;
|
||||
use Jikan\Request\Anime\AnimeRequest;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@ -215,4 +217,9 @@ class Anime extends JikanApiSearchableModel
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected static function newFactory()
|
||||
{
|
||||
return App::make(AnimeFactory::class);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
namespace App;
|
||||
|
||||
use App\Http\HttpHelper;
|
||||
use Database\Factories\MangaFactory;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Jikan\Jikan;
|
||||
use Jikan\Request\Manga\MangaRequest;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
@ -138,4 +140,9 @@ class Manga extends JikanApiSearchableModel
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
protected static function newFactory()
|
||||
{
|
||||
return App::make(MangaFactory::class);
|
||||
}
|
||||
}
|
||||
|
@ -43,4 +43,9 @@ class AnimeModelFactoryDescriptor implements MediaModelFactoryDescriptor
|
||||
{
|
||||
return GenreAnime::factory($count, $state);
|
||||
}
|
||||
|
||||
public function activityMarkerLogicalKeyName(): string
|
||||
{
|
||||
return "airing";
|
||||
}
|
||||
}
|
||||
|
@ -16,26 +16,33 @@ abstract class JikanMediaModelFactory extends JikanModelFactory implements Media
|
||||
|
||||
protected ?MediaModelFactoryDescriptor $descriptor;
|
||||
|
||||
protected function configureInternal(): self
|
||||
public function __construct(
|
||||
MediaModelFactoryDescriptor $descriptor,
|
||||
?int $count = null,
|
||||
?Collection $states = null,
|
||||
?Collection $has = null,
|
||||
?Collection $for = null,
|
||||
?Collection $afterMaking = null,
|
||||
?Collection $afterCreating = null,
|
||||
$connection = null,
|
||||
?Collection $recycle = null)
|
||||
{
|
||||
// contextual binding / service location
|
||||
App::call([$this, "withMediaModelFactoryDescriptor"]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
return $this->configureInternal();
|
||||
parent::__construct($count, $states, $has, $for, $afterMaking, $afterCreating, $connection, $recycle);
|
||||
$this->descriptor = $descriptor;
|
||||
}
|
||||
|
||||
protected function newInstance(array $arguments = []): self
|
||||
{
|
||||
return parent::newInstance($arguments)->configureInternal();
|
||||
}
|
||||
|
||||
public function withMediaModelFactoryDescriptor(MediaModelFactoryDescriptor $descriptor): void
|
||||
{
|
||||
$this->descriptor = $descriptor;
|
||||
return App::makeWith(static::class, array_merge([
|
||||
'count' => $this->count,
|
||||
'states' => $this->states,
|
||||
'has' => $this->has,
|
||||
'for' => $this->for,
|
||||
'afterMaking' => $this->afterMaking,
|
||||
'afterCreating' => $this->afterCreating,
|
||||
'connection' => $this->connection,
|
||||
'recycle' => $this->recycle,
|
||||
], $arguments));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,4 +44,9 @@ class MangaModelFactoryDescriptor implements MediaModelFactoryDescriptor
|
||||
{
|
||||
return GenreManga::factory($count, $state);
|
||||
}
|
||||
|
||||
public function activityMarkerLogicalKeyName(): string
|
||||
{
|
||||
return "publishing";
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,8 @@ interface MediaModelFactoryDescriptor
|
||||
{
|
||||
public function activityMarkerKeyName(): string;
|
||||
|
||||
public function activityMarkerLogicalKeyName(): string;
|
||||
|
||||
public function typeParamMap(): array;
|
||||
|
||||
public function statusParamMap(): array;
|
||||
|
@ -17,9 +17,6 @@ class TestServiceProvider extends ServiceProvider
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->singleton(MediaModelFactoryDescriptor::class, AnimeModelFactoryDescriptor::class);
|
||||
$this->app->singleton(MediaModelFactoryDescriptor::class, MangaModelFactoryDescriptor::class);
|
||||
|
||||
$this->app->when(AnimeFactory::class)
|
||||
->needs(MediaModelFactoryDescriptor::class)
|
||||
->give(AnimeModelFactoryDescriptor::class);
|
||||
|
Loading…
x
Reference in New Issue
Block a user