Skip to content

Commit

Permalink
Rename class PublicationField to PublicationFieldType
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Nov 22, 2022
1 parent d19c79c commit fcde4ea
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Hyde\Framework\Actions\Interfaces\CreateActionInterface;
use Hyde\Framework\Concerns\InteractsWithDirectories;
use Hyde\Framework\Features\Publications\Models\PublicationField;
use Hyde\Framework\Features\Publications\Models\PublicationFieldType;
use Hyde\Framework\Features\Publications\Models\PublicationType;
use Hyde\Framework\Features\Publications\PublicationHelper;
use Hyde\Hyde;
Expand Down Expand Up @@ -41,7 +41,7 @@ public function create(): void
{
$dir = ($this->pubType->getDirectory());
$canonicalFieldName = $this->pubType->canonicalField;
$canonicalFieldDefinition = $this->pubType->getFields()->filter(fn (PublicationField $field): bool => $field->name === $canonicalFieldName)->first() ?? throw new RuntimeException("Could not find field definition for '$canonicalFieldName'");
$canonicalFieldDefinition = $this->pubType->getFields()->filter(fn (PublicationFieldType $field): bool => $field->name === $canonicalFieldName)->first() ?? throw new RuntimeException("Could not find field definition for '$canonicalFieldName'");
$canonicalValue = $canonicalFieldDefinition->type !== 'array' ? $this->fieldData->{$canonicalFieldName} : $this->fieldData->{$canonicalFieldName}[0];
$canonicalStr = Str::of($canonicalValue)->substr(0, 64);
$slug = $canonicalStr->slug()->toString();
Expand All @@ -55,7 +55,7 @@ public function create(): void
$output = "---\n";
$output .= "__createdAt: $now\n";
foreach ($this->fieldData as $name => $value) {
/** @var PublicationField $fieldDefinition */
/** @var PublicationFieldType $fieldDefinition */
$fieldDefinition = $this->pubType->getFields()->where('name', $name)->firstOrFail();

if ($fieldDefinition->type == 'text') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @see \Hyde\Framework\Testing\Feature\PublicationFieldTest
*/
class PublicationField implements JsonSerializable, Arrayable
class PublicationFieldType implements JsonSerializable, Arrayable
{
use JsonSerializesArrayable;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public function getDirectory(): string
return $this->directory;
}

/** @return \Illuminate\Support\Collection<string, \Hyde\Framework\Features\Publications\Models\PublicationField> */
/** @return \Illuminate\Support\Collection<string, \Hyde\Framework\Features\Publications\Models\PublicationFieldType> */
public function getFields(): Collection
{
return collect($this->fields)->mapWithKeys(function (array $data) {
return [$data['name'] => new PublicationField(...$data)];
return [$data['name'] => new PublicationFieldType(...$data)];
});
}

Expand Down
22 changes: 11 additions & 11 deletions packages/framework/tests/Feature/PublicationFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

namespace Hyde\Framework\Testing\Feature;

use Hyde\Framework\Features\Publications\Models\PublicationField;
use Hyde\Framework\Features\Publications\Models\PublicationFieldType;
use Hyde\Testing\TestCase;
use InvalidArgumentException;

/**
* @covers \Hyde\Framework\Features\Publications\Models\PublicationField
* @covers \Hyde\Framework\Features\Publications\Models\PublicationFieldType
*/
class PublicationFieldTest extends TestCase
{
public function test_can_instantiate_class()
{
$field = $this->makeField();
$this->assertInstanceOf(PublicationField::class, $field);
$this->assertInstanceOf(PublicationFieldType::class, $field);

$this->assertSame('string', $field->type);
$this->assertSame('test', $field->name);
Expand All @@ -41,7 +41,7 @@ public function test_can_encode_field_as_json()

public function test_range_values_can_be_null()
{
$field = new PublicationField('string', 'test', null, null);
$field = new PublicationFieldType('string', 'test', null, null);
$this->assertNull($field->min);
$this->assertNull($field->max);
}
Expand All @@ -51,12 +51,12 @@ public function test_max_value_cannot_be_less_than_min_value()
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("The 'max' value cannot be less than the 'min' value.");

new PublicationField('string', 'test', 10, 1);
new PublicationFieldType('string', 'test', 10, 1);
}

public function test_integers_can_be_added_as_strings()
{
$field = new PublicationField('string', 'test', 1, '10');
$field = new PublicationFieldType('string', 'test', 1, '10');
$this->assertSame(1, $field->min);
$this->assertSame(10, $field->max);
}
Expand All @@ -73,20 +73,20 @@ public function test_types_constant()
'array',
'text',
'image',
], PublicationField::TYPES);
], PublicationFieldType::TYPES);
}

public function test_type_must_be_valid()
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage("The type 'invalid' is not a valid type. Valid types are: string, boolean, integer, float, datetime, url, array, text, image.");

new PublicationField('invalid', 'test', 1, 10);
new PublicationFieldType('invalid', 'test', 1, 10);
}

public function test_type_input_is_case_insensitive()
{
$field = new PublicationField('STRING', 'test', 1, 10);
$field = new PublicationFieldType('STRING', 'test', 1, 10);
$this->assertSame('string', $field->type);
}

Expand All @@ -95,8 +95,8 @@ public function test_validate_input_against_rules()
$this->markTestIncomplete('TODO: Implement this method.');
}

protected function makeField(): PublicationField
protected function makeField(): PublicationFieldType
{
return new PublicationField('string', 'test', 1, 10);
return new PublicationFieldType('string', 'test', 1, 10);
}
}
6 changes: 3 additions & 3 deletions packages/framework/tests/Feature/PublicationTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Hyde\Framework\Testing\Feature;

use function array_merge;
use Hyde\Framework\Features\Publications\Models\PublicationField;
use Hyde\Framework\Features\Publications\Models\PublicationFieldType;
use Hyde\Framework\Features\Publications\Models\PublicationType;
use Hyde\Hyde;
use Hyde\Testing\TestCase;
Expand Down Expand Up @@ -99,9 +99,9 @@ public function test_get_fields_method_returns_collection_of_field_objects()
$collection = $publicationType->getFields();
$this->assertCount(1, $collection);
$this->assertInstanceOf(Collection::class, $collection);
$this->assertInstanceOf(PublicationField::class, $collection->first());
$this->assertInstanceOf(PublicationFieldType::class, $collection->first());
$this->assertEquals(new Collection([
'test' => new PublicationField('string', 'test', 0, 128),
'test' => new PublicationFieldType('string', 'test', 0, 128),
]), $collection);
}

Expand Down

0 comments on commit fcde4ea

Please sign in to comment.