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

ExportTest::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\Export;
14
use Ladybirdweb\ImportExport\Jobs\ExportJob;
15
use Ladybirdweb\ImportExport\Models\Export as ModelExport;
16
17
class ExportTest extends TestCase
18
{
19
	use RefreshDatabase;
0 ignored issues
show
introduced by
The trait Illuminate\Foundation\Testing\RefreshDatabase requires some properties which are not provided by Tests\ExportTest: $connectionsToTransact, $dropViews
Loading history...
20
21
	protected $export;
22
23
	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

23
	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...
24
	{
25
	    return ['Ladybirdweb\ImportExport\ImportExportServiceProvider'];
26
	}
27
28
    protected function getEnvironmentSetUp($app)
29
    {
30
        $app['config']->set('database.default', 'testing');
31
    }
32
33
	protected function setUp ()
34
	{
35
	    parent::setUp();
36
37
	    $this->artisan('migrate', ['--database' => 'testing']);
38
39
	    Route::middleware('web')->group(function() {
40
41
			Route::get('/ticket/export/{id}', [ 'as' => 'ticket.export.progress', 'uses' => 'Ladybirdweb\ImportExport\Export@showExportStatus']);
42
43
			Route::get( '/export/{id}/download',  [ 'as' => 'ladybirdweb.export.download', 'uses' => 'Ladybirdweb\ImportExport\Export@downloadExportedFile']);
44
45
		});
46
47
		Storage::putFileAs('exports', new File( storage_path( 'test/test.csv' ) ), 'test.xls');
48
49
		$this->export = ModelExport::create([
50
			'file' => 'test.xls',
51
			'query' => \App\Models\User::select([ 'name', 'email', 'created_at' ])->getModel(),
0 ignored issues
show
Bug introduced by
The type App\Models\User was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
52
			'type' => 'xls'
53
		]);
54
	}
55
56
	/**
57
	* @test
58
	*/
59
	public function data_export_initiated_and_dispatched()
60
	{
61
		Queue::fake();
62
63
		$export = Export::export( \App\Models\User::select([ 'name', 'email', 'created_at' ]), 'xls' );
0 ignored issues
show
Bug introduced by
The method export() does not exist on Ladybirdweb\ImportExport\Facades\Export. 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

63
		/** @scrutinizer ignore-call */ 
64
  $export = Export::export( \App\Models\User::select([ 'name', 'email', 'created_at' ]), 'xls' );
Loading history...
64
65
		$this->assertInstanceOf( ModelExport::class, $export );
66
67
		Queue::assertPushedOn('exporting', ExportJob::class);
68
	}
69
70
	/**
71
	* @test
72
	*/
73
	public function see_export_progress_page()
74
	{
75
		$response =  $this->get('/ticket/export/' . $this->export->id);
76
77
		$response->assertStatus(200);
78
79
		$response->assertSee('Export');
80
	}
81
82
	/**
83
	* @test
84
	*/
85
	public function check_export_progress_ajax()
86
	{
87
		$response = $this->json( 'GET', '/export/' . $this->export->id . '/progress');
88
89
		$response->assertStatus(200);
90
91
		$response->assertJsonFragment( ['status' => 200] );
92
93
		$response->assertJsonFragment( ['progress'] );
94
	}
95
96
	/**
97
	* @test
98
	*/
99
	public function try_download_exported_file()
100
	{
101
		$response = $this->get('/export/' . $this->export->id . '/download');
102
103
		$response->assertHeader( 'content-disposition', 'attachment; filename="test.xls"');
104
105
		$response->assertStatus(200);
106
	}
107
108
	/**
109
	* @test
110
	*/
111
	public function fail_download_exported_file()
112
	{
113
		$response = $this->get('/export/987654321/download');
114
115
		$response->assertStatus(404);
116
	}
117
}
118