Skip to content

Commit

Permalink
test improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
frasmage committed Apr 18, 2024
1 parent 4b165f9 commit b21d81e
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 83 deletions.
3 changes: 1 addition & 2 deletions src/Commands/RefreshMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,4 @@ public function handle(): void

$this->info('Refresh complete.');
}

}
}
3 changes: 1 addition & 2 deletions tests/Integration/Commands/RefreshMetaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,4 @@ public function test_it_refreshes_all_meta_values(): void
$this->assertEquals('2020-01-01 00:00:00.000000+0000', $result[2]->string_value);
$this->assertEquals(1577836800, $result[2]->numeric_value);
}

}
}
191 changes: 112 additions & 79 deletions tests/Integration/DataType/HandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,108 +41,134 @@ public static function handlerProvider(): array

return [
'array' => [
new ArrayHandler(),
'array',
['foo' => ['bar'], 'baz'],
[new stdClass()],
null,
null,
'handler' => new ArrayHandler(),
'type' => 'array',
'value' => ['foo' => ['bar'], 'baz'],
'invalid' => [new stdClass()],
'numericValue' => null,
'stringValue' => null,
'stringValueComplex' => json_encode(['foo' => ['bar'], 'baz']),
'isIdempotent' => true,
],
'boolean' => [
new BooleanHandler(),
'boolean',
true,
[1, 0, '', [], null],
1,
'true'
'handler' => new BooleanHandler(),
'type' => 'boolean',
'value' => true,
'invalid' => [1, 0, '', [], null],
'numericValue' => 1,
'stringValue' => 'true',
'stringValueComplex' => 'true',
'isIdempotent' => true,
],
'datetime' => [
new DateTimeHandler(),
'datetime',
$datetime,
[2017, '2017-01-01'],
$timestamp,
$dateString,
'handler' => new DateTimeHandler(),
'type' => 'datetime',
'value' => $datetime,
'invalid' => [2017, '2017-01-01'],
'numericValue' => $timestamp,
'stringValue' => $dateString,
'stringValueComplex' => $dateString,
'isIdempotent' => true,
],
'float' => [
new FloatHandler(),
'float',
1.1,
['1.1', 1],
1.1,
'1.1',
'handler' => new FloatHandler(),
'type' => 'float',
'value' => 1.1,
'invalid' => ['1.1', 1],
'numericValue' => 1.1,
'stringValue' => '1.1',
'stringValueComplex' => '1.1',
'isIdempotent' => true,
],
'integer' => [
new IntegerHandler(),
'integer',
3,
[1.1, '1'],
3,
'3',
'handler' => new IntegerHandler(),
'type' => 'integer',
'value' => 3,
'invalid' => [1.1, '1'],
'numericValue' => 3,
'stringValue' => '3',
'stringValueComplex' => '3',
'isIdempotent' => true,
],
'model' => [
new ModelHandler(),
'model',
$model,
[new stdClass()],
null,
SampleMetable::class,
'handler' => new ModelHandler(),
'type' => 'model',
'value' => $model,
'invalid' => [new stdClass()],
'numericValue' => null,
'stringValue' => SampleMetable::class,
'stringValueComplex' => SampleMetable::class,
'isIdempotent' => true,
],
'model collection' => [
new ModelCollectionHandler(),
'collection',
new Collection([new SampleMetable()]),
[collect()],
null,
null,
'handler' => new ModelCollectionHandler(),
'type' => 'collection',
'value' => new Collection([new SampleMetable()]),
'invalid' => [collect()],
'numericValue' => null,
'stringValue' => null,
'stringValueComplex' => null,
'isIdempotent' => true,
],
'null' => [
new NullHandler(),
'null',
null,
[0, '', 'null', [], false],
null,
null,
'handler' => new NullHandler(),
'type' => 'null',
'value' => null,
'invalid' => [0, '', 'null', [], false],
'numericValue' => null,
'stringValue' => null,
'stringValueComplex' => null,
'isIdempotent' => true,
],
'object' => [
new ObjectHandler(),
'object',
$object,
[[]],
null,
null,
'handler' => new ObjectHandler(),
'type' => 'object',
'value' => $object,
'invalid' => [[]],
'numericValue' => null,
'stringValue' => null,
'stringValueComplex' => json_encode($object),
'isIdempotent' => true,
],
'serialize' => [
new SerializeHandler(),
'serialized',
['foo' => 'bar', 'baz' => [3]],
[self::$resource],
null,
null,
'handler' => new SerializeHandler(),
'type' => 'serialized',
'value' => ['foo' => 'bar', 'baz' => [3]],
'invalid' => [self::$resource],
'numericValue' => null,
'stringValue' => null,
'stringValueComplex' => serialize(['foo' => 'bar', 'baz' => [3]]),
'isIdempotent' => false,
],
'serializable' => [
new SerializableHandler(),
'serializable',
new SampleSerializable(['foo' => 'bar']),
[],
null,
null,
'handler' => new SerializableHandler(),
'type' => 'serializable',
'value' => new SampleSerializable(['foo' => 'bar']),
'invalid' => [],
'numericValue' => null,
'stringValue' => null,
'stringValueComplex' => serialize(new SampleSerializable(['foo' => 'bar'])),
'isIdempotent' => true,
],
'string' => [
new StringHandler(),
'string',
'foo',
[1, 1.1],
null,
'foo',
'handler' => new StringHandler(),
'type' => 'string',
'value' => 'foo',
'invalid' => [1, 1.1],
'numericValue' => null,
'stringValue' => 'foo',
'stringValueComplex' => 'foo',
'isIdempotent' => true,
],
'numeric-string' => [
new StringHandler(),
'string',
'1.2345',
[1, 1.1],
1.2345,
'1.2345',
'handler' => new StringHandler(),
'type' => 'string',
'value' => '1.2345',
'invalid' => [1, 1.1],
'numericValue' => 1.2345,
'stringValue' => '1.2345',
'stringValueComplex' => '1.2345',
'isIdempotent' => true,
],
];
}
Expand All @@ -165,7 +191,9 @@ public function test_it_can_verify_and_serialize_data(
mixed $value,
array $incompatible,
null|int|float $numericValue,
null|string $stringValue
null|string $stringValue,
null|string $stringValueComplex,
bool $isIdempotent
): void {
$this->assertEquals($type, $handler->getDataType());
$this->assertTrue($handler->canHandleValue($value));
Expand All @@ -179,6 +207,11 @@ public function test_it_can_verify_and_serialize_data(

$this->assertEquals($value, $unserialized);
$this->assertEquals($numericValue, $handler->getNumericValue($value));
config()->set('metable.indexComplexDataTypes', false);
$this->assertEquals($stringValue, $handler->getStringValue($value));
config()->set('metable.indexComplexDataTypes', true);
$this->assertEquals($stringValueComplex, $handler->getStringValue($value));

$this->assertEquals($isIdempotent, $handler->isIdempotent());
}
}

0 comments on commit b21d81e

Please sign in to comment.