Skip to content

Commit a53268a

Browse files
committed
Ensure new changes are backwards compatible
1 parent 8f25e12 commit a53268a

File tree

5 files changed

+37
-7
lines changed

5 files changed

+37
-7
lines changed

src/Concerns/HasDrafts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public function updateAsDraft(array $attributes = [], array $options = []): bool
283283
return $this->fill($attributes)->saveAsDraft($options);
284284
}
285285

286-
public static function createDraft(...$attributes): self
286+
public static function createDraft(...$attributes): static
287287
{
288288
return tap(static::make(...$attributes), function ($instance) {
289289
$instance->{$instance->getIsPublishedColumn()} = false;

src/Contacts/Draftable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function savedAsDraft(string|Closure $callback): void;
5353

5454
public function updateAsDraft(array $attributes = [], array $options = []): bool;
5555

56-
public static function createDraft(...$attributes): self;
56+
public static function createDraft(...$attributes): static;
5757

5858
public function setPublisher(): static;
5959

tests/Post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Oddvalue\LaravelDrafts\Concerns\HasDrafts;
1212
use Oddvalue\LaravelDrafts\Contacts\Draftable;
1313

14-
class Post extends Model implements Draftable
14+
class Post extends Model
1515
{
1616
use HasDrafts;
1717
use HasFactory;

tests/SchedulingPost.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Oddvalue\LaravelDrafts\Tests;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
8+
use Illuminate\Database\Eloquent\Relations\HasMany;
9+
use Illuminate\Database\Eloquent\Relations\HasOne;
10+
use Illuminate\Database\Eloquent\Relations\MorphToMany;
11+
use Oddvalue\LaravelDrafts\Concerns\HasDrafts;
12+
use Oddvalue\LaravelDrafts\Contacts\Draftable;
13+
use Oddvalue\LaravelDrafts\Database\Factories\PostFactory;
14+
15+
/**
16+
* This Draftable trait was added after v1 was tagged, this model should be used for all new tests and existing
17+
* functionality must be tested against Post to ensure backwards compatibility.
18+
*/
19+
class SchedulingPost extends Post implements Draftable
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
protected $table = 'posts';
25+
26+
protected static function newFactory(): PostFactory
27+
{
28+
return new PostFactory();
29+
}
30+
}

tests/SchedulingTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?php
22

3-
use Oddvalue\LaravelDrafts\Tests\Post;
3+
use Oddvalue\LaravelDrafts\Tests\SchedulingPost;
44

55
use function Spatie\PestPluginTestTime\testTime;
66

77
it('can schedule draft', function () {
88
$willPublishAt = now()->addMonth();
9-
$post = Post::factory()->published()->create();
9+
$post = SchedulingPost::factory()->published()->create();
1010
$draft = $post->createDraft(['title' => 'Hello World']);
1111
$draft->schedulePublishing($willPublishAt);
1212
$this->assertDatabaseHas('posts', [
@@ -18,13 +18,13 @@
1818

1919
it('can publish scheduled drafts', function () {
2020
$willPublishAt = now()->addWeek();
21-
$post = Post::factory()->published()->create();
21+
$post = SchedulingPost::factory()->published()->create();
2222
$draft = $post->createDraft(['title' => 'Hello World']);
2323
$draft->schedulePublishing($willPublishAt);
2424

2525
testTime()->addMonth()->freeze();
2626

27-
\Illuminate\Support\Facades\Artisan::call('drafts:publish', ['model' => Post::class]);
27+
\Illuminate\Support\Facades\Artisan::call('drafts:publish', ['model' => SchedulingPost::class]);
2828

2929
$this->assertDatabaseHas('posts', [
3030
'title' => 'Hello World',

0 commit comments

Comments
 (0)