Test Failed
Branch develop (5056e3)
by Abhishek Kumar
05:17
created

ExportTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Tests;
4
5
use Tests\TestCase;
0 ignored issues
show
Bug introduced by
The type Tests\TestCase 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...
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;
20
21
	protected $export;
22
23
	protected function setUp ()
24
	{
25
	    parent::setUp();
26
27
	    Route::middleware('web')->group(function() {
28
29
			Route::get('/ticket/export/{id}', [ 'as' => 'ticket.export.progress', 'uses' => 'Ladybirdweb\ImportExport\Export@showExportStatus']);
30
31
			Route::get( '/export/{id}/download',  [ 'as' => 'ladybirdweb.export.download', 'uses' => 'Ladybirdweb\ImportExport\Export@downloadExportedFile']);
32
33
		});
34
35
		Storage::putFileAs('exports', new File( storage_path( 'test/test.csv' ) ), 'test.xls');
36
37
		$this->export = ModelExport::create([
38
			'file' => 'test.xls',
39
			'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...
40
			'type' => 'xls'
41
		]);
42
	}
43
44
	/**
45
	* @test
46
	*/
47
	public function data_export_initiated_and_dispatched()
48
	{
49
		Queue::fake();
50
51
		$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

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