Completed
Push — master ( dab270...a45a25 )
by Abhishek Kumar
08:02
created

ImportExportLogTest::get_saved_logs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Tests;
4
5
use Orchestra\Testbench\TestCase;
6
use Ladybirdweb\ImportExport\Models\Import;
7
use Illuminate\Foundation\Testing\RefreshDatabase;
8
use Ladybirdweb\ImportExport\Facades\ImportExportLog;
9
use Ladybirdweb\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
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 ['Ladybirdweb\ImportExport\ImportExportServiceProvider'];
20
    }
21
22
    protected function getEnvironmentSetUp($app)
23
    {
24
        $app['config']->set('database.default', 'testing');
25
    }
26
27
    protected function setUp()
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 Ladybirdweb\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 Ladybirdweb\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);
65
66
        $this->assertArrayHasKey('data', $log_in_db[0]);
67
68
        $this->assertArrayHasKey('message', $log_in_db[0]);
69
    }
70
}
71