generated from cjmellor/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from Simoneu01/main
Allow model customisation
- Loading branch information
Showing
12 changed files
with
95 additions
and
26 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
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
namespace LevelUp\Experience\Tests\Fixtures; | ||
|
||
class Level extends \LevelUp\Experience\Models\Level | ||
{ | ||
public function extra_function(): string | ||
{ | ||
return 'extra_function'; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
use LevelUp\Experience\Exceptions\LevelExistsException; | ||
|
||
uses()->group('levels'); | ||
|
||
beforeEach(function (): void { | ||
config()->set('level-up.models.level', \LevelUp\Experience\Tests\Fixtures\Level::class); | ||
}); | ||
|
||
it(description: 'is a custom model', closure: function (): void { | ||
$levelClass = config('level-up.models.level'); | ||
|
||
$level = $levelClass::add([ | ||
'level' => 6, | ||
'next_level_experience' => 750, | ||
]); | ||
|
||
expect(value: $level[0])->toBeInstanceOf($levelClass); | ||
expect(value: $level[0]->extra_function())->toBe(expected: 'extra_function'); | ||
}); | ||
|
||
it(description: 'can create a level with custom model', closure: function (): void { | ||
|
||
$level = config('level-up.models.level')::add([ | ||
'level' => 6, | ||
'next_level_experience' => 750, | ||
]); | ||
|
||
expect(value: $level[0]->level)->toBe(expected: 6); | ||
|
||
$this->assertDatabaseHas(table: 'levels', data: [ | ||
'level' => 6, | ||
'next_level_experience' => 750, | ||
]); | ||
}); | ||
|
||
it(description: 'throws an error if a level exists with custom model', closure: function (): void { | ||
config('level-up.models.level')::add(level: 1, pointsToNextLevel: 100); | ||
config('level-up.models.level')::add(level: 1, pointsToNextLevel: 100); | ||
})->throws(exception: LevelExistsException::class, exceptionMessage: 'The level with number "1" already exists'); |
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