|
1 | 1 | <?php |
2 | 2 |
|
3 | | -it('can test', function () { |
4 | | - expect(true)->toBeTrue(); |
5 | | -}); |
| 3 | +use Coderflex\LaravelPresenter\Tests\Models\Post; |
| 4 | +use Coderflex\LaravelPresenter\Tests\Models\User; |
| 5 | + |
| 6 | +it('cannot create new eloquent model presenter', function () { |
| 7 | + $this->artisan('presenter:make ') |
| 8 | + ->assertExitCode(1); |
| 9 | +})->throws( |
| 10 | + Symfony\Component\Console\Exception\RuntimeException::class, |
| 11 | + 'Not enough arguments (missing: "name").' |
| 12 | +)->group('Presenter Command'); |
| 13 | + |
| 14 | +it('can create new eloquent model presenter', function () { |
| 15 | + $this->artisan('presenter:make UserPresenter') |
| 16 | + ->assertExitCode(0); |
| 17 | +})->group('Presenter Command'); |
| 18 | + |
| 19 | +it('presents user full name', function () { |
| 20 | + $user = new User([ |
| 21 | + 'first_name' => 'John', |
| 22 | + 'last_name' => 'Doe', |
| 23 | + 'email' => 'john@example.com', |
| 24 | + 'password' => '123' |
| 25 | + ]); |
| 26 | + |
| 27 | + expect($user->present()->fullName) |
| 28 | + ->toEqual('John Doe'); |
| 29 | +})->group('Presenter Implementation'); |
| 30 | + |
| 31 | +it('should implements CanPresent Interface', function () { |
| 32 | + $post = new Post([ |
| 33 | + 'title' => 'a title for a post' |
| 34 | + ]); |
| 35 | + |
| 36 | + $post->present()->slug; |
| 37 | +})->throws( |
| 38 | + Coderflex\LaravelPresenter\Exceptions\PresenterException::class, |
| 39 | + 'Coderflex\LaravelPresenter\Tests\Models\Post should implements \Coderflex\LaravelPresenter\Concerns\CanPresent interface' |
| 40 | +)->group('Presenter Implementation'); |
| 41 | + |
| 42 | + |
0 commit comments