TestCase   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 95.45%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 18
c 1
b 0
f 0
dl 0
loc 54
rs 10
ccs 21
cts 22
cp 0.9545

3 Methods

Rating   Name   Duplication   Size   Complexity  
A assertCommandNotCalled() 0 7 1
A assertCommandCalled() 0 7 1
A setUp() 0 19 4
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Testing;
15
16
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
17
use Illuminate\Support\Facades\Facade;
18
use LaravelZero\Framework\Providers\CommandRecorder\CommandRecorderRepository;
19
use NunoMaduro\Collision\ArgumentFormatter;
20
21
abstract class TestCase extends BaseTestCase
22
{
23
    /**
24
     * Setup the test environment.
25
     */
26 39
    protected function setUp(): void
27
    {
28 39
        if (! $this->app) {
29 39
            $this->refreshApplication();
30
        }
31
32 39
        $this->setUpTraits();
33
34 39
        foreach ($this->afterApplicationCreatedCallbacks as $callback) {
35
            call_user_func($callback);
36
        }
37
38 39
        Facade::clearResolvedInstances();
39
40 39
        if (class_exists(\Illuminate\Database\Eloquent\Model::class)) {
41 39
            \Illuminate\Database\Eloquent\Model::setEventDispatcher($this->app['events']);
42
        }
43
44 39
        $this->setUpHasRun = true;
45 39
    }
46
47
    /**
48
     * Assert that a command was called using the given arguments.
49
     *
50
     * @param string $command
51
     * @param array $arguments
52
     */
53 2
    protected function assertCommandCalled(string $command, array $arguments = []): void
54
    {
55 2
        $argumentsAsString = (new ArgumentFormatter)->format($arguments);
56 2
        $recorder = app(CommandRecorderRepository::class);
57
58 2
        static::assertTrue($recorder->exists($command, $arguments),
59 2
            'Failed asserting that \''.$command.'\' was called with the given arguments: '.$argumentsAsString);
60 2
    }
61
62
    /**
63
     * Assert that a command was not called using the given arguments.
64
     *
65
     * @param string $command
66
     * @param array $arguments
67
     */
68 2
    protected function assertCommandNotCalled(string $command, array $arguments = []): void
69
    {
70 2
        $argumentsAsString = (new ArgumentFormatter)->format($arguments);
71 2
        $recorder = app(CommandRecorderRepository::class);
72
73 2
        static::assertFalse($recorder->exists($command, $arguments),
74 2
            'Failed asserting that \''.$command.'\' was not called with the given arguments: '.$argumentsAsString);
75 2
    }
76
}
77