|
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 Moo\FlashCard\Command\CreateCard; |
|
15
|
|
|
use Moo\FlashCard\Entity\Card; |
|
16
|
|
|
use Moo\FlashCard\Tests\BaseTestCase; |
|
17
|
|
|
use Mockery; |
|
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
|
|
|
|