Completed
Branch master (beb88f)
by Mohamed
05:11 queued 03:39
created

CreateCategoryTest::testCreateCategory()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
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\CreateCategory;
16
use Moo\FlashCard\Entity\Category;
17
use Moo\FlashCard\Tests\BaseTestCase;
18
19
/**
20
 * CreateCategoryTest contains test cases for the command line CreateCategory class.
21
 *
22
 * @author Mohamed Alsharaf <[email protected]>
23
 */
24
class CreateCategoryTest extends BaseTestCase
25
{
26
    public function testCreateCategory()
27
    {
28
        // Test creating category.
29
        $categoryTile = 'Test Category 1';
30
31
        // Mock the ask method
32
        $command = Mockery::mock(CreateCategory::class . '[ask]');
33
        $command->shouldReceive('ask')
34
            ->times(3)
35
            ->andReturn($categoryTile);
36
37
        // Register the command
38
        $this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($command);
39
40
        // Call the command
41
        $this->artisan('flashcard:category', [
42
            '--active' => true,
43
            '--no-interaction' => true,
44
        ]);
45
46
        // Query the created category
47
        $category = Category::where('title', $categoryTile)->first();
48
49
        // Check category values as expected
50
        $this->assertEquals($categoryTile, $category->title);
51
        $this->assertTrue((bool)$category->active);
52
    }
53
54
    public function testCreateSubCategoryInteractive()
55
    {
56
        $this->category();
57
        $category = $this->category([
58
            'title' => 'Category 2',
59
        ]);
60
61
        // Test creating category.
62
        $title = 'Child Category 1';
63
        $content = 'Content';
64
        $color = 'red';
65
66
        // Mock the ask & choice method
67
        $ask = Mockery::mock(CreateCategory::class . '[ask, choice]');
68
        $ask->shouldReceive('ask')
69
            ->times(3)
70
            ->andReturn($title, $content, $color)
71
            ->shouldReceive('choice')
72
            ->once()
73
            ->andReturn($category->title);
74
75
        // Register the command
76
        $this->app['Illuminate\Contracts\Console\Kernel']->registerCommand($ask);
77
78
        // Call the command
79
        $this->artisan('flashcard:category', [
80
            '--active' => true,
81
            '--no-interaction' => true,
82
        ]);
83
84
        // Query the created category
85
        $childCategory = Category::where('title', $title)->first();
86
87
        // Check category values as expected
88
        $this->assertEquals($title, $childCategory->title);
89
        $this->assertEquals($category->id, $childCategory->parent);
90
        $this->assertTrue((bool)$childCategory->active);
91
    }
92
}
93