ImportExportLogTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 58
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getEnvironmentSetUp() 0 3 1
A setUp() 0 11 1
A get_saved_logs() 0 13 1
A getPackageProviders() 0 3 1
A save_new_log() 0 7 1
1
<?php
2
3
namespace Tests;
4
5
use Orchestra\Testbench\TestCase;
6
use LWS\ImportExport\Models\Import;
7
use Illuminate\Foundation\Testing\RefreshDatabase;
8
use LWS\ImportExport\Facades\ImportExportLog;
9
use LWS\ImportExport\Models\ImportExportLog as ModelImportExportLog;
10
11
class ImportExportLogTest extends TestCase
12
{
13
    use RefreshDatabase;
0 ignored issues
show
introduced by
The trait Illuminate\Foundation\Testing\RefreshDatabase requires some properties which are not provided by Tests\ImportExportLogTest: $connectionsToTransact, $dropViews, $dropTypes
Loading history...
14
15
    protected $import;
16
17
    protected 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
    protected 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 ['LWS\ImportExport\ImportExportServiceProvider'];
20
    }
21
22
    protected function getEnvironmentSetUp($app)
23
    {
24
        $app['config']->set('database.default', 'testing');
25
    }
26
27
    protected function setUp():void
28
    {
29
        parent::setUp();
30
31
        $this->artisan('migrate', ['--database' => 'testing']);
32
33
        $this->import = Import::create([
34
            'file' => 'imports/import-1530262997.csv',
35
            'file_rows' => 104,
36
            'db_cols' => ['name', 'email', 'password'],
37
            'model_map' => ['email', 'name', 'password'],
38
        ]);
39
    }
40
41
    /**
42
     * @test
43
     */
44
    public function save_new_log()
45
    {
46
        $import = $this->import;
47
48
        $result = ImportExportLog::logImportError($import, ['data' => 'this is test data'], 'This is not expected');
0 ignored issues
show
Bug introduced by
The method logImportError() does not exist on LWS\ImportExport\Facades\ImportExportLog. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

48
        /** @scrutinizer ignore-call */ 
49
        $result = ImportExportLog::logImportError($import, ['data' => 'this is test data'], 'This is not expected');
Loading history...
49
50
        $this->assertInstanceOf(ModelImportExportLog::class, $result);
51
    }
52
53
    /**
54
     * @test
55
     */
56
    public function get_saved_logs()
57
    {
58
        $import = $this->import;
59
60
        $log = ImportExportLog::logImportError($import, ['data' => 'this is test data'], 'This is not expected');
61
62
        $log_in_db = ImportExportLog::getLogs($log->id);
0 ignored issues
show
Bug introduced by
The method getLogs() does not exist on LWS\ImportExport\Facades\ImportExportLog. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

62
        /** @scrutinizer ignore-call */ 
63
        $log_in_db = ImportExportLog::getLogs($log->id);
Loading history...
63
64
        $this->assertInternalType('array', $log_in_db);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

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

64
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType('array', $log_in_db);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
65
66
        $this->assertArrayHasKey('data', $log_in_db[0]);
67
68
        $this->assertArrayHasKey('message', $log_in_db[0]);
69
    }
70
}
71