Skip to content

Commit 6adf233

Browse files
Make artisan commands callable from tests
1 parent d4995a3 commit 6adf233

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
},
2525
"require-dev": {
2626
"phpunit/phpunit" : "^5.0||^6.0||^7.0",
27-
"orchestra/testbench": "~3.0"
27+
"orchestra/testbench": "~3.0",
28+
"mockery/mockery": "~0.9||~1.0"
2829
},
2930
"autoload": {
3031
"psr-4": {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: alex
5+
* Date: 18/03/19
6+
* Time: 5:31 AM
7+
*/
8+
9+
namespace CrestApps\CodeGenerator\Tests;
10+
11+
use Illuminate\Support\Facades\Artisan;
12+
use Illuminate\Support\Facades\File;
13+
14+
class ResourceFileCreateCommandTest extends TestCase
15+
{
16+
public function testCreateResourceFileWithBigIntField()
17+
{
18+
//first, mock out the file system so we don't accidentally scribble on something
19+
File::shouldReceive('exists')->andReturnNull();
20+
File::shouldReceive('put')->andReturnNull();
21+
File::shouldReceive('isDirectory')->andReturn(false);
22+
File::shouldReceive('makeDirectory')->andReturnNull();
23+
24+
// arguments we're passing in
25+
$fieldString = 'name:foo_count;data-type:bigint';
26+
27+
// now call Artisan
28+
Artisan::call('resource-file:create', ['model-name' => 'TestModel', '--fields' => $fieldString]);
29+
// Vacuous assertion to give PHPUnit something to do instead of complaining about a risky test
30+
$this->assertTrue(true);
31+
}
32+
33+
public function testCreateResourceFileWithBigIntegerField()
34+
{
35+
//first, mock out the file system so we don't accidentally scribble on something
36+
File::shouldReceive('exists')->andReturnNull();
37+
File::shouldReceive('put')->andReturnNull();
38+
File::shouldReceive('isDirectory')->andReturn(false);
39+
File::shouldReceive('makeDirectory')->andReturnNull();
40+
41+
// arguments we're passing in
42+
$fieldString = 'name:foo_count;data-type:biginteger';
43+
44+
// now call Artisan
45+
Artisan::call('resource-file:create', ['model-name' => 'TestModel', '--fields' => $fieldString]);
46+
// Vacuous assertion to give PHPUnit something to do instead of complaining about a risky test
47+
$this->assertTrue(true);
48+
}
49+
}

tests/TestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212

1313
class TestCase extends BaseTestCase
1414
{
15-
15+
protected function getPackageProviders($app)
16+
{
17+
return ['CrestApps\CodeGenerator\CodeGeneratorServiceProvider'];
18+
}
1619
}

0 commit comments

Comments
 (0)