-
Notifications
You must be signed in to change notification settings - Fork 42
/
SeedCommandTest.php
67 lines (56 loc) · 2.25 KB
/
SeedCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/*
* This file is part of the WouterJEloquentBundle package.
*
* (c) 2014 Wouter de Jong
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace WouterJ\EloquentBundle\Command;
use Illuminate\Console\View\Components;
use Illuminate\Database\DatabaseManager;
use WouterJ\EloquentBundle\MockeryTrait;
use WouterJ\EloquentBundle\Seeder;
use WouterJ\EloquentBundle\Promise;
use Symfony\Component\DependencyInjection\ContainerInterface;
use PHPUnit\Framework\TestCase;
/**
* @author Wouter J <wouter@wouterj.nl>
*/
class SeedCommandTest extends TestCase
{
use MockeryTrait;
protected $container;
protected $command;
protected $manager;
public function setUp(): void
{
$this->container = \Mockery::mock(ContainerInterface::class);
$this->manager = \Mockery::mock(DatabaseManager::class);
$this->manager->allows()->setDefaultConnection()->withAnyArgs();
$this->command = new SeedCommand($this->container, $this->manager, [], 'dev');
}
/** @test */
public function it_executes_specified_classes()
{
$seederClass = __CLASS__.'_DummySeeder';
$seeder1Class = __CLASS__.'_SecondDummySeeder';
Promise::containerDoesNotHaveService($this->container, $seederClass);
Promise::containerDoesNotHaveService($this->container, $seeder1Class);
$test = TestCommand::create($this->command)
->passing('--database')
->passing('class', [$seederClass, $seeder1Class])
->duringExecute()
;
if (class_exists(Components\Task::class)) {
$test->outputsRegex('/'.preg_quote($seederClass).'[\s\.]* [\d\.]+ms DONE\s+'.preg_quote($seeder1Class).'[\s\.]* [\d\.]+ms DONE/');
} else {
// BC Laravel <9.39
$test->outputsRegex('/RUNNING: '.preg_quote($seederClass).'\s+DONE: '.preg_quote($seederClass).' \(\d+ms\)/');
$test->outputsRegex('/RUNNING: '.preg_quote($seeder1Class).'\s+DONE: '.preg_quote($seeder1Class).' \(\d+ms\)/');
}
}
}
class SeedCommandTest_DummySeeder extends Seeder { public function run() { } }
class SeedCommandTest_SecondDummySeeder extends Seeder { public function run() { } }