ImportTest::remove_import()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Tests;
4
5
use Illuminate\Http\File;
6
use Orchestra\Testbench\TestCase;
7
use Illuminate\Support\Facades\Queue;
8
use Illuminate\Support\Facades\Route;
9
use Illuminate\Support\Facades\Storage;
10
use LWS\ImportExport\Facades\Import;
11
use Illuminate\Foundation\Testing\RefreshDatabase;
12
use LWS\ImportExport\Models\Import as ModelImport;
13
14
class ImportTest extends TestCase
15
{
16
    use RefreshDatabase;
0 ignored issues
show
introduced by
The trait Illuminate\Foundation\Testing\RefreshDatabase requires some properties which are not provided by Tests\ImportTest: $connectionsToTransact, $dropViews, $dropTypes
Loading history...
17
18
    protected $import;
19
20
    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

20
    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...
21
    {
22
        return ['LWS\ImportExport\ImportExportServiceProvider'];
23
    }
24
25
    protected function getEnvironmentSetUp($app)
26
    {
27
        $app['config']->set('database.default', 'testing');
28
    }
29
30
    protected function setUp():void
31
    {
32
        parent::setUp();
33
34
        $this->artisan('migrate', ['--database' => 'testing']);
35
36
        Route::middleware('web')->group(function () {
37
            Route::get('/import/{id}/progress', ['as' => 'ladybirdweb.import.ajax.progress', 'uses' => 'LWS\ImportExport\Import@returnImportProgress']);
38
        });
39
40
        Storage::putFileAs('imports', new File(__DIR__.'/storage/test/test.csv'), 'test.csv');
41
42
        $this->import = ModelImport::create([
43
            'file' => 'imports/test.csv',
44
            'file_rows' => 104,
45
            'db_cols' => ['name', 'email', 'password'],
46
            'model_map' => ['email', 'name', 'password'],
47
        ]);
48
    }
49
50
    /**
51
     * @test
52
     */
53
    public function create_new_import_success()
54
    {
55
        $import = Import::createImport('imports/test.csv', ['name', 'email', 'password']);
0 ignored issues
show
Bug introduced by
The method createImport() does not exist on LWS\ImportExport\Facades\Import. 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

55
        /** @scrutinizer ignore-call */ 
56
        $import = Import::createImport('imports/test.csv', ['name', 'email', 'password']);
Loading history...
56
57
        $this->assertInstanceOf(ModelImport::class, $import);
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function fetch_import()
64
    {
65
        $import = Import::getImport($this->import->id);
0 ignored issues
show
Bug introduced by
The method getImport() does not exist on LWS\ImportExport\Facades\Import. 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

65
        /** @scrutinizer ignore-call */ 
66
        $import = Import::getImport($this->import->id);
Loading history...
66
67
        $this->assertInstanceOf(ModelImport::class, $import);
68
    }
69
70
    /**
71
     * @test
72
     */
73
    public function get_few_rows_from_uploaded_file()
74
    {
75
        $csv_data = Import::getImportFileData($this->import->id);
0 ignored issues
show
Bug introduced by
The method getImportFileData() does not exist on LWS\ImportExport\Facades\Import. 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

75
        /** @scrutinizer ignore-call */ 
76
        $csv_data = Import::getImportFileData($this->import->id);
Loading history...
76
77
        $this->assertInternalType('array', $csv_data);
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

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

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...
78
    }
79
80
    /**
81
     * @test
82
     */
83
    public function store_data_map_with_csv_cols()
84
    {
85
        $import = Import::setDataMap(['email', 'name', 'password'], $this->import->id);
0 ignored issues
show
Bug introduced by
The method setDataMap() does not exist on LWS\ImportExport\Facades\Import. 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

85
        /** @scrutinizer ignore-call */ 
86
        $import = Import::setDataMap(['email', 'name', 'password'], $this->import->id);
Loading history...
86
87
        $this->assertInstanceOf(ModelImport::class, $import);
88
    }
89
90
    /**
91
     * @test
92
     */
93
    public function sucess_to_dispatch_given_job_class()
94
    {
95
        $import = $id = $this->import;
0 ignored issues
show
Unused Code introduced by
The assignment to $id is dead and can be removed.
Loading history...
96
97
        Queue::fake();
98
99
        Import::dispatchImportJob(FakeJob::class, $import);
0 ignored issues
show
Bug introduced by
The method dispatchImportJob() does not exist on LWS\ImportExport\Facades\Import. 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

99
        Import::/** @scrutinizer ignore-call */ 
100
                dispatchImportJob(FakeJob::class, $import);
Loading history...
100
101
        Queue::assertPushedOn('importing', FakeJob::class);
102
    }
103
104
    /**
105
     * @test
106
     */
107
    public function check_import_progress()
108
    {
109
        $response = $this->json('GET', '/import/1/progress');
110
111
        $response->assertStatus(200);
112
113
        $response->assertJsonFragment(['status' => 200]);
114
115
        $response->assertJsonFragment(['progress'=>0]);
116
    }
117
118
    /**
119
     * @test
120
     */
121
    public function remove_import()
122
    {
123
        $this->assertTrue(Import::removeImport($this->import->id));
0 ignored issues
show
Bug introduced by
The method removeImport() does not exist on LWS\ImportExport\Facades\Import. 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

123
        $this->assertTrue(Import::/** @scrutinizer ignore-call */ removeImport($this->import->id));
Loading history...
124
    }
125
}
126