. */ declare(strict_types=1); namespace Tests\Feature\Controllers\Import; use FireflyIII\Import\Routine\FileRoutine; use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface; use Log; use Tests\TestCase; /** * Class AccountControllerTest * * @SuppressWarnings(PHPMD.TooManyPublicMethods) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class IndexControllerTest extends TestCase { /** * */ public function setUp() { parent::setUp(); Log::debug(sprintf('Now in %s.', get_class($this))); } /** * @covers \FireflyIII\Http\Controllers\Import\IndexController::create */ public function testCreate() { $job = $this->user()->importJobs()->where('key', 'new')->first(); $repository = $this->mock(ImportJobRepositoryInterface::class); $repository->shouldReceive('create')->withArgs(['file'])->andReturn($job); $this->be($this->user()); $response = $this->get(route('import.create-job', ['file'])); $response->assertStatus(302); $response->assertRedirect(route('import.configure', ['new'])); } /** * @covers \FireflyIII\Http\Controllers\Import\IndexController::download */ public function testDownload() { $repository = $this->mock(ImportJobRepositoryInterface::class); //$job = $this->user()->importJobs()->where('key', 'testImport')->first(); $this->be($this->user()); $response = $this->get(route('import.download', ['testImport'])); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\Import\IndexController::__construct * @covers \FireflyIII\Http\Controllers\Import\IndexController::index */ public function testIndex() { $repository = $this->mock(ImportJobRepositoryInterface::class); $this->be($this->user()); $response = $this->get(route('import.index')); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\Import\IndexController::start */ public function testStart() { $repository = $this->mock(ImportJobRepositoryInterface::class); $routine = $this->mock(FileRoutine::class); $routine->shouldReceive('setJob')->once(); $routine->shouldReceive('run')->once()->andReturn(true); $this->be($this->user()); $response = $this->post(route('import.start', ['configured'])); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\Import\IndexController::start * @expectedExceptionMessage Job did not complete successfully. */ public function testStartFailed() { $repository = $this->mock(ImportJobRepositoryInterface::class); $routine = $this->mock(FileRoutine::class); $routine->shouldReceive('setJob')->once(); $routine->shouldReceive('run')->once()->andReturn(false); $this->be($this->user()); $response = $this->post(route('import.start', ['configured'])); $response->assertStatus(500); } }