Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 708d047

Browse files
Add test for callArtisan method
1 parent e669ca5 commit 708d047

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

‎app/Console/Commands/CreateUser.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php namespace App\Console\Commands;
2+
3+
use App\User;
4+
use Illuminate\Console\Command;
5+
use Symfony\Component\Console\Input\InputArgument;
6+
7+
class CreateUser extends Command
8+
{
9+
10+
/**
11+
* The console command name.
12+
*
13+
* @var string
14+
*/
15+
protected $name = 'create-user';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Create a user';
23+
24+
/**
25+
* @return array
26+
*/
27+
protected function getArguments()
28+
{
29+
return [
30+
['email', InputArgument::REQUIRED],
31+
['password', InputArgument::REQUIRED]
32+
];
33+
}
34+
35+
/**
36+
* Execute the console command.
37+
*
38+
* @return mixed
39+
*/
40+
public function handle()
41+
{
42+
$user = new User();
43+
$user->email = $this->argument('email');
44+
$user->password = $this->argument('password');
45+
$user->save();
46+
47+
$this->line('User created!');
48+
}
49+
}

‎app/Console/Kernel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class Kernel extends ConsoleKernel {
1111
* @var array
1212
*/
1313
protected $commands = [
14-
'App\Console\Commands\Inspire'
14+
'App\Console\Commands\Inspire',
15+
'App\Console\Commands\CreateUser'
1516
];
1617

1718
/**

‎tests/functional/ArtisanCest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
class ArtisanCest
4+
{
5+
6+
public function testArtisan(FunctionalTester $I)
7+
{
8+
$output = $I->callArtisan('create-user', ['email' => 'test@example.com', 'password' => 'password']);
9+
10+
$I->seeRecord('users', ['email' => 'test@example.com']);
11+
$I->assertEquals('User created!', $output);
12+
}
13+
14+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /