Best Phake code snippet using AtLeast.verify
AccountTransformerTest.php
Source:AccountTransformerTest.php
...77 $accountRepos->shouldReceive('getOpeningBalanceDate')->withArgs([Mockery::any()])->andReturnNull()->atLeast()->once();78 // steam is also called for the account balance:79 Steam::shouldReceive('balance')->andReturn('123.45')->atLeast()->once();80 $result = $transformer->transform($account);81 // verify all fields.82 $this->assertEquals($account->id, $result['id']);83 $this->assertEquals($account->active, $result['active']);84 $this->assertEquals($account->name, $result['name']);85 $this->assertEquals('asset', $result['type']);86 $this->assertEquals('defaultAsset', $result['account_role']);87 $this->assertEquals(1, $result['currency_id']);88 $this->assertEquals('EUR', $result['currency_code']);89 $this->assertEquals('â¬', $result['currency_symbol']);90 $this->assertEquals(2, $result['currency_decimal_places']);91 // date given, so it must match.92 $this->assertEquals('2018-01-01', $result['current_balance_date']);93 $this->assertEquals(123.45, $result['current_balance']);94 $this->assertEquals('I am a note', $result['notes']);95 $this->assertNull($result['monthly_payment_date']);96 $this->assertNull($result['credit_card_type']);97 $this->assertEquals('12345', $result['account_number']);98 $this->assertEquals($account->iban, $result['iban']);99 $this->assertEquals('NL5X', $result['bic']);100 $this->assertNull($result['liability_type']);101 $this->assertNull($result['liability_amount']);102 $this->assertNull($result['liability_start_date']);103 $this->assertNull($result['interest']);104 $this->assertNull($result['interest_period']);105 $this->assertTrue($result['include_net_worth']);106 }107 /**108 * Load a basic asset account, and verify the result in the transformer.109 *110 * @covers \FireflyIII\Transformers\AccountTransformer111 */112 public function testBasicAsset(): void113 {114 // mock stuff and get object:115 $account = $this->getRandomAsset();116 $euro = $this->getEuro();117 $accountRepos = $this->mock(AccountRepositoryInterface::class);118 $transformer = app(AccountTransformer::class);119 $transformer->setParameters(new ParameterBag);120 // following calls are expected:121 $accountRepos->shouldReceive('setUser')->atLeast()->once();122 $accountRepos->shouldReceive('getAccountType')->andReturn('Asset account')->atLeast()->once();123 $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();124 $accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();125 $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();126 // get all kinds of meta values:127 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset')->atLeast()->once();128 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();129 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();130 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();131 // opening balance:132 $accountRepos->shouldReceive('getOpeningBalanceAmount')->withArgs([Mockery::any()])->andReturnNull()->atLeast()->once();133 $accountRepos->shouldReceive('getOpeningBalanceDate')->withArgs([Mockery::any()])->andReturnNull()->atLeast()->once();134 // steam is also called for the account balance:135 Steam::shouldReceive('balance')->andReturn('123.45')->atLeast()->once();136 $result = $transformer->transform($account);137 // verify all fields.138 $this->assertEquals($account->id, $result['id']);139 $this->assertEquals($account->active, $result['active']);140 $this->assertEquals($account->name, $result['name']);141 $this->assertEquals('asset', $result['type']);142 $this->assertEquals('defaultAsset', $result['account_role']);143 $this->assertEquals(1, $result['currency_id']);144 $this->assertEquals('EUR', $result['currency_code']);145 $this->assertEquals('â¬', $result['currency_symbol']);146 $this->assertEquals(2, $result['currency_decimal_places']);147 // no date given, so must be today:148 $this->assertEquals(date('Y-m-d'), $result['current_balance_date']);149 $this->assertEquals(123.45, $result['current_balance']);150 $this->assertEquals('I am a note', $result['notes']);151 $this->assertNull($result['monthly_payment_date']);152 $this->assertNull($result['credit_card_type']);153 $this->assertEquals('12345', $result['account_number']);154 $this->assertEquals($account->iban, $result['iban']);155 $this->assertEquals('NL5X', $result['bic']);156 $this->assertNull($result['liability_type']);157 $this->assertNull($result['liability_amount']);158 $this->assertNull($result['liability_start_date']);159 $this->assertNull($result['interest']);160 $this->assertNull($result['interest_period']);161 $this->assertTrue($result['include_net_worth']);162 }163 /**164 * Credit card asset has some extra fields165 *166 * @covers \FireflyIII\Transformers\AccountTransformer167 */168 public function testCreditCardAsset(): void169 {170 // mock stuff and get object:171 $account = $this->getRandomAsset();172 $euro = $this->getEuro();173 $accountRepos = $this->mock(AccountRepositoryInterface::class);174 $transformer = app(AccountTransformer::class);175 $transformer->setParameters(new ParameterBag);176 // following calls are expected:177 $accountRepos->shouldReceive('setUser')->atLeast()->once();178 $accountRepos->shouldReceive('getAccountType')->andReturn('Asset account')->atLeast()->once();179 $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();180 $accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();181 $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();182 // get all kinds of meta values:183 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('ccAsset')->atLeast()->once();184 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();185 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();186 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();187 // credit card fields:188 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_type'])->andReturn('monthlyFull')->atLeast()->once();189 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'cc_monthly_payment_date'])->andReturn('2018-01-01')->atLeast()->once();190 // opening balance:191 $accountRepos->shouldReceive('getOpeningBalanceAmount')->withArgs([Mockery::any()])->andReturnNull()->atLeast()->once();192 $accountRepos->shouldReceive('getOpeningBalanceDate')->withArgs([Mockery::any()])->andReturnNull()->atLeast()->once();193 // steam is also called for the account balance:194 Steam::shouldReceive('balance')->andReturn('123.45')->atLeast()->once();195 $result = $transformer->transform($account);196 // verify all fields.197 $this->assertEquals($account->id, $result['id']);198 $this->assertEquals($account->active, $result['active']);199 $this->assertEquals($account->name, $result['name']);200 $this->assertEquals('asset', $result['type']);201 $this->assertEquals('ccAsset', $result['account_role']);202 $this->assertEquals(1, $result['currency_id']);203 $this->assertEquals('EUR', $result['currency_code']);204 $this->assertEquals('â¬', $result['currency_symbol']);205 $this->assertEquals(2, $result['currency_decimal_places']);206 // no date given, so must be today:207 $this->assertEquals(date('Y-m-d'), $result['current_balance_date']);208 $this->assertEquals(123.45, $result['current_balance']);209 $this->assertEquals('I am a note', $result['notes']);210 // cc fields must be filled in:211 $this->assertEquals('2018-01-01', $result['monthly_payment_date']);212 $this->assertEquals('monthlyFull', $result['credit_card_type']);213 $this->assertEquals('12345', $result['account_number']);214 $this->assertEquals($account->iban, $result['iban']);215 $this->assertEquals('NL5X', $result['bic']);216 $this->assertNull($result['liability_type']);217 $this->assertNull($result['liability_amount']);218 $this->assertNull($result['liability_start_date']);219 $this->assertNull($result['interest']);220 $this->assertNull($result['interest_period']);221 $this->assertTrue($result['include_net_worth']);222 }223 /**224 * Liability also has some extra fields.225 *226 * @covers \FireflyIII\Transformers\AccountTransformer227 */228 public function testLiability(): void229 {230 // mock stuff and get object:231 $account = $this->getRandomAsset();232 $euro = $this->getEuro();233 $accountRepos = $this->mock(AccountRepositoryInterface::class);234 $transformer = app(AccountTransformer::class);235 $transformer->setParameters(new ParameterBag);236 // following calls are expected:237 $accountRepos->shouldReceive('setUser')->atLeast()->once();238 $accountRepos->shouldReceive('getAccountType')->andReturn('Mortgage')->atLeast()->once();239 $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();240 $accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();241 $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();242 // get all kinds of meta values:243 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('')->atLeast()->once();244 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();245 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();246 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();247 // data for liability248 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest'])->andReturn('3')->atLeast()->once();249 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'interest_period'])->andReturn('monthly')->atLeast()->once();250 // opening balance:251 $accountRepos->shouldReceive('getOpeningBalanceAmount')->withArgs([Mockery::any()])->andReturn('-1000')->atLeast()->once();252 $accountRepos->shouldReceive('getOpeningBalanceDate')->withArgs([Mockery::any()])->andReturn('2018-01-01')->atLeast()->once();253 // steam is also called for the account balance:254 Steam::shouldReceive('balance')->andReturn('123.45')->atLeast()->once();255 $result = $transformer->transform($account);256 // verify all fields.257 $this->assertEquals($account->id, $result['id']);258 $this->assertEquals($account->active, $result['active']);259 $this->assertEquals($account->name, $result['name']);260 $this->assertEquals('liabilities', $result['type']);261 $this->assertNull($result['account_role']);262 $this->assertEquals(1, $result['currency_id']);263 $this->assertEquals('EUR', $result['currency_code']);264 $this->assertEquals('â¬', $result['currency_symbol']);265 $this->assertEquals(2, $result['currency_decimal_places']);266 // no date given, so must be today:267 $this->assertEquals(date('Y-m-d'), $result['current_balance_date']);268 $this->assertEquals(123.45, $result['current_balance']);269 $this->assertEquals('I am a note', $result['notes']);270 $this->assertNull($result['monthly_payment_date']);271 $this->assertNull($result['credit_card_type']);272 $this->assertEquals('12345', $result['account_number']);273 $this->assertEquals($account->iban, $result['iban']);274 $this->assertEquals('NL5X', $result['bic']);275 // liability fields276 $this->assertEquals('mortgage', $result['liability_type']);277 $this->assertEquals('-1000', $result['liability_amount']);278 $this->assertEquals('2018-01-01', $result['liability_start_date']);279 $this->assertEquals('3', $result['interest']);280 $this->assertEquals('monthly', $result['interest_period']);281 $this->assertTrue($result['include_net_worth']);282 }283 /**284 * If the account is not an asset account, the role must always be NULL.285 *286 * @covers \FireflyIII\Transformers\AccountTransformer287 */288 public function testRoleEmpty(): void289 {290 // mock stuff and get object:291 $account = $this->getRandomExpense();292 $euro = $this->getEuro();293 $accountRepos = $this->mock(AccountRepositoryInterface::class);294 $transformer = app(AccountTransformer::class);295 $transformer->setParameters(new ParameterBag);296 // following calls are expected:297 $accountRepos->shouldReceive('setUser')->atLeast()->once();298 $accountRepos->shouldReceive('getAccountType')->andReturn('Expense account')->atLeast()->once();299 $accountRepos->shouldReceive('getAccountCurrency')->andReturn($euro)->atLeast()->once();300 $accountRepos->shouldReceive('getNoteText')->andReturn('I am a note')->atLeast()->once();301 $accountRepos->shouldReceive('getLocation')->atLeast()->once()->andReturnNull();302 // get all kinds of meta values:303 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_role'])->andReturn('defaultAsset')->atLeast()->once();304 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'include_net_worth'])->andReturn('1')->atLeast()->once();305 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'account_number'])->andReturn('12345')->atLeast()->once();306 $accountRepos->shouldReceive('getMetaValue')->withArgs([Mockery::any(), 'BIC'])->andReturn('NL5X')->atLeast()->once();307 // steam is also called for the account balance:308 Steam::shouldReceive('balance')->andReturn('123.45')->atLeast()->once();309 $result = $transformer->transform($account);310 // verify all fields.311 $this->assertEquals($account->id, $result['id']);312 $this->assertEquals($account->active, $result['active']);313 $this->assertEquals($account->name, $result['name']);314 $this->assertEquals('expense', $result['type']);315 $this->assertNull($result['account_role']);316 $this->assertEquals(1, $result['currency_id']);317 $this->assertEquals('EUR', $result['currency_code']);318 $this->assertEquals('â¬', $result['currency_symbol']);319 $this->assertEquals(2, $result['currency_decimal_places']);320 // no date given, so must be today:321 $this->assertEquals(date('Y-m-d'), $result['current_balance_date']);322 $this->assertEquals(123.45, $result['current_balance']);323 $this->assertEquals('I am a note', $result['notes']);324 $this->assertNull($result['monthly_payment_date']);...
CreateCSVImportTest.php
Source:CreateCSVImportTest.php
...97 ->expectsOutput(sprintf('Configuration file : %s', $config))98 ->expectsOutput('User : #1 (james@firefly-iii.org)')99 ->expectsOutput(sprintf('Job : %s', $importJob->key))100 ->assertExitCode(0);101 // this method imports nothing so there is nothing to verify.102 }103 /**104 * Covers a default run with perfect arguments, but no import tag105 *106 * @covers \FireflyIII\Console\Commands\Import\CreateCSVImport107 */108 public function testHandleNoTag(): void109 {110 $userRepos = $this->mock(UserRepositoryInterface::class);111 $jobRepos = $this->mock(ImportJobRepositoryInterface::class);112 $fileRoutine = $this->mock(FileRoutine::class);113 $storage = $this->mock(ImportArrayStorage::class);114 $user = $this->user();115 $token = new Preference;116 $importJob = ImportJob::create(117 [118 'key' => 'key-' . $this->randomInt(),119 'user_id' => 1,120 'file_type' => 'csv',121 'status' => 'new',122 'errors' => [],123 ]124 );125 $file = storage_path('build/test-upload.csv');126 $config = storage_path('build/configuration.json');127 // set preferences:128 $token->data = 'token';129 // mock calls to repository:130 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($user);131 $jobRepos->shouldReceive('setUser')->atLeast()->once();132 $jobRepos->shouldReceive('create')->atLeast()->once()->andReturn($importJob);133 $jobRepos->shouldReceive('storeCLIupload')->atLeast()->once()->andReturn(new MessageBag);134 $jobRepos->shouldReceive('setConfiguration')->atLeast()->once();135 // job is ready to run.136 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->atLeast()->once();137 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->atLeast()->once();138 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storing_data'])->atLeast()->once();139 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storage_finished'])->atLeast()->once();140 // file routine gets called.141 $fileRoutine->shouldReceive('setImportJob')->atLeast()->once();142 $fileRoutine->shouldReceive('run')->atLeast()->once();143 // store data thing gets called.144 $storage->shouldReceive('setImportJob')->atLeast()->once();145 $storage->shouldReceive('store')->atLeast()->once();146 // mock Preferences.147 Preferences::shouldReceive('setForUser')->atLeast()->once()->withArgs([Mockery::any(), 'lastActivity', Mockery::any()]);148 Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'access_token', null])->andReturn($token);149 $parameters = [150 $file,151 $config,152 '--user=1',153 '--token=token',154 ];155 $this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))156 ->expectsOutput(sprintf('Import file : %s', $file))157 ->expectsOutput(sprintf('Configuration file : %s', $config))158 ->expectsOutput('User : #1 (james@firefly-iii.org)')159 ->expectsOutput(sprintf('Job : %s', $importJob->key))160 ->expectsOutput('No transactions have been imported :(.')161 ->assertExitCode(0);162 // this method imports nothing so there is nothing to verify.163 }164 /**165 * Covers a default run with perfect arguments, but errors after importing.166 *167 * @covers \FireflyIII\Console\Commands\Import\CreateCSVImport168 */169 public function testHandleErrors(): void170 {171 $userRepos = $this->mock(UserRepositoryInterface::class);172 $jobRepos = $this->mock(ImportJobRepositoryInterface::class);173 $fileRoutine = $this->mock(FileRoutine::class);174 $storage = $this->mock(ImportArrayStorage::class);175 $user = $this->user();176 $token = new Preference;177 $importJob = ImportJob::create(178 [179 'key' => 'key-' . $this->randomInt(),180 'user_id' => 1,181 'file_type' => 'csv',182 'status' => 'new',183 'errors' => ['I am an error'],184 ]185 );186 $file = storage_path('build/test-upload.csv');187 $config = storage_path('build/configuration.json');188 // set preferences:189 $token->data = 'token';190 // mock calls to repository:191 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($user);192 $jobRepos->shouldReceive('setUser')->atLeast()->once();193 $jobRepos->shouldReceive('create')->atLeast()->once()->andReturn($importJob);194 $jobRepos->shouldReceive('storeCLIupload')->atLeast()->once()->andReturn(new MessageBag);195 $jobRepos->shouldReceive('setConfiguration')->atLeast()->once();196 // job is ready to run.197 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->atLeast()->once();198 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->atLeast()->once();199 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storing_data'])->atLeast()->once();200 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storage_finished'])->atLeast()->once();201 // file routine gets called.202 $fileRoutine->shouldReceive('setImportJob')->atLeast()->once();203 $fileRoutine->shouldReceive('run')->atLeast()->once();204 // store data thing gets called.205 $storage->shouldReceive('setImportJob')->atLeast()->once();206 $storage->shouldReceive('store')->atLeast()->once();207 // mock Preferences.208 Preferences::shouldReceive('setForUser')->atLeast()->once()->withArgs([Mockery::any(), 'lastActivity', Mockery::any()]);209 Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'access_token', null])->andReturn($token);210 $parameters = [211 $file,212 $config,213 '--user=1',214 '--token=token',215 ];216 $this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))217 ->expectsOutput(sprintf('Import file : %s', $file))218 ->expectsOutput(sprintf('Configuration file : %s', $config))219 ->expectsOutput('User : #1 (james@firefly-iii.org)')220 ->expectsOutput(sprintf('Job : %s', $importJob->key))221 ->expectsOutput('- I am an error')222 ->assertExitCode(0);223 // this method imports nothing so there is nothing to verify.224 }225 /**226 * Crash while storing data.227 *228 * @covers \FireflyIII\Console\Commands\Import\CreateCSVImport229 */230 public function testHandleCrashStorage(): void231 {232 $userRepos = $this->mock(UserRepositoryInterface::class);233 $jobRepos = $this->mock(ImportJobRepositoryInterface::class);234 $fileRoutine = $this->mock(FileRoutine::class);235 $storage = $this->mock(ImportArrayStorage::class);236 $user = $this->user();237 $token = new Preference;238 $importJob = $this->user()->importJobs()->first();239 $file = storage_path('build/test-upload.csv');240 $config = storage_path('build/configuration.json');241 // set preferences:242 $token->data = 'token';243 // mock calls to repository:244 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($user);245 $jobRepos->shouldReceive('setUser')->atLeast()->once();246 $jobRepos->shouldReceive('create')->atLeast()->once()->andReturn($importJob);247 $jobRepos->shouldReceive('storeCLIupload')->atLeast()->once()->andReturn(new MessageBag);248 $jobRepos->shouldReceive('setConfiguration')->atLeast()->once();249 // job is ready to run.250 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->atLeast()->once();251 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'provider_finished'])->atLeast()->once();252 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'storing_data'])->atLeast()->once();253 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'error'])->atLeast()->once();254 // file routine gets called.255 $fileRoutine->shouldReceive('setImportJob')->atLeast()->once();256 $fileRoutine->shouldReceive('run')->atLeast()->once();257 // store data thing gets called.258 $storage->shouldReceive('setImportJob')->atLeast()->once();259 $storage->shouldReceive('store')->atLeast()->once()->andThrow(new FireflyException('I am storage error.'));260 // mock Preferences.261 Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'access_token', null])->andReturn($token);262 $parameters = [263 $file,264 $config,265 '--user=1',266 '--token=token',267 ];268 Log::warning('The following error is part of a test.');269 $this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))270 ->expectsOutput(sprintf('Import file : %s', $file))271 ->expectsOutput(sprintf('Configuration file : %s', $config))272 ->expectsOutput('User : #1 (james@firefly-iii.org)')273 ->expectsOutput(sprintf('Job : %s', $importJob->key))274 ->expectsOutput('The import routine crashed: I am storage error.')275 ->assertExitCode(1);276 // this method imports nothing so there is nothing to verify.277 }278 /**279 * The file processor crashes for some reason.280 *281 * @covers \FireflyIII\Console\Commands\Import\CreateCSVImport282 */283 public function testHandleCrashProcess(): void284 {285 $userRepos = $this->mock(UserRepositoryInterface::class);286 $jobRepos = $this->mock(ImportJobRepositoryInterface::class);287 $fileRoutine = $this->mock(FileRoutine::class);288 $storage = $this->mock(ImportArrayStorage::class);289 $user = $this->user();290 $token = new Preference;291 $importJob = $this->user()->importJobs()->first();292 $file = storage_path('build/test-upload.csv');293 $config = storage_path('build/configuration.json');294 // set preferences:295 $token->data = 'token';296 // mock calls to repository:297 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($user);298 $jobRepos->shouldReceive('setUser')->atLeast()->once();299 $jobRepos->shouldReceive('create')->atLeast()->once()->andReturn($importJob);300 $jobRepos->shouldReceive('storeCLIupload')->atLeast()->once()->andReturn(new MessageBag);301 $jobRepos->shouldReceive('setConfiguration')->atLeast()->once();302 // job is ready to run.303 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'ready_to_run'])->atLeast()->once();304 $jobRepos->shouldReceive('setStatus')->withArgs([Mockery::any(), 'error'])->atLeast()->once();305 // file routine gets called.306 $fileRoutine->shouldReceive('setImportJob')->atLeast()->once();307 $fileRoutine->shouldReceive('run')->atLeast()->once()->andThrows(new FireflyException('I am big bad exception.'));308 // mock Preferences.309 Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'access_token', null])->andReturn($token);310 $parameters = [311 $file,312 $config,313 '--user=1',314 '--token=token',315 ];316 Log::warning('The following error is part of a test.');317 $this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))318 ->expectsOutput(sprintf('Import file : %s', $file))319 ->expectsOutput(sprintf('Configuration file : %s', $config))320 ->expectsOutput('User : #1 (james@firefly-iii.org)')321 ->expectsOutput(sprintf('Job : %s', $importJob->key))322 ->expectsOutput('The import routine crashed: I am big bad exception.')323 ->assertExitCode(1);324 // this method imports nothing so there is nothing to verify.325 }326 /**327 * Throw error when storing data.328 *329 * @covers \FireflyIII\Console\Commands\Import\CreateCSVImport330 */331 public function testHandleFileStoreError(): void332 {333 $userRepos = $this->mock(UserRepositoryInterface::class);334 $jobRepos = $this->mock(ImportJobRepositoryInterface::class);335 $this->mock(FileRoutine::class);336 $this->mock(ImportArrayStorage::class);337 $user = $this->user();338 $token = new Preference;339 $importJob = $this->user()->importJobs()->first();340 $file = storage_path('build/test-upload.csv');341 $config = storage_path('build/configuration.json');342 $messages = new MessageBag;343 $messages->add('file', 'Some file error.');344 // set preferences:345 $token->data = 'token';346 // mock calls to repository:347 $userRepos->shouldReceive('findNull')->atLeast()->once()->andReturn($user);348 $jobRepos->shouldReceive('setUser')->atLeast()->once();349 $jobRepos->shouldReceive('create')->atLeast()->once()->andReturn($importJob);350 $jobRepos->shouldReceive('storeCLIupload')->atLeast()->once()->andReturn($messages);351 // mock Preferences.352 Preferences::shouldReceive('getForUser')->atLeast()->once()->withArgs([Mockery::any(), 'access_token', null])->andReturn($token);353 $parameters = [354 $file,355 $config,356 '--user=1',357 '--token=token',358 ];359 Log::warning('The following error is part of a test.');360 $this->artisan('firefly-iii:csv-import ' . implode(' ', $parameters))361 ->expectsOutput(sprintf('Import file : %s', $file))362 ->expectsOutput(sprintf('Configuration file : %s', $config))363 ->expectsOutput('User : #1 (james@firefly-iii.org)')364 ->expectsOutput(sprintf('Job : %s', $importJob->key))365 ->expectsOutput('Some file error.')366 ->assertExitCode(1);367 // this method imports nothing so there is nothing to verify.368 }369}...
VerifyTest.php
Source:VerifyTest.php
2use ShortifyPunit\ShortifyPunit;3class VerifyTest extends \PHPUnit_Framework_TestCase4{5 /**6 * Testing the verify corrupt data return values7 */8 public function testVerifyCorruptDataReturnValues()9 {10 $mock = ShortifyPunit::mock('Foo');11 ShortifyPunit::when($mock)->bar()->foo()->returns(1);12 $this->assertTrue(ShortifyPunit::verify($mock)->blabla()->calledTimes(0)); // missing function13 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->calledTimes(0)); // this function with that parameter hasn't been stubbed14 }15 /**16 * Testing if verify throws exception if not a mocked object17 *18 * @expectedException \PHPUnit_Framework_AssertionFailedError19 */20 public function testVerifyNotAnInstanceOfMockInterface()21 {22 ShortifyPunit::verify(new Foo());23 }24 /**25 * Basic test verify chain stubbing without any parameter26 */27 public function testVerifyChainNoParameters()28 {29 $mock = ShortifyPunit::mock('Foo');30 ShortifyPunit::when($mock)->bar()->foo()->returns(1);31 $mock->bar()->foo();32 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->foo()->atLeast(1));33 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->foo()->calledTimes(1));34 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->foo()->lessThan(2));35 $this->assertFalse(ShortifyPunit::verify($mock)->bar()->foo()->lessThan(1));36 $this->assertFalse(ShortifyPunit::verify($mock)->bar()->foo()->calledTimes(2));37 $this->assertFalse(ShortifyPunit::verify($mock)->bar()->foo()->atLeast(2));38 }39 /**40 * Secondary stub should reset call counter41 */42 public function testVerifyResetCounterOnMock()43 {44 // First stub45 $mock = ShortifyPunit::mock('Foo');46 ShortifyPunit::when($mock)->bar()->foo()->returns(1);47 $mock->bar()->foo();48 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->foo()->atLeast(1));49 // Secondary stub should reset counter50 ShortifyPunit::when($mock)->bar()->foo()->returns(1);51 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->foo()->calledTimes(0));52 }53 /**54 * Testing secondary stub is not effecting child elements55 */56 public function testSecondaryStubNotCausingIssues()57 {58 $mock = ShortifyPunit::mock('Foo');59 ShortifyPunit::when($mock)->bar()->foo()->returns(1);60 ShortifyPunit::when($mock)->bar(1)->foo()->returns(2);61 ShortifyPunit::when($mock)->bar()->foo(2)->returns(3);62 $this->assertEquals($mock->bar()->foo(), 1);63 $this->assertEquals($mock->bar(1)->foo(), 2);64 $this->assertEquals($mock->bar()->foo(2), 3);65 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->foo()->calledTimes(1));66 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo()->calledTimes(1));67 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->foo(2)->calledTimes(1));68 ShortifyPunit::when($mock)->bar()->foo()->returns(1);69 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->foo()->calledTimes(0));70 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo()->calledTimes(1));71 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->foo(2)->calledTimes(1));72 }73 /**74 * Basic single stubbing75 */76 public function testVerifySingleStub()77 {78 $mock = ShortifyPunit::mock('Foo');79 ShortifyPunit::when($mock)->bar()->returns(1);80 $mock->bar();81 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->atLeast(1));82 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->calledTimes(1));83 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->lessThan(2));84 $mock->bar();85 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->atLeast(2));86 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->calledTimes(2));87 $this->assertTrue(ShortifyPunit::verify($mock)->bar()->lessThan(3));88 ShortifyPunit::when($mock)->bar(1)->returns(2);89 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->neverCalled());90 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->atLeast(0));91 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->calledTimes(0));92 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->lessThan(1));93 $mock->bar(1);94 $this->assertTrue(ShortifyPunit::Verify($mock)->bar(1)->atLeast(1));95 $this->assertTrue(ShortifyPunit::Verify($mock)->bar(1)->calledTimes(1));96 $this->assertTrue(ShortifyPunit::Verify($mock)->bar(1)->lessThan(2));97 }98 /**99 * Verifying chained stubbing with parameters100 */101 public function testVerifyWithParameters()102 {103 $mock = ShortifyPunit::mock('Foo');104 ShortifyPunit::when($mock)->bar(1)->foo(2)->returns(10);105 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->neverCalled());106 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeast(0));107 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->calledTimes(0));108 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->lessThan(1));109 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeast(1));110 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeastOnce());111 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->calledTimes(1));112 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->lessThan(0));113 $mock->bar(1)->foo(2);114 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->neverCalled());115 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeast(1));116 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeastOnce());117 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->calledTimes(1));118 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->lessThan(2));119 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeast(2));120 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->calledTimes(2));121 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->lessThan(1));122 }123 /**124 * Testing with Hamcrest matching functions125 */126 public function testWithHamcrestMatcher()127 {128 $mock = ShortifyPunit::mock('Foo');129 ShortifyPunit::when($mock)->bar(equalTo(1))->foo(anything())->returns(10);130 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->neverCalled());131 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeast(0));132 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->calledTimes(0));133 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->lessThan(1));134 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeastOnce());135 $mock->bar(1)->foo(2);136 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->neverCalled());137 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeast(1));138 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeastOnce());139 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->calledTimes(1));140 $this->assertTrue(ShortifyPunit::verify($mock)->bar(1)->foo(2)->lessThan(2));141 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->atLeast(2));142 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->calledTimes(2));143 $this->assertFalse(ShortifyPunit::verify($mock)->bar(1)->foo(2)->lessThan(1));144 }145}...
verify
Using AI Code Generation
1$atleast = new AtLeast();2$atleast->verify();3$atleast = new AtLeast();4$atleast->verify();5$atleast = new AtLeast();6$atleast->verify();7$atleast = new AtLeast();8$atleast->verify();9$atleast = new AtLeast();10$atleast->verify();11$atleast = new AtLeast();12$atleast->verify();13$atleast = new AtLeast();14$atleast->verify();15$atleast = new AtLeast();16$atleast->verify();17$atleast = new AtLeast();18$atleast->verify();19$atleast = new AtLeast();20$atleast->verify();21$atleast = new AtLeast();22$atleast->verify();23$atleast = new AtLeast();24$atleast->verify();25$atleast = new AtLeast();26$atleast->verify();27$atleast = new AtLeast();28$atleast->verify();29$atleast = new AtLeast();30$atleast->verify();31$atleast = new AtLeast();32$atleast->verify();
verify
Using AI Code Generation
1$atLeast = new AtLeast();2$atLeast->verify(4, 4, 4);3$atLeast = new AtLeast();4$atLeast->verify(4, 4, 4, 4);5$atLeast = new AtLeast();6$atLeast->verify(4, 4, 4, 4, 4);7$atLeast = new AtLeast();8$atLeast->verify(4, 4, 4, 4, 4, 4);9$atLeast = new AtLeast();10$atLeast->verify(4, 4, 4, 4, 4, 4, 4);11$atLeast = new AtLeast();12$atLeast->verify(4, 4, 4, 4, 4, 4, 4, 4);13$atLeast = new AtLeast();14$atLeast->verify(4, 4, 4, 4, 4, 4, 4, 4, 4);15$atLeast = new AtLeast();16$atLeast->verify(4, 4, 4, 4, 4, 4, 4, 4, 4, 4);17$atLeast = new AtLeast();18$atLeast->verify(4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4);19$atLeast = new AtLeast();20$atLeast->verify(4, 4, 4, 4, 4, 4
verify
Using AI Code Generation
1$atLeast = new AtLeast();2$atLeast->verify(7, array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));3$atLeast = new AtLeast();4$atLeast->verify(7, array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));5$atLeast = new AtLeast();6$atLeast->verify(7, array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));7$atLeast = new AtLeast();8$atLeast->verify(7, array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));9$atLeast = new AtLeast();10$atLeast->verify(7, array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));11$atLeast = new AtLeast();12$atLeast->verify(7, array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));13$atLeast = new AtLeast();14$atLeast->verify(7, array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));15$atLeast = new AtLeast();16$atLeast->verify(7, array(1, 2, 3, 4, 5, 6, 7, 8, 9
verify
Using AI Code Generation
1$atLeast = new AtLeast();2$atLeast->verify(2, 5, 6, 7, 8, 9, 10);3$atLeast = new AtLeast();4$atLeast->verify(3, 5, 6, 7, 8, 9, 10);5$atLeast = new AtLeast();6$atLeast->verify(4, 5, 6, 7, 8, 9, 10);7$atLeast = new AtLeast();8$atLeast->verify(5, 5, 6, 7, 8, 9, 10);9$atLeast = new AtLeast();10$atLeast->verify(6, 5, 6, 7, 8, 9, 10);11$atLeast = new AtLeast();12$atLeast->verify(7, 5, 6, 7, 8, 9, 10);13$atLeast = new AtLeast();14$atLeast->verify(8, 5, 6, 7, 8, 9, 10);15$atLeast = new AtLeast();16$atLeast->verify(9, 5, 6, 7, 8, 9, 10);17$atLeast = new AtLeast();18$atLeast->verify(10, 5, 6, 7, 8, 9, 10);19$atLeast = new AtLeast();20$atLeast->verify(11, 5, 6, 7, 8, 9
verify
Using AI Code Generation
1$atleast = new AtLeast(2);2$atleast->add(1);3$atleast->add(2);4$atleast->add(3);5$atleast = new AtLeast(2);6$atleast->add(1);7$atleast->add(2);8$atleast = new AtLeast(2);9$atleast->add(1);10$atleast->add(2);11$atleast = new AtLeast(2);12$atleast->add(1);13$atleast->add(2);14$atleast->add(3);15$atleast = new AtLeast(2);16$atleast->add(1);17$atleast->add(2);18$atleast = new AtLeast(2);19$atleast->add(1);20$atleast->add(2);21$atleast->add(3);22$atleast = new AtLeast(2);23$atleast->add(1);24$atleast->add(2);25$atleast->add(3);26$atleast = new AtLeast(2);27$atleast->add(1);28$atleast->add(2);29$atleast->add(3);30$atleast = new AtLeast(2);31$atleast->add(1);32$atleast->add(2);
verify
Using AI Code Generation
1$atleast = new AtLeast(2);2$atleast->verify(array(1,2,3,4));3$atleast = new AtLeast(2);4$atleast->verify(array(1,2));5$atleast = new AtLeast(2);6$atleast->verify(array(1));7$atleast = new AtLeast(2);8$atleast->verify(array());9$atleast = new AtLeast(2);10$atleast->verify(array(1,2,3,4,5,6,7,8,9,10,11));11$atleast = new AtLeast(2);12$atleast->verify(array(1,2,3,4,5,6,7,8,9,10,11,12));13$atleast = new AtLeast(2);14$atleast->verify(array(1,2,3,4,5,6,7,8,9,10,11,12,13));15$atleast = new AtLeast(2);16$atleast->verify(array(1,2,3,4,5,6,7,8,9,10,11,12,13,14));17$atleast = new AtLeast(2);18$atleast->verify(array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15));19$atleast = new AtLeast(2);20$atleast->verify(array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16
verify
Using AI Code Generation
1include('AtLeast.php');2$atleast = new AtLeast();3$atleast->verify(2, 3);4echo $atleast->message;5include('AtLeast.php');6$atleast = new AtLeast();7$atleast->verify(3, 3);8echo $atleast->message;9include('AtLeast.php');10$atleast = new AtLeast();11$atleast->verify(4, 3);12echo $atleast->message;13include('AtLeast.php');14$atleast = new AtLeast();15$atleast->verify(5, 3);16echo $atleast->message;17include('AtLeast.php');18$atleast = new AtLeast();19$atleast->verify(6, 3);20echo $atleast->message;21include('AtLeast.php');22$atleast = new AtLeast();23$atleast->verify(7, 3);24echo $atleast->message;25include('AtLeast.php');26$atleast = new AtLeast();27$atleast->verify(8, 3);28echo $atleast->message;29include('AtLeast.php');30$atleast = new AtLeast();31$atleast->verify(9, 3);32echo $atleast->message;33include('AtLeast.php');34$atleast = new AtLeast();35$atleast->verify(10, 3);36echo $atleast->message;37include('AtLeast.php');38$atleast = new AtLeast();39$atleast->verify(11, 3);40echo $atleast->message;
verify
Using AI Code Generation
1$atLeast = new AtLeast();2$atLeast->verify(2, 1, 2, 3);3$atLeast = new AtLeast();4$atLeast->verify(2, 1, 2, 3);5$atLeast = new AtLeast();6$atLeast->verify(2, 1, 2, 3);7$atLeast = new AtLeast();8$atLeast->verify(2, 1, 2, 3);9$atLeast = new AtLeast();10$atLeast->verify(2, 1, 2, 3);11$atLeast = new AtLeast();12$atLeast->verify(2, 1, 2, 3);13$atLeast = new AtLeast();14$atLeast->verify(2, 1, 2, 3);15$atLeast = new AtLeast();16$atLeast->verify(2, 1, 2, 3);17$atLeast = new AtLeast();18$atLeast->verify(2, 1, 2, 3);19$atLeast = new AtLeast();20$atLeast->verify(2, 1, 2, 3);21$atLeast = new AtLeast();
verify
Using AI Code Generation
1if($atleast->verify($password))2{3 echo "Password is valid";4}5{6 echo "Password is not valid";7}
verify
Using AI Code Generation
1$atleast = new AtLeast();2if($atleast->verify($password) == false){3 echo "Your password is not strong enough";4}5$atleast = new AtLeast();6if($atleast->verify($password) == false){7 echo "Your password is not strong enough";8}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with verify on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!