BaseTestCase::useMySqlConnection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 16
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 19
rs 9.7333
1
<?php
2
3
namespace EDouna\LaravelDBBackup\Test;
4
5
use EDouna\LaravelDBBackup\LaravelDBBackupProvider;
6
use Orchestra\Testbench\TestCase;
7
use ReflectionClass;
8
use ReflectionException;
9
10
class BaseTestCase extends TestCase
11
{
12
    public function setUp(): void
13
    {
14
        parent::setUp(); // TODO: Change the autogenerated stub
15
    }
16
17
    public function getPackageProviders($app)
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

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

17
    public function getPackageProviders(/** @scrutinizer ignore-unused */ $app)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
18
    {
19
        return [
20
            LaravelDBBackupProvider::class,
21
        ];
22
    }
23
24
    public function getEnvironmentSetUp($app)
25
    {
26
        parent::getEnvironmentSetUp($app); // TODO: Change the autogenerated stub
27
    }
28
29
    /**
30
     * @param $object
31
     * @param $property
32
     * @param $value
33
     *
34
     * @throws ReflectionException
35
     */
36
    public function setProtectedProperty($object, $property, $value): void
37
    {
38
        try {
39
            $reflection = new ReflectionClass($object);
40
        } catch (ReflectionException $e) {
41
            throw new ReflectionException('Failed setting Protected property. Exception thrown: '.$e->getMessage());
42
        }
43
44
        $reflection_property = $reflection->getProperty($property);
45
        $reflection_property->setAccessible(true);
46
        $reflection_property->setValue($object, $value);
47
    }
48
49
    /**
50
     * @param $object
51
     * @param $property
52
     *
53
     * @throws ReflectionException
54
     */
55
    public function getProtectedProperty($object, $property): void
56
    {
57
        try {
58
            $reflection = new ReflectionClass($object);
59
        } catch (ReflectionException $e) {
60
            throw new ReflectionException('Failed getting Protected property. Exception thrown: '.$e->getMessage());
61
        }
62
63
        $reflection_property = $reflection->getProperty($property);
64
        $reflection_property->setAccessible(true);
65
        $reflection_property->getValue($object);
66
    }
67
68
    protected function useMySqlConnection($app)
69
    {
70
        $app->config->set('database.default', 'mysql');
71
72
        $app->config->set('database.connections.mysql', [
73
            'driver'         => 'mysql',
74
            'url'            => env('DATABASE_URL'),
75
            'host'           => env('DB_HOST', '127.0.0.1'),
76
            'port'           => env('DB_PORT', '3306'),
77
            'database'       => env('DB_DATABASE', 'forge'),
78
            'username'       => env('DB_USERNAME', 'forge'),
79
            'password'       => env('DB_PASSWORD', ''),
80
            'unix_socket'    => env('DB_SOCKET', ''),
81
            'charset'        => 'utf8mb4',
82
            'collation'      => 'utf8mb4_unicode_ci',
83
            'prefix'         => '',
84
            'prefix_indexes' => true,
85
            'strict'         => true,
86
            'engine'         => null,
87
        ]);
88
    }
89
90
    protected function useSqliteConnection($app)
91
    {
92
        $app->config->set('database.default', 'sqlite');
93
    }
94
95
    protected function useStoragePath($app)
96
    {
97
        $app->config->set('db-backup.backup_folder', storage_path('db-backups'));
98
    }
99
}
100