. */ declare(strict_types=1); namespace tests\Feature\Controllers\Rule; use Carbon\Carbon; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Jobs\ExecuteRuleOnExistingTransactions; use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Rule\RuleRepositoryInterface; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\TransactionRules\Engine\RuleEngine; use FireflyIII\TransactionRules\TransactionMatcher; use Illuminate\Support\Collection; use Log; use Mockery; use Tests\TestCase; /** * Class SelectControllerTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ class SelectControllerTest extends TestCase { /** * */ public function setUp(): void { parent::setUp(); Log::info(sprintf('Now in %s.', get_class($this))); } /** * @covers \FireflyIII\Http\Controllers\Rule\SelectController */ public function testExecute(): void { $this->mockDefaultSession(); $account = $this->user()->accounts()->find(1); $accountRepos = $this->mock(AccountRepositoryInterface::class); $repository = $this->mock(RuleRepositoryInterface::class); $userRepos = $this->mock(UserRepositoryInterface::class); $collector = $this->mock(GroupCollectorInterface::class); $ruleEngine = $this->mock(RuleEngine::class); $this->session(['first' => new Carbon('2010-01-01')]); $accountRepos->shouldReceive('getAccountsById')->andReturn(new Collection([$account])); // new mocks for ruleEngine $ruleEngine->shouldReceive('setUser')->atLeast()->once(); $ruleEngine->shouldReceive('setRulesToApply')->atLeast()->once(); $ruleEngine->shouldReceive('setTriggerMode')->atLeast()->once(); $ruleEngine->shouldReceive('processJournalArray')->atLeast()->once(); $collector->shouldReceive('setAccounts')->atLeast()->once(); $collector->shouldReceive('setRange')->atLeast()->once(); $collector->shouldReceive('getExtractedJournals')->atLeast()->once()->andReturn([['x']]); $data = [ 'accounts' => [1], 'start_date' => '2017-01-01', 'end_date' => '2017-01-02', ]; $this->be($this->user()); $response = $this->post(route('rules.execute', [1]), $data); $response->assertStatus(302); $response->assertSessionHas('success'); } /** * @covers \FireflyIII\Http\Controllers\Rule\SelectController */ public function testSelectTransactions(): void { $this->mockDefaultSession(); $accountRepos = $this->mock(AccountRepositoryInterface::class); $userRepos = $this->mock(UserRepositoryInterface::class); $userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->atLeast()->once()->andReturn(true); $accountRepos->shouldReceive('getAccountsByType')->andReturn(new Collection); $this->be($this->user()); $response = $this->get(route('rules.select-transactions', [1])); $response->assertStatus(200); $response->assertSee('