mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Fix tests
This commit is contained in:
		| @@ -22,6 +22,7 @@ use FireflyIII\Http\Requests\ExportFormRequest; | ||||
| use FireflyIII\Models\AccountType; | ||||
| use FireflyIII\Models\ExportJob; | ||||
| use FireflyIII\Repositories\Account\AccountRepositoryInterface; | ||||
| use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface; | ||||
| use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface as EJRI; | ||||
| use Preferences; | ||||
| use Response; | ||||
| @@ -59,21 +60,22 @@ class ExportController extends Controller | ||||
|      * @return \Symfony\Component\HttpFoundation\Response|\Illuminate\Contracts\Routing\ResponseFactory | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
|     public function download(ExportJob $job) | ||||
|     public function download(ExportJobRepositoryInterface $repository, ExportJob $job) | ||||
|     { | ||||
|         $disk   = Storage::disk('export'); | ||||
|         $file   = $job->key . '.zip'; | ||||
|         $date   = date('Y-m-d \a\t H-i-s'); | ||||
|         $name   = 'Export job on ' . $date . '.zip'; | ||||
|         $quoted = sprintf('"%s"', addcslashes($name, '"\\')); | ||||
|  | ||||
|         if (!$disk->exists($file)) { | ||||
|         if (!$repository->exists($job)) { | ||||
|             throw new FireflyException('Against all expectations, zip file "' . $file . '" does not exist.'); | ||||
|         } | ||||
|         $content = $repository->getContent($job); | ||||
|  | ||||
|  | ||||
|         $job->change('export_downloaded'); | ||||
|  | ||||
|         return response($disk->get($file), 200) | ||||
|         return response($content, 200) | ||||
|             ->header('Content-Description', 'File Transfer') | ||||
|             ->header('Content-Type', 'application/octet-stream') | ||||
|             ->header('Content-Disposition', 'attachment; filename=' . $quoted) | ||||
| @@ -82,7 +84,7 @@ class ExportController extends Controller | ||||
|             ->header('Expires', '0') | ||||
|             ->header('Cache-Control', 'must-revalidate, post-check=0, pre-check=0') | ||||
|             ->header('Pragma', 'public') | ||||
|             ->header('Content-Length', $disk->size($file)); | ||||
|             ->header('Content-Length', strlen($content)); | ||||
|  | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -15,7 +15,7 @@ namespace FireflyIII\Http\Controllers; | ||||
| use Crypt; | ||||
| use FireflyIII\Exceptions\FireflyException; | ||||
| use FireflyIII\Http\Requests\ImportUploadRequest; | ||||
| use FireflyIII\Import\ImportProcedure; | ||||
| use FireflyIII\Import\ImportProcedureInterface; | ||||
| use FireflyIII\Import\Setup\SetupInterface; | ||||
| use FireflyIII\Models\ImportJob; | ||||
| use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; | ||||
| @@ -315,13 +315,13 @@ class ImportController extends Controller | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param ImportJob $job | ||||
|      * @param ImportProcedureInterface $importProcedure | ||||
|      * @param ImportJob                $job | ||||
|      */ | ||||
|     public function start(ImportJob $job) | ||||
|     public function start(ImportProcedureInterface $importProcedure, ImportJob $job) | ||||
|     { | ||||
|         set_time_limit(0); | ||||
|         if ($job->status == 'settings_complete') { | ||||
|             $importProcedure = new ImportProcedure; | ||||
|             $importProcedure->runImport($job); | ||||
|         } | ||||
|     } | ||||
| @@ -334,7 +334,7 @@ class ImportController extends Controller | ||||
|      * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|View | ||||
|      */ | ||||
|     public function status(ImportJob $job) | ||||
|     { | ||||
|     { // | ||||
|         Log::debug('Now in status()', ['job' => $job->key]); | ||||
|         if (!$this->jobInCorrectStep($job, 'status')) { | ||||
|             return $this->redirectToCorrectStep($job); | ||||
|   | ||||
| @@ -23,7 +23,7 @@ use Illuminate\Support\Collection; | ||||
|  * | ||||
|  * @package FireflyIII\Import | ||||
|  */ | ||||
| class ImportProcedure | ||||
| class ImportProcedure implements ImportProcedureInterface | ||||
| { | ||||
|  | ||||
|     /** | ||||
|   | ||||
							
								
								
									
										33
									
								
								app/Import/ImportProcedureInterface.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								app/Import/ImportProcedureInterface.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| <?php | ||||
| /** | ||||
|  * ImportProcedureInterface.php | ||||
|  * Copyright (C) 2016 thegrumpydictator@gmail.com | ||||
|  * | ||||
|  * This software may be modified and distributed under the terms of the | ||||
|  * Creative Commons Attribution-ShareAlike 4.0 International License. | ||||
|  * | ||||
|  * See the LICENSE file for details. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types = 1); | ||||
|  | ||||
| namespace FireflyIII\Import; | ||||
|  | ||||
| use FireflyIII\Models\ImportJob; | ||||
| use Illuminate\Support\Collection; | ||||
|  | ||||
| /** | ||||
|  * Interface ImportProcedureInterface | ||||
|  * | ||||
|  * @package FireflyIII\Import | ||||
|  */ | ||||
| interface ImportProcedureInterface | ||||
| { | ||||
|     /** | ||||
|      * @param ImportJob $job | ||||
|      * | ||||
|      * @return Collection | ||||
|      */ | ||||
|     public function runImport(ImportJob $job): Collection; | ||||
|  | ||||
| } | ||||
| @@ -98,21 +98,13 @@ class FireflyServiceProvider extends ServiceProvider | ||||
|  | ||||
|         // other generators | ||||
|         $this->app->bind('FireflyIII\Export\ProcessorInterface', 'FireflyIII\Export\Processor'); | ||||
|         $this->app->bind('FireflyIII\Import\ImportProcedureInterface', 'FireflyIII\Import\ImportProcedure'); | ||||
|         $this->app->bind('FireflyIII\Repositories\User\UserRepositoryInterface', 'FireflyIII\Repositories\User\UserRepository'); | ||||
|         $this->app->bind('FireflyIII\Helpers\Attachments\AttachmentHelperInterface', 'FireflyIII\Helpers\Attachments\AttachmentHelper'); | ||||
|         $this->app->bind('FireflyIII\Generator\Chart\Bill\BillChartGeneratorInterface', 'FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator'); | ||||
|         $this->app->bind('FireflyIII\Generator\Chart\Budget\BudgetChartGeneratorInterface', 'FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator'); | ||||
|         $this->app->bind( | ||||
|             'FireflyIII\Generator\Chart\Category\CategoryChartGeneratorInterface', 'FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator' | ||||
|         ); | ||||
|         $this->app->bind( | ||||
|             'FireflyIII\Generator\Chart\PiggyBank\PiggyBankChartGeneratorInterface', 'FireflyIII\Generator\Chart\PiggyBank\ChartJsPiggyBankChartGenerator' | ||||
|         ); | ||||
|         $this->app->bind('FireflyIII\Generator\Chart\Report\ReportChartGeneratorInterface', 'FireflyIII\Generator\Chart\Report\ChartJsReportChartGenerator'); | ||||
|  | ||||
|         $this->app->bind('FireflyIII\Helpers\Help\HelpInterface', 'FireflyIII\Helpers\Help\Help'); | ||||
|         $this->app->bind('FireflyIII\Helpers\Report\ReportHelperInterface', 'FireflyIII\Helpers\Report\ReportHelper'); | ||||
|         $this->app->bind('FireflyIII\Helpers\FiscalHelperInterface', 'FireflyIII\Helpers\FiscalHelper'); | ||||
|         $this->app->bind('FireflyIII\Helpers\Report\AccountReportHelperInterface', 'FireflyIII\Helpers\Report\AccountReportHelper'); | ||||
|         $this->app->bind('FireflyIII\Helpers\Report\BalanceReportHelperInterface', 'FireflyIII\Helpers\Report\BalanceReportHelper'); | ||||
|         $this->app->bind('FireflyIII\Helpers\Report\BudgetReportHelperInterface', 'FireflyIII\Helpers\Report\BudgetReportHelper'); | ||||
|     } | ||||
|   | ||||
| @@ -17,6 +17,7 @@ use Carbon\Carbon; | ||||
| use FireflyIII\Models\ExportJob; | ||||
| use FireflyIII\User; | ||||
| use Illuminate\Support\Str; | ||||
| use Storage; | ||||
|  | ||||
| /** | ||||
|  * Class ExportJobRepository | ||||
| @@ -94,6 +95,19 @@ class ExportJobRepository implements ExportJobRepositoryInterface | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param ExportJob $job | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function exists(ExportJob $job): bool | ||||
|     { | ||||
|         $disk = Storage::disk('export'); | ||||
|         $file = $job->key . '.zip'; | ||||
|  | ||||
|         return $disk->exists($file); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param string $key | ||||
|      * | ||||
| @@ -109,4 +123,17 @@ class ExportJobRepository implements ExportJobRepositoryInterface | ||||
|         return $result; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param ExportJob $job | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getContent(ExportJob $job): string | ||||
|     { | ||||
|         $disk    = Storage::disk('export'); | ||||
|         $file    = $job->key . '.zip'; | ||||
|         $content = $disk->get($file); | ||||
|  | ||||
|         return $content; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -32,6 +32,13 @@ interface ExportJobRepositoryInterface | ||||
|      */ | ||||
|     public function create(): ExportJob; | ||||
|  | ||||
|     /** | ||||
|      * @param ExportJob $job | ||||
|      * | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function exists(ExportJob $job): bool; | ||||
|  | ||||
|     /** | ||||
|      * @param string $key | ||||
|      * | ||||
| @@ -39,4 +46,11 @@ interface ExportJobRepositoryInterface | ||||
|      */ | ||||
|     public function findByKey(string $key): ExportJob; | ||||
|  | ||||
|     /** | ||||
|      * @param ExportJob $job | ||||
|      * | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getContent(ExportJob $job): string; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -9,7 +9,7 @@ | ||||
|  * See the LICENSE file for details. | ||||
|  */ | ||||
| use FireflyIII\Export\Processor; | ||||
|  | ||||
| use FireflyIII\Repositories\ExportJob\ExportJobRepositoryInterface; | ||||
|  | ||||
| /** | ||||
|  * Generated by PHPUnit_SkeletonGenerator on 2016-12-10 at 05:51:41. | ||||
| @@ -32,6 +32,10 @@ class ExportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testDownload() | ||||
|     { | ||||
|         $repository = $this->mock(ExportJobRepositoryInterface::class); | ||||
|         $repository->shouldReceive('exists')->once()->andReturn(true); | ||||
|         $repository->shouldReceive('getContent')->once()->andReturn('Some content beep boop'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $this->call('GET', route('export.download', ['testExport'])); | ||||
|         $this->assertResponseStatus(200); | ||||
|   | ||||
| @@ -10,7 +10,7 @@ | ||||
|  */ | ||||
| use FireflyIII\Import\Setup\CsvSetup; | ||||
| use Illuminate\Http\UploadedFile; | ||||
|  | ||||
| use FireflyIII\Import\ImportProcedureInterface; | ||||
|  | ||||
| /** | ||||
|  * Generated by PHPUnit_SkeletonGenerator on 2016-12-10 at 05:51:41. | ||||
| @@ -142,6 +142,11 @@ class ImportControllerTest extends TestCase | ||||
|      */ | ||||
|     public function testStart() | ||||
|     { | ||||
|         /** @var ImportProcedureInterface $procedure */ | ||||
|         $procedure = $this->mock(ImportProcedureInterface::class); | ||||
|  | ||||
|         $procedure->shouldReceive('runImport'); | ||||
|  | ||||
|         $this->be($this->user()); | ||||
|         $this->call('post', route('import.start', ['complete'])); | ||||
|         $this->assertResponseStatus(200); | ||||
| @@ -156,7 +161,7 @@ class ImportControllerTest extends TestCase | ||||
|         // complete | ||||
|         $this->be($this->user()); | ||||
|         $this->call('get', route('import.status', ['complete'])); | ||||
|         $this->assertResponseStatus(302); | ||||
|         $this->assertResponseStatus(200); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
		Reference in New Issue
	
	Block a user