Skip to content

Commit

Permalink
patch
Browse files Browse the repository at this point in the history
  • Loading branch information
AnourValar committed Jan 29, 2024
1 parent 138e736 commit 73a5a76
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public static function from(array|object $data): static
}

$args[] = $value;
unset($data[$rule['name']]);
}

if ($data && ! \App::isProduction()) {
throw new \RuntimeException('Unused attributes: ' . implode(', ', array_keys($data)));
}

return new static(...$args);
Expand Down
10 changes: 9 additions & 1 deletion tests/MapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use AnourValar\LaravelAtom\Tests\Mappers\ArrayOfMapper;
use AnourValar\LaravelAtom\Tests\Mappers\ExcludeMapper;

class MapperTest extends \PHPUnit\Framework\TestCase
class MapperTest extends \Orchestra\Testbench\TestCase
{
/**
* @return void
Expand Down Expand Up @@ -67,6 +67,14 @@ public function test_simple()
],
(new SimpleMapper(1, '2', '3', '4'))->toArray()
);

$this->expectException(\RuntimeException::class);
try {
SimpleMapper::from(['a' => 1, 'b' => '2', 'eee' => '3']);
} catch (\RuntimeException $e) {
$this->assertStringContainsString('eee', $e->getMessage());
throw $e;
}
}

/**
Expand Down

0 comments on commit 73a5a76

Please sign in to comment.