Issues (11)

tests/QuickDatabaseMigrationsTest.php (5 issues)

1
<?php
2
3
namespace Mnabialek\LaravelQuickMigrations\Tests;
4
5
use ArrayAccess;
6
use Illuminate\Container\Container;
7
use Illuminate\Contracts\Console\Kernel;
8
use Illuminate\Foundation\Testing\RefreshDatabaseState;
9
use Illuminate\Foundation\Testing\TestCase;
10
use Mnabialek\LaravelQuickMigrations\QuickDatabaseMigrations;
11
use Mockery;
12
use stdClass;
13
14
class QuickDatabaseMigrationsTest extends UnitTestCase
15
{
16
    /** @test */
17
    public function it_runs_default_method_when_turned_off()
18
    {
19
        $app = Mockery::mock(Container::class, ArrayAccess::class);
20
21
        $config = Mockery::mock(stdClass::class);
22
23
        $app->shouldReceive('make')->once()->with('config', [])->andReturn($config);
24
25
        $config->shouldReceive('get')->once()->with('quick_migrations.enabled', null)->andReturn(false);
26
27
        Container::setInstance($app);
0 ignored issues
show
$app of type Mockery\LegacyMockInterface|Mockery\MockInterface is incompatible with the type Illuminate\Contracts\Container\Container|null expected by parameter $container of Illuminate\Container\Container::setInstance(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

27
        Container::setInstance(/** @scrutinizer ignore-type */ $app);
Loading history...
28
29
        $class = Mockery::mock(TestClass::class)->makePartial()->shouldAllowMockingProtectedMethods();
30
31
        $class->shouldReceive('useDefaultWay')->once()->withNoArgs();
32
        $class->shouldNotReceive('artisan');
33
        $class->shouldNotReceive('beforeApplicationDestroyed');
34
35
        $class->runDatabaseMigrations();
0 ignored issues
show
The method runDatabaseMigrations() does not exist on Mockery\LegacyMockInterface. It seems like you code against a sub-type of Mockery\LegacyMockInterface such as Mockery\Mock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        $class->/** @scrutinizer ignore-call */ 
36
                runDatabaseMigrations();
Loading history...
36
        $this->assertTrue(true);
37
    }
38
39
    /** @test */
40
    public function it_runs_custom_code_when_turned_on()
41
    {
42
        $app = Mockery::mock(Container::class, ArrayAccess::class);
43
44
        $config = Mockery::mock(stdClass::class);
45
46
        $app->shouldReceive('make')->once()->with('config', [])->andReturn($config);
47
48
        $config->shouldReceive('get')->once()->with('quick_migrations.enabled', null)->andReturn(true);
49
50
        Container::setInstance($app);
0 ignored issues
show
$app of type Mockery\LegacyMockInterface|Mockery\MockInterface is incompatible with the type Illuminate\Contracts\Container\Container|null expected by parameter $container of Illuminate\Container\Container::setInstance(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

50
        Container::setInstance(/** @scrutinizer ignore-type */ $app);
Loading history...
51
52
        $class = Mockery::mock(TestClass::class)->makePartial()->shouldAllowMockingProtectedMethods();
53
        $class->setApp($app);
0 ignored issues
show
The method setApp() does not exist on Mockery\LegacyMockInterface. It seems like you code against a sub-type of Mockery\LegacyMockInterface such as Mockery\Mock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        $class->/** @scrutinizer ignore-call */ 
54
                setApp($app);
Loading history...
54
55
        $class->shouldNotReceive('useDefaultWay');
56
57
        $class->shouldReceive('artisan')->once()->with('migrate:fresh', [
58
            '--path' => realpath(__DIR__ . '/../migrations'),
59
            '--realpath' => 1,
60
        ]);
61
62
        $kernel = Mockery::mock(stdClass::class);
63
64
        $app->shouldReceive('offsetGet')->once()->with(Kernel::class)->andReturn($kernel);
65
66
        $kernel->shouldReceive('setArtisan')->once()->with(null);
67
68
        // set some state
69
        RefreshDatabaseState::$migrated = true;
70
        $this->assertSame(true, RefreshDatabaseState::$migrated);
71
72
        $class->shouldReceive('beforeApplicationDestroyed')->once()->passthru();
73
74
        $class->runDatabaseMigrations();
75
76
        $callbacks = $class->getCallbacks();
0 ignored issues
show
The method getCallbacks() does not exist on Mockery\LegacyMockInterface. It seems like you code against a sub-type of Mockery\LegacyMockInterface such as Mockery\Mock. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

76
        /** @scrutinizer ignore-call */ 
77
        $callbacks = $class->getCallbacks();
Loading history...
77
        $this->assertCount(1, $callbacks);
78
79
        // execute callback
80
        $callbacks[0]();
81
82
        // make sure state was changed
83
        $this->assertSame(false, RefreshDatabaseState::$migrated);
84
    }
85
}
86
87
class TestClass extends TestCase
88
{
89
    use QuickDatabaseMigrations;
90
91
    public function setApp($app)
92
    {
93
        $this->app = $app;
94
    }
95
96
    public function createApplication()
97
    {
98
    }
99
100
    public function getCallbacks()
101
    {
102
        return $this->beforeApplicationDestroyedCallbacks;
103
    }
104
}
105