Skip to content

Commit

Permalink
passing craft 5 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markhuot committed Mar 20, 2024
1 parent abafb54 commit 030c2e9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/factories/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,13 @@ public function newElement()
*/
public function inferences(array $definition = [])
{
$sectionId = $this->inferSectionId();
$typeId = $this->inferTypeId($sectionId);
if (empty($this->entryTypeIdentifier)) {
$sectionId = $this->inferSectionId();
$typeId = $this->inferTypeId($sectionId);
} else {
$sectionId = null;
$typeId = \Craft::$app->getEntries()->getEntryTypeByHandle($this->entryTypeIdentifier)->id;
}

return array_merge($definition, [
'sectionId' => $sectionId,
Expand Down
6 changes: 4 additions & 2 deletions tests/FactoryFieldTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use Composer\InstalledVersions;
use Composer\Semver\VersionParser;
use markhuot\craftpest\factories\Entry;
use markhuot\craftpest\factories\Field;
use markhuot\craftpest\factories\Section;
Expand All @@ -24,9 +26,9 @@
expect(\craft\elements\Entry::find()->count())->toBe($entryCount);
});

it('errors when trying to create fields after content elements', function () {
it('errors when trying to create fields after content elements in Craft 4', function () {
$this->expectException(\markhuot\craftpest\exceptions\AutoCommittingFieldsException::class);

Section::factory()->create();
Field::factory()->type(\craft\fields\PlainText::class)->create();
});
})->skip(InstalledVersions::satisfies(new VersionParser, 'craftcms/cms', '>=5.0.0'));

0 comments on commit 030c2e9

Please sign in to comment.