Test Failed
Branch develop (f16019)
by Abhishek Kumar
08:27
created

ImportTest::getEnvironmentSetUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Tests;
4
5
use Orchestra\Testbench\TestCase;
6
use Illuminate\Http\File;
7
use Illuminate\Http\UploadedFile;
8
use Illuminate\Foundation\Testing\RefreshDatabase;
9
use Illuminate\Foundation\Testing\WithoutMiddleware;
10
use Illuminate\Support\Facades\Queue;
11
use Illuminate\Support\Facades\Route;
12
use Illuminate\Support\Facades\Storage;
13
use Ladybirdweb\ImportExport\Facades\Import;
14
use Ladybirdweb\ImportExport\Models\Import as ModelImport;
15
16
class ImportTest extends TestCase
17
{
18
	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
Loading history...
19
20
	protected $import;
21
22
	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

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

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

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

79
		/** @scrutinizer ignore-call */ 
80
  $csv_data = Import::getImportFileData($this->import->id);
Loading history...
80
81
		$this->assertInternalType( 'array', $csv_data );
82
	}
83
84
	/**
85
	* @test
86
	*/
87
	public function store_data_map_with_csv_cols()
88
	{
89
		$import = Import::setDataMap(['email', 'name', 'password'], $this->import->id);
0 ignored issues
show
Bug introduced by
The method setDataMap() does not exist on Ladybirdweb\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

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

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

127
		$this->assertTrue(Import::/** @scrutinizer ignore-call */ removeImport($this->import->id));
Loading history...
128
	}
129
}
130