Skip to content

Commit 77f50f2

Browse files
committed
test: adds fromModel exception test
1 parent b838c79 commit 77f50f2

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

tests/_support/Helper/MockModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class MockModel extends Model {
1111
'lastName' => 'string',
1212
'emails' => [ 'array', [] ],
1313
'microseconds' => 'float',
14-
'number' => 'number',
14+
'number' => 'int',
15+
'date' => \DateTime::class,
1516
];
1617
}

tests/wpunit/ModelTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,8 @@ public function testShouldSetMultipleAttributes() {
275275

276276
/**
277277
* @since 1.0.0
278-
*
279-
* @return void
280278
*/
281-
public function testIsSet() {
279+
public function testIsSet(): void {
282280
$model = new MockModel();
283281

284282
// This has a default so we should see as set.
@@ -292,7 +290,10 @@ public function testIsSet() {
292290
$this->assertTrue( $model->isSet( 'lastName' ) );
293291
}
294292

295-
public function testFromData() {
293+
/**
294+
* @since 2.0.0
295+
*/
296+
public function testFromDataShouldCreateInstanceWithCorrectTypes(): void {
296297
$model = MockModel::fromData( [
297298
'id' => '1',
298299
'firstName' => 'Bill',
@@ -310,6 +311,17 @@ public function testFromData() {
310311
$this->assertEquals( 1234567890, $model->number );
311312
}
312313

314+
/**
315+
* @since 2.0.0
316+
*/
317+
public function testFromDataShouldThrowExceptionForNonPrimitiveTypes(): void {
318+
$this->expectException( Config::getInvalidArgumentException() );
319+
320+
MockModel::fromData( [
321+
'date' => '123',
322+
] );
323+
}
324+
313325
/**
314326
* @since 1.0.0
315327
*

0 commit comments

Comments
 (0)