-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refactor configurable morph type and rewrite tests for pest
* ci: load database migrations when running `phpstan` * refactor: refactor configurable morph type code * refactor: refactor tests to pest format * test: fix tests
- Loading branch information
Showing
24 changed files
with
2,958 additions
and
3,588 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,60 +1,41 @@ | ||
<?php | ||
|
||
namespace Kolossal\Multiplex\Tests; | ||
|
||
use Kolossal\Multiplex\DataType\ArrayHandler; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
final class DataTypeArrayHandlerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_will_resolve_null_as_null(): void | ||
{ | ||
$handler = new ArrayHandler; | ||
it('will resolve null as null', function () { | ||
$handler = new ArrayHandler; | ||
|
||
$this->assertInstanceOf(ArrayHandler::class, $handler); | ||
expect($handler)->toBeInstanceOf(ArrayHandler::class); | ||
|
||
$this->assertNull($handler->unserializeValue(null)); | ||
} | ||
expect($handler->unserializeValue(null))->toBeNull(); | ||
}); | ||
|
||
/** @test */ | ||
public function it_can_handle_arrays(): void | ||
{ | ||
$handler = new ArrayHandler; | ||
it('can handle arrays', function () { | ||
$handler = new ArrayHandler; | ||
|
||
$this->assertTrue($handler->canHandleValue(['id' => 123])); | ||
} | ||
expect($handler->canHandleValue(['id' => 123]))->toBeTrue(); | ||
}); | ||
|
||
/** @test */ | ||
public function it_cannot_handle_other_values(): void | ||
{ | ||
$handler = new ArrayHandler; | ||
it('cannot handle other values', function () { | ||
$handler = new ArrayHandler; | ||
|
||
$this->assertFalse($handler->canHandleValue((object) ['id' => 123])); | ||
$this->assertFalse($handler->canHandleValue(123)); | ||
$this->assertFalse($handler->canHandleValue(false)); | ||
} | ||
expect($handler->canHandleValue((object) ['id' => 123]))->toBeFalse(); | ||
expect($handler->canHandleValue(123))->toBeFalse(); | ||
expect($handler->canHandleValue(false))->toBeFalse(); | ||
}); | ||
|
||
/** @test */ | ||
public function it_serializes_value(): void | ||
{ | ||
$handler = new ArrayHandler; | ||
it('serializes value', function () { | ||
$handler = new ArrayHandler; | ||
|
||
$this->assertSame( | ||
'{"id":123}', | ||
$handler->serializeValue(['id' => 123]) | ||
); | ||
} | ||
expect($handler->serializeValue(['id' => 123]))->toBe('{"id":123}'); | ||
}); | ||
|
||
/** @test */ | ||
public function it_unserializes_value(): void | ||
{ | ||
$handler = new ArrayHandler; | ||
it('unserializes value', function () { | ||
$handler = new ArrayHandler; | ||
|
||
$value = $handler->unserializeValue('{"id":123}'); | ||
$value = $handler->unserializeValue('{"id":123}'); | ||
|
||
$this->assertIsArray($value); | ||
expect($value)->toBeArray(); | ||
|
||
$this->assertSame(123, $value['id']); | ||
} | ||
} | ||
expect($value['id'])->toBe(123); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,38 @@ | ||
<?php | ||
|
||
namespace Kolossal\Multiplex\Tests; | ||
|
||
use Carbon\Carbon; | ||
use Kolossal\Multiplex\DataType\DateHandler; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
final class DataTypeDateHandlerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_will_parse_to_specified_date_format(): void | ||
{ | ||
$handler = new DateHandler; | ||
|
||
$this->assertSame( | ||
'2022-04-01', | ||
$handler->serializeValue('2022-04-01 14:00 Europe/Berlin') | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_will_unserialize_using_specified_date_format_if_possible(): void | ||
{ | ||
$handler = new DateHandler; | ||
|
||
$this->assertTrue( | ||
$handler->unserializeValue('2022-04-01')->eq(Carbon::create(2022, 4, 1)) | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_will_fallback_to_carbon_parse(): void | ||
{ | ||
$handler = new DateHandler; | ||
|
||
$this->assertTrue( | ||
$handler->unserializeValue('01.04.2022 14:00 Europe/Berlin')->eq(Carbon::create(2022, 3, 31, 22)) | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_handle_handle_date_strings(): void | ||
{ | ||
$handler = new DateHandler; | ||
|
||
$this->assertTrue($handler->canHandleValue('2024-03-29')); | ||
$this->assertTrue($handler->canHandleValue('1970-01-01')); | ||
} | ||
|
||
/** @test */ | ||
public function it_cannot_handle_handle_invalid_values(): void | ||
{ | ||
$handler = new DateHandler; | ||
|
||
$this->assertFalse($handler->canHandleValue(now())); | ||
$this->assertFalse($handler->canHandleValue('2024-3-29')); | ||
$this->assertFalse($handler->canHandleValue('20240329')); | ||
$this->assertFalse($handler->canHandleValue(true)); | ||
} | ||
} | ||
|
||
it('will parse to specified date format', function () { | ||
$handler = new DateHandler; | ||
|
||
expect($handler->serializeValue('2022-04-01 14:00 Europe/Berlin'))->toBe('2022-04-01'); | ||
}); | ||
|
||
it('will unserialize using specified date format if possible', function () { | ||
$handler = new DateHandler; | ||
|
||
expect($handler->unserializeValue('2022-04-01')->eq(Carbon::create(2022, 4, 1)))->toBeTrue(); | ||
}); | ||
|
||
it('will fallback to carbon parse', function () { | ||
$handler = new DateHandler; | ||
|
||
expect($handler->unserializeValue('01.04.2022 14:00 Europe/Berlin')->eq(Carbon::create(2022, 3, 31, 22)))->toBeTrue(); | ||
}); | ||
|
||
it('can handle handle date strings', function () { | ||
$handler = new DateHandler; | ||
|
||
expect($handler->canHandleValue('2024-03-29'))->toBeTrue(); | ||
expect($handler->canHandleValue('1970-01-01'))->toBeTrue(); | ||
}); | ||
|
||
it('cannot handle handle invalid values', function () { | ||
$handler = new DateHandler; | ||
|
||
expect($handler->canHandleValue(now()))->toBeFalse(); | ||
expect($handler->canHandleValue('2024-3-29'))->toBeFalse(); | ||
expect($handler->canHandleValue('20240329'))->toBeFalse(); | ||
expect($handler->canHandleValue(true))->toBeFalse(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,22 @@ | ||
<?php | ||
|
||
namespace Kolossal\Multiplex\Tests; | ||
|
||
use Carbon\Carbon; | ||
use Kolossal\Multiplex\DataType\DateTimeHandler; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
final class DataTypeDateTimeHandlerTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_will_parse_to_specified_datetime_format(): void | ||
{ | ||
$handler = new DateTimeHandler; | ||
it('will parse to specified datetime format', function () { | ||
$handler = new DateTimeHandler; | ||
|
||
$this->assertSame( | ||
'2022-04-01 14:00:00.000000+0200', | ||
$handler->serializeValue('2022-04-01 14:00 Europe/Berlin') | ||
); | ||
} | ||
expect($handler->serializeValue('2022-04-01 14:00 Europe/Berlin'))->toBe('2022-04-01 14:00:00.000000+0200'); | ||
}); | ||
|
||
/** @test */ | ||
public function it_will_unserialize_using_specified_datetime_format_if_possible(): void | ||
{ | ||
$handler = new DateTimeHandler; | ||
it('will unserialize using specified datetime format if possible', function () { | ||
$handler = new DateTimeHandler; | ||
|
||
$this->assertTrue( | ||
$handler->unserializeValue('2022-04-01 14:00:00.000000+0200')->eq(Carbon::create(2022, 4, 1, 12)) | ||
); | ||
} | ||
expect($handler->unserializeValue('2022-04-01 14:00:00.000000+0200')->eq(Carbon::create(2022, 4, 1, 12)))->toBeTrue(); | ||
}); | ||
|
||
/** @test */ | ||
public function it_will_fallback_to_carbon_parse(): void | ||
{ | ||
$handler = new DateTimeHandler; | ||
it('will fallback to carbon parse', function () { | ||
$handler = new DateTimeHandler; | ||
|
||
$this->assertTrue( | ||
$handler->unserializeValue('01.04.2022 14:00 Europe/Berlin')->eq(Carbon::create(2022, 4, 1, 12)) | ||
); | ||
} | ||
} | ||
expect($handler->unserializeValue('01.04.2022 14:00 Europe/Berlin')->eq(Carbon::create(2022, 4, 1, 12)))->toBeTrue(); | ||
}); |
Oops, something went wrong.