Skip to content

Commit

Permalink
type cleanup and support for creating provisional drafts
Browse files Browse the repository at this point in the history
  • Loading branch information
markhuot committed Oct 1, 2024
1 parent 9724d5c commit 5a83332
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/factories/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
*
* > **Note**
* > Any assets created during a test will be cleaned up and deleted after the test.
*
* @extends Factory<\craft\elements\Asset>
*/
class Asset extends Element

Check failure on line 30 in src/factories/Asset.php

View workflow job for this annotation

GitHub Actions / test (~5.3.0, 5.3)

The @extends tag of class markhuot\craftpest\factories\Asset describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 30 in src/factories/Asset.php

View workflow job for this annotation

GitHub Actions / test (~5.4.0, 5.4)

The @extends tag of class markhuot\craftpest\factories\Asset describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 30 in src/factories/Asset.php

View workflow job for this annotation

GitHub Actions / test (~5.1.0, 5)

The @extends tag of class markhuot\craftpest\factories\Asset describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 30 in src/factories/Asset.php

View workflow job for this annotation

GitHub Actions / test (~5.2.0, 5.2)

The @extends tag of class markhuot\craftpest\factories\Asset describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 30 in src/factories/Asset.php

View workflow job for this annotation

GitHub Actions / test (~5.0.0, 5)

The @extends tag of class markhuot\craftpest\factories\Asset describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 30 in src/factories/Asset.php

View workflow job for this annotation

GitHub Actions / test (~4.7.0, 4)

The @extends tag of class markhuot\craftpest\factories\Asset describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 30 in src/factories/Asset.php

View workflow job for this annotation

GitHub Actions / test (~4.5.0, 4)

The @extends tag of class markhuot\craftpest\factories\Asset describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 30 in src/factories/Asset.php

View workflow job for this annotation

GitHub Actions / test (~4.6.0, 4)

The @extends tag of class markhuot\craftpest\factories\Asset describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.
{
Expand Down
1 change: 1 addition & 0 deletions src/factories/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @method self title(string $title)
* @extends Factory<\craft\elements\Category>
*/
class Category extends Element

Check failure on line 9 in src/factories/Category.php

View workflow job for this annotation

GitHub Actions / test (~5.3.0, 5.3)

The @extends tag of class markhuot\craftpest\factories\Category describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/Category.php

View workflow job for this annotation

GitHub Actions / test (~5.4.0, 5.4)

The @extends tag of class markhuot\craftpest\factories\Category describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/Category.php

View workflow job for this annotation

GitHub Actions / test (~5.1.0, 5)

The @extends tag of class markhuot\craftpest\factories\Category describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/Category.php

View workflow job for this annotation

GitHub Actions / test (~5.2.0, 5.2)

The @extends tag of class markhuot\craftpest\factories\Category describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/Category.php

View workflow job for this annotation

GitHub Actions / test (~5.0.0, 5)

The @extends tag of class markhuot\craftpest\factories\Category describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/Category.php

View workflow job for this annotation

GitHub Actions / test (~4.7.0, 4)

The @extends tag of class markhuot\craftpest\factories\Category describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/Category.php

View workflow job for this annotation

GitHub Actions / test (~4.5.0, 4)

The @extends tag of class markhuot\craftpest\factories\Category describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/Category.php

View workflow job for this annotation

GitHub Actions / test (~4.6.0, 4)

The @extends tag of class markhuot\craftpest\factories\Category describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.
{
Expand Down
8 changes: 8 additions & 0 deletions src/factories/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* @phpstan-ignore-next-line ignored because the file is generated
*
* @mixin FactoryFields
* @extends Factory<\craft\elements\Entry>
*/
class Entry extends Element
{
Expand Down Expand Up @@ -104,6 +105,13 @@ public function setDateField($key, $value)
$this->attributes[$key] = $value;
}

public function isProvisionalDraft($provisionalDraft=true): self
{
$this->attributes['isProvisionalDraft'] = $provisionalDraft;

return $this;
}

/**
* Set the author of the entry. You may pass a full user object, a user ID,
* a username, email, or a user ID.
Expand Down
2 changes: 1 addition & 1 deletion src/factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function __isset($key)
* Create a new factory by calling `::factory()` on the type of element to be
* created, such as `Entry::factory()` or `Asset::factory()`.
*/
public static function factory()
public static function factory(): static
{
return new static;
}
Expand Down
1 change: 1 addition & 0 deletions src/factories/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @method self admin(bool $isAdmin)
* @extends Factory<\craft\elements\User>
*/
class User extends Element

Check failure on line 9 in src/factories/User.php

View workflow job for this annotation

GitHub Actions / test (~5.3.0, 5.3)

The @extends tag of class markhuot\craftpest\factories\User describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/User.php

View workflow job for this annotation

GitHub Actions / test (~5.4.0, 5.4)

The @extends tag of class markhuot\craftpest\factories\User describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/User.php

View workflow job for this annotation

GitHub Actions / test (~5.1.0, 5)

The @extends tag of class markhuot\craftpest\factories\User describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/User.php

View workflow job for this annotation

GitHub Actions / test (~5.2.0, 5.2)

The @extends tag of class markhuot\craftpest\factories\User describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/User.php

View workflow job for this annotation

GitHub Actions / test (~5.0.0, 5)

The @extends tag of class markhuot\craftpest\factories\User describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/User.php

View workflow job for this annotation

GitHub Actions / test (~4.7.0, 4)

The @extends tag of class markhuot\craftpest\factories\User describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/User.php

View workflow job for this annotation

GitHub Actions / test (~4.5.0, 4)

The @extends tag of class markhuot\craftpest\factories\User describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.

Check failure on line 9 in src/factories/User.php

View workflow job for this annotation

GitHub Actions / test (~4.6.0, 4)

The @extends tag of class markhuot\craftpest\factories\User describes markhuot\craftpest\factories\Factory but the class extends markhuot\craftpest\factories\Element.
{
Expand Down
3 changes: 3 additions & 0 deletions src/factories/Volume.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
use function markhuot\craftpest\helpers\craft\volumeDefinition;
use function markhuot\craftpest\helpers\craft\volumeDeleteRootDirectory;

/**
* @extends Factory<\craft\models\Volume>
*/
class Volume extends Factory
{
/**
Expand Down
11 changes: 11 additions & 0 deletions tests/ProvisionalDraftTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use markhuot\craftpest\factories\Entry;

it('creates provisional drafts', function () {
$entry = Entry::factory()
->isProvisionalDraft()
->create();

expect($entry)->isProvisionalDraft->toBeTrue();
});

0 comments on commit 5a83332

Please sign in to comment.