CreateCardTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 3
dl 0
loc 37
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testCreateCard() 0 34 1
1
<?php
2
3
/*
4
 * This file is part of the Moo\FlashCard package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Moo\FlashCard\Tests\Command;
13
14
use Mockery;
15
use Moo\FlashCard\Command\CreateCard;
16
use Moo\FlashCard\Entity\Card;
17
use Moo\FlashCard\Tests\BaseTestCase;
18
19
/**
20
 * CreateCardTest contains test cases for the command line CreateCard class.
21
 *
22
 * @author Mohamed Alsharaf <[email protected]>
23
 */
24
class CreateCardTest extends BaseTestCase
25
{
26
    public function testCreateCard()
27
    {
28
        // Test creating card.
29
        $title    = 'Test Card 1';
30
        $slug     = 'test-card-1';
31
        $category = $this->category();
32
33
        // Mock the ask & choice method
34
        $command = Mockery::mock(CreateCard::class . '[ask, choice]');
35
        $command->shouldReceive('ask')
36
            ->times(3)
37
            ->andReturn($title, $title, $title)
38
            ->shouldReceive('choice')
39
            ->once()
40
            ->andReturn($category->title);
41
42
        // Register the command
43
        $this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($command);
44
45
        // Call the command
46
        $this->artisan('flashcard:card', [
47
            '--active'         => true,
48
            '--no-interaction' => true,
49
        ]);
50
51
        // Query the created card
52
        $card = Card::where('slug', $slug)->first();
53
54
        // Check card values as expected
55
        $this->assertEquals($title, $card->title);
56
        $this->assertEquals($category->id, $card->category_id);
57
        $this->assertEquals($slug, $card->slug);
58
        $this->assertTrue((bool) $card->active);
59
    }
60
}
61