How to use validate method of AtLeast class

Best Mockery code snippet using AtLeast.validate

RecurrenceControllerTest.php

Source:RecurrenceControllerTest.php Github

copy

Full Screen

...69 $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);70 $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);71 // mock calls to validator:72 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);73 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);74 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);75 // mock calls:76 $repository->shouldReceive('setUser')->atLeast()->once();77 $repository->shouldReceive('store')->once()->andReturn($recurrence);78 // data to submit79 $firstDate = new Carbon;80 $firstDate->addDays(2);81 $data = [82 'type' => 'withdrawal',83 'title' => 'Hello',84 'first_date' => $firstDate->format('Y-m-d'),85 'apply_rules' => 1,86 'active' => 1,87 'transactions' => [88 [89 'amount' => '100',90 'currency_id' => '1',91 'description' => 'Test description',92 'source_id' => '1',93 ],94 ],95 'repetitions' => [96 [97 'type' => 'daily',98 'moment' => '',99 'skip' => '0',100 'weekend' => '1',101 ],102 ],103 ];104 // test API105 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);106 $response->assertStatus(200);107 $response->assertHeader('Content-Type', 'application/vnd.api+json');108 }109 /**110 * Submit the minimum amount to store a recurring transaction (using source name field).111 *112 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController113 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest114 * @covers \FireflyIII\Api\V1\Requests\Request115 */116 public function testStoreAssetName(): void117 {118 /** @var Recurrence $recurrence */119 $recurrence = $this->user()->recurrences()->first();120 // mock stuff:121 $repository = $this->mock(RecurringRepositoryInterface::class);122 $transformer = $this->mock(RecurrenceTransformer::class);123 $validator = $this->mock(AccountValidator::class);124 // mock calls to transformer:125 $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();126 $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();127 $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);128 $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);129 $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);130 // mock calls to validator:131 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);132 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([0, 'Checking Account'])->andReturn(true);133 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);134 // mock calls:135 $repository->shouldReceive('setUser')->atLeast()->once();136 $repository->shouldReceive('store')->once()->andReturn($recurrence);137 // data to submit138 $firstDate = new Carbon;139 $firstDate->addDays(2);140 $data = [141 'type' => 'withdrawal',142 'title' => 'Hello',143 'first_date' => $firstDate->format('Y-m-d'),144 'apply_rules' => 1,145 'active' => 1,146 'transactions' => [147 [148 'amount' => '100',149 'currency_id' => '1',150 'description' => 'Test description',151 'source_name' => 'Checking Account',152 ],153 ],154 'repetitions' => [155 [156 'type' => 'daily',157 'moment' => '',158 'skip' => '0',159 'weekend' => '1',160 ],161 ],162 ];163 // test API164 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);165 $response->assertStatus(200);166 $response->assertHeader('Content-Type', 'application/vnd.api+json');167 }168 /**169 * Submit a deposit. Since most validators have been tested in other methods, dont bother too much.170 *171 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController172 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest173 * @covers \FireflyIII\Api\V1\Requests\Request174 */175 public function testStoreDeposit(): void176 {177 /** @var Recurrence $recurrence */178 $recurrence = $this->user()->recurrences()->first();179 // mock stuff:180 $repository = $this->mock(RecurringRepositoryInterface::class);181 $transformer = $this->mock(RecurrenceTransformer::class);182 $validator = $this->mock(AccountValidator::class);183 // mock calls to transformer:184 $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();185 $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();186 $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);187 $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);188 $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);189 // mock calls:190 $repository->shouldReceive('setUser')->atLeast()->once();191 $repository->shouldReceive('store')->once()->andReturn($recurrence);192 // mock calls to validator:193 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['deposit']);194 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([null, 'Some expense account'])->andReturn(true);195 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([1, null])->andReturn(true);196 // data to submit197 $firstDate = new Carbon;198 $firstDate->addDays(2);199 $data = [200 'type' => 'deposit',201 'title' => 'Hello',202 'first_date' => $firstDate->format('Y-m-d'),203 'apply_rules' => 1,204 'active' => 1,205 'transactions' => [206 [207 'amount' => '100',208 'currency_id' => '1',209 'description' => 'Test description deposit',210 'source_name' => 'Some expense account',211 'destination_id' => '1',212 ],213 ],214 'repetitions' => [215 [216 'type' => 'daily',217 'moment' => '',218 'skip' => '0',219 'weekend' => '1',220 ],221 ],222 ];223 // test API224 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);225 $response->assertStatus(200);226 $response->assertHeader('Content-Type', 'application/vnd.api+json');227 }228 /**229 * Add a recurring with correct reference to a destination (expense).230 *231 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController232 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest233 * @covers \FireflyIII\Api\V1\Requests\Request234 */235 public function testStoreDestinationId(): void236 {237 /** @var Recurrence $recurrence */238 $recurrence = $this->user()->recurrences()->first();239 // mock stuff:240 $repository = $this->mock(RecurringRepositoryInterface::class);241 $transformer = $this->mock(RecurrenceTransformer::class);242 $validator = $this->mock(AccountValidator::class);243 $expenseAccount = $this->getRandomExpense();244 // mock calls to transformer:245 $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();246 $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();247 $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);248 $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);249 $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);250 // mock calls:251 $repository->shouldReceive('setUser')->atLeast()->once();252 $repository->shouldReceive('store')->once()->andReturn($recurrence);253 // mock calls to validator:254 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);255 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);256 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([$expenseAccount->id, null])->andReturn(true);257 // data to submit258 $firstDate = new Carbon;259 $firstDate->addDays(2);260 $data = [261 'type' => 'withdrawal',262 'title' => 'Hello',263 'first_date' => $firstDate->format('Y-m-d'),264 'apply_rules' => 1,265 'active' => 1,266 'transactions' => [267 [268 'amount' => '100',269 'currency_id' => '1',270 'description' => 'Test description',271 'source_id' => '1',272 'destination_id' => $expenseAccount->id,273 ],274 ],275 'repetitions' => [276 [277 'type' => 'daily',278 'moment' => '',279 'skip' => '0',280 'weekend' => '1',281 ],282 ],283 ];284 // test API285 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);286 $response->assertStatus(200);287 $response->assertHeader('Content-Type', 'application/vnd.api+json');288 }289 /**290 * Add a recurring with correct reference to a destination (expense).291 *292 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController293 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest294 * @covers \FireflyIII\Api\V1\Requests\Request295 */296 public function testStoreDestinationName(): void297 {298 /** @var Recurrence $recurrence */299 $recurrence = $this->user()->recurrences()->first();300 // mock stuff:301 $repository = $this->mock(RecurringRepositoryInterface::class);302 $transformer = $this->mock(RecurrenceTransformer::class);303 $validator = $this->mock(AccountValidator::class);304 // mock calls to transformer:305 $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();306 $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();307 $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);308 $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);309 $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);310 $expenseAccount = $this->getRandomExpense();311 // mock calls to validator:312 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);313 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);314 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, $expenseAccount->name])->andReturn(true);315 // mock calls:316 $repository->shouldReceive('setUser')->atLeast()->once();317 $repository->shouldReceive('store')->once()->andReturn($recurrence);318 // data to submit319 $firstDate = new Carbon;320 $firstDate->addDays(2);321 $data = [322 'type' => 'withdrawal',323 'title' => 'Hello',324 'first_date' => $firstDate->format('Y-m-d'),325 'apply_rules' => 1,326 'active' => 1,327 'transactions' => [328 [329 'amount' => '100',330 'currency_id' => '1',331 'description' => 'Test description',332 'source_id' => '1',333 'destination_name' => $expenseAccount->name,334 ],335 ],336 'repetitions' => [337 [338 'type' => 'daily',339 'moment' => '',340 'skip' => '0',341 'weekend' => '1',342 ],343 ],344 ];345 // test API346 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);347 $response->assertStatus(200);348 $response->assertHeader('Content-Type', 'application/vnd.api+json');349 }350 /**351 * Includes both repetition count and an end date.352 *353 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController354 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest355 * @covers \FireflyIII\Api\V1\Requests\Request356 */357 public function testStoreFailBothRepetitions(): void358 {359 // mock stuff:360 $repository = $this->mock(RecurringRepositoryInterface::class);361 $validator = $this->mock(AccountValidator::class);362 // mock calls to validator:363 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);364 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);365 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);366 // mock calls:367 $repository->shouldReceive('setUser')->atLeast()->once();368 // data to submit369 $firstDate = new Carbon;370 $firstDate->addDays(2);371 $repeatUntil = new Carbon;372 $repeatUntil->addMonth();373 $data = [374 'type' => 'withdrawal',375 'title' => 'Hello',376 'first_date' => $firstDate->format('Y-m-d'),377 'repeat_until' => $repeatUntil->format('Y-m-d'),378 'nr_of_repetitions' => 10,379 'apply_rules' => 1,380 'active' => 1,381 'transactions' => [382 [383 'amount' => '100',384 'currency_id' => '1',385 'description' => 'Test description',386 'source_id' => '1',387 ],388 ],389 'repetitions' => [390 [391 'type' => 'daily',392 'moment' => '',393 'skip' => '0',394 'weekend' => '1',395 ],396 ],397 ];398 // test API399 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);400 $response->assertExactJson(401 [402 'message' => 'The given data was invalid.',403 'errors' => [404 'repeat_until' => [405 'Require either a number of repetitions, or an end date (repeat_until). Not both.',406 ],407 'nr_of_repetitions' => [408 'Require either a number of repetitions, or an end date (repeat_until). Not both.',409 ],410 ],411 ]412 );413 $response->assertStatus(422);414 $response->assertHeader('Content-Type', 'application/json');415 }416 /**417 * Submit foreign amount but no currency information.418 *419 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController420 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest421 * @covers \FireflyIII\Api\V1\Requests\Request422 */423 public function testStoreFailForeignCurrency(): void424 {425 // mock stuff:426 $repository = $this->mock(RecurringRepositoryInterface::class);427 $validator = $this->mock(AccountValidator::class);428 // mock calls to validator:429 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);430 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([null, 'Checking Account'])->andReturn(true);431 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);432 // mock calls:433 $repository->shouldReceive('setUser')->atLeast()->once();434 // data to submit435 $firstDate = new Carbon;436 $firstDate->addDays(2);437 $data = [438 'type' => 'withdrawal',439 'title' => 'Hello',440 'first_date' => $firstDate->format('Y-m-d'),441 'apply_rules' => 1,442 'active' => 1,443 'transactions' => [444 [445 'amount' => '100',446 'currency_id' => '1',447 'foreign_amount' => '100',448 'description' => 'Test description',449 'source_name' => 'Checking Account',450 ],451 ],452 'repetitions' => [453 [454 'type' => 'daily',455 'moment' => '',456 'skip' => '0',457 'weekend' => '1',458 ],459 ],460 ];461 // test API462 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);463 $response->assertExactJson(464 [465 'message' => 'The given data was invalid.',466 'errors' => [467 'transactions.0.foreign_amount' => [468 'The content of this field is invalid without currency information.',469 ],470 ],471 ]472 );473 $response->assertStatus(422);474 $response->assertHeader('Content-Type', 'application/json');475 }476 /**477 * Submit the minimum amount to store a recurring transaction (using source ID field).478 *479 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController480 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest481 * @covers \FireflyIII\Api\V1\Requests\Request482 */483 public function testStoreFailInvalidDaily(): void484 {485 // mock stuff:486 $repository = $this->mock(RecurringRepositoryInterface::class);487 $validator = $this->mock(AccountValidator::class);488 // mock calls to validator:489 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);490 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);491 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);492 // mock calls:493 $repository->shouldReceive('setUser')->atLeast()->once();494 // data to submit495 $firstDate = new Carbon;496 $firstDate->addDays(2);497 $data = [498 'type' => 'withdrawal',499 'title' => 'Hello',500 'first_date' => $firstDate->format('Y-m-d'),501 'apply_rules' => 1,502 'active' => 1,503 'transactions' => [504 [505 'amount' => '100',506 'currency_id' => '1',507 'description' => 'Test description',508 'source_id' => '1',509 ],510 ],511 'repetitions' => [512 [513 'type' => 'daily',514 'moment' => '1',515 'skip' => '0',516 'weekend' => '1',517 ],518 ],519 ];520 // test API521 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);522 $response->assertExactJson(523 [524 'message' => 'The given data was invalid.',525 'errors' => [526 'repetitions.0.moment' => [527 'Invalid repetition moment for this type of repetition.',528 ],529 ],530 ]531 );532 $response->assertStatus(422);533 $response->assertHeader('Content-Type', 'application/json');534 }535 /**536 * Add a recurring but refer to an asset as destination.537 *538 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController539 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest540 * @covers \FireflyIII\Api\V1\Requests\Request541 */542 public function testStoreFailInvalidDestinationId(): void543 {544 // mock stuff:545 $repository = $this->mock(RecurringRepositoryInterface::class);546 $validator = $this->mock(AccountValidator::class);547 $assetAccount = $this->getRandomAsset();548 // mock calls to validator:549 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);550 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([$assetAccount->id, null])->andReturn(true);551 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([$assetAccount->id, null])->andReturn(false);552 // mock calls:553 $repository->shouldReceive('setUser')->atLeast()->once();554 // data to submit555 $firstDate = new Carbon;556 $firstDate->addDays(2);557 $data = [558 'type' => 'withdrawal',559 'title' => 'Hello',560 'first_date' => $firstDate->format('Y-m-d'),561 'apply_rules' => 1,562 'active' => 1,563 'transactions' => [564 [565 'amount' => '100',566 'currency_id' => '1',567 'description' => 'Test description',568 'source_id' => $assetAccount->id,569 'destination_id' => $assetAccount->id,570 ],571 ],572 'repetitions' => [573 [574 'type' => 'daily',575 'moment' => '',576 'skip' => '0',577 'weekend' => '1',578 ],579 ],580 ];581 // test API582 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);583 $response->assertExactJson(584 [585 'message' => 'The given data was invalid.',586 'errors' => [587 'transactions.0.destination_id' => [588 null,589 ],590 'transactions.0.destination_name' => [591 null,592 ],593 ],594 ]595 );596 $response->assertStatus(422);597 $response->assertHeader('Content-Type', 'application/json');598 }599 /**600 * Submit the minimum amount to store a recurring transaction (using source ID field).601 *602 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController603 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest604 * @covers \FireflyIII\Api\V1\Requests\Request605 */606 public function testStoreFailInvalidMonthly(): void607 {608 // mock stuff:609 $repository = $this->mock(RecurringRepositoryInterface::class);610 $validator = $this->mock(AccountValidator::class);611 // mock calls:612 $repository->shouldReceive('setUser')->atLeast()->once();613 // mock calls to validator:614 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);615 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);616 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);617 // data to submit618 $firstDate = new Carbon;619 $firstDate->addDays(2);620 $data = [621 'type' => 'withdrawal',622 'title' => 'Hello',623 'first_date' => $firstDate->format('Y-m-d'),624 'apply_rules' => 1,625 'active' => 1,626 'transactions' => [627 [628 'amount' => '100',629 'currency_id' => '1',630 'description' => 'Test description',631 'source_id' => '1',632 ],633 ],634 'repetitions' => [635 [636 'type' => 'monthly',637 'moment' => '32',638 'skip' => '0',639 'weekend' => '1',640 ],641 ],642 ];643 // test API644 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);645 $response->assertExactJson(646 [647 'message' => 'The given data was invalid.',648 'errors' => [649 'repetitions.0.moment' => [650 'Invalid repetition moment for this type of repetition.',651 ],652 ],653 ]654 );655 $response->assertStatus(422);656 $response->assertHeader('Content-Type', 'application/json');657 }658 /**659 * Submit the minimum amount to store a recurring transaction (using source ID field).660 *661 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController662 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest663 * @covers \FireflyIII\Api\V1\Requests\Request664 */665 public function testStoreFailInvalidNdom(): void666 {667 // mock stuff:668 $repository = $this->mock(RecurringRepositoryInterface::class);669 $validator = $this->mock(AccountValidator::class);670 // mock calls to validator:671 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);672 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);673 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);674 // mock calls:675 $repository->shouldReceive('setUser')->atLeast()->once();676 // data to submit677 $firstDate = new Carbon;678 $firstDate->addDays(2);679 $data = [680 'type' => 'withdrawal',681 'title' => 'Hello',682 'first_date' => $firstDate->format('Y-m-d'),683 'apply_rules' => 1,684 'active' => 1,685 'transactions' => [686 [687 'amount' => '100',688 'currency_id' => '1',689 'description' => 'Test description',690 'source_id' => '1',691 ],692 ],693 'repetitions' => [694 [695 'type' => 'ndom',696 'moment' => '9,9',697 'skip' => '0',698 'weekend' => '1',699 ],700 ],701 ];702 // test API703 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);704 $response->assertExactJson(705 [706 'message' => 'The given data was invalid.',707 'errors' => [708 'repetitions.0.moment' => [709 'Invalid repetition moment for this type of repetition.',710 ],711 ],712 ]713 );714 $response->assertStatus(422);715 $response->assertHeader('Content-Type', 'application/json');716 }717 /**718 * Submit the minimum amount to store a recurring transaction (using source ID field).719 *720 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController721 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest722 * @covers \FireflyIII\Api\V1\Requests\Request723 */724 public function testStoreFailInvalidNdomCount(): void725 {726 // mock stuff:727 $repository = $this->mock(RecurringRepositoryInterface::class);728 $validator = $this->mock(AccountValidator::class);729 // mock calls to validator:730 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);731 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);732 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);733 // mock calls:734 $repository->shouldReceive('setUser')->atLeast()->once();735 // data to submit736 $firstDate = new Carbon;737 $firstDate->addDays(2);738 $data = [739 'type' => 'withdrawal',740 'title' => 'Hello',741 'first_date' => $firstDate->format('Y-m-d'),742 'apply_rules' => 1,743 'active' => 1,744 'transactions' => [745 [746 'amount' => '100',747 'currency_id' => '1',748 'description' => 'Test description',749 'source_id' => '1',750 ],751 ],752 'repetitions' => [753 [754 'type' => 'ndom',755 'moment' => '9',756 'skip' => '0',757 'weekend' => '1',758 ],759 ],760 ];761 // test API762 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);763 $response->assertExactJson(764 [765 'message' => 'The given data was invalid.',766 'errors' => [767 'repetitions.0.moment' => [768 'Invalid repetition moment for this type of repetition.',769 ],770 ],771 ]772 );773 $response->assertStatus(422);774 $response->assertHeader('Content-Type', 'application/json');775 }776 /**777 * Submit the minimum amount to store a recurring transaction (using source ID field).778 *779 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController780 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest781 * @covers \FireflyIII\Api\V1\Requests\Request782 */783 public function testStoreFailInvalidNdomHigh(): void784 {785 // mock stuff:786 $repository = $this->mock(RecurringRepositoryInterface::class);787 $validator = $this->mock(AccountValidator::class);788 // mock calls:789 $repository->shouldReceive('setUser')->atLeast()->once();790 // mock calls to validator:791 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);792 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);793 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);794 // data to submit795 $firstDate = new Carbon;796 $firstDate->addDays(2);797 $data = [798 'type' => 'withdrawal',799 'title' => 'Hello',800 'first_date' => $firstDate->format('Y-m-d'),801 'apply_rules' => 1,802 'active' => 1,803 'transactions' => [804 [805 'amount' => '100',806 'currency_id' => '1',807 'description' => 'Test description',808 'source_id' => '1',809 ],810 ],811 'repetitions' => [812 [813 'type' => 'ndom',814 'moment' => '4,9',815 'skip' => '0',816 'weekend' => '1',817 ],818 ],819 ];820 // test API821 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);822 $response->assertExactJson(823 [824 'message' => 'The given data was invalid.',825 'errors' => [826 'repetitions.0.moment' => [827 'Invalid repetition moment for this type of repetition.',828 ],829 ],830 ]831 );832 $response->assertStatus(422);833 $response->assertHeader('Content-Type', 'application/json');834 }835 /**836 * Submit the minimum amount to store a recurring transaction (using source ID field).837 *838 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController839 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest840 * @covers \FireflyIII\Api\V1\Requests\Request841 */842 public function testStoreFailInvalidWeekly(): void843 {844 // mock stuff:845 $repository = $this->mock(RecurringRepositoryInterface::class);846 $validator = $this->mock(AccountValidator::class);847 // mock calls to validator:848 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);849 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);850 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);851 // mock calls:852 $repository->shouldReceive('setUser')->atLeast()->once();853 // data to submit854 $firstDate = new Carbon;855 $firstDate->addDays(2);856 $data = [857 'type' => 'withdrawal',858 'title' => 'Hello',859 'first_date' => $firstDate->format('Y-m-d'),860 'apply_rules' => 1,861 'active' => 1,862 'transactions' => [863 [864 'amount' => '100',865 'currency_id' => '1',866 'description' => 'Test description',867 'source_id' => '1',868 ],869 ],870 'repetitions' => [871 [872 'type' => 'weekly',873 'moment' => '8',874 'skip' => '0',875 'weekend' => '1',876 ],877 ],878 ];879 // test API880 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);881 $response->assertExactJson(882 [883 'message' => 'The given data was invalid.',884 'errors' => [885 'repetitions.0.moment' => [886 'Invalid repetition moment for this type of repetition.',887 ],888 ],889 ]890 );891 $response->assertStatus(422);892 $response->assertHeader('Content-Type', 'application/json');893 }894 /**895 * Submit without a source account.896 *897 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController898 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest899 * @covers \FireflyIII\Api\V1\Requests\Request900 */901 public function testStoreFailNoAsset(): void902 {903 // mock stuff:904 $repository = $this->mock(RecurringRepositoryInterface::class);905 $validator = $this->mock(AccountValidator::class);906 // mock calls to validator:907 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);908 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([0, null])->andReturn(false);909 // mock calls:910 $repository->shouldReceive('setUser')->atLeast()->once();911 // data to submit912 $firstDate = new Carbon;913 $firstDate->addDays(2);914 $data = [915 'type' => 'withdrawal',916 'title' => 'Hello',917 'first_date' => $firstDate->format('Y-m-d'),918 'apply_rules' => 1,919 'active' => 1,920 'transactions' => [921 [922 'amount' => '100',923 'currency_id' => '1',924 'description' => 'Test description',925 'source_id' => '0',926 ],927 ],928 'repetitions' => [929 [930 'type' => 'daily',931 'moment' => '',932 'skip' => '0',933 'weekend' => '1',934 ],935 ],936 ];937 // test API938 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);939 $response->assertExactJson(940 [941 'message' => 'The given data was invalid.',942 'errors' => [943 'transactions.0.source_id' => [944 null,945 ],946 'transactions.0.source_name' => [947 null,948 ],949 ],950 ]951 );952 $response->assertStatus(422);953 $response->assertHeader('Content-Type', 'application/json');954 }955 /**956 * Submit with an expense account.957 *958 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController959 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest960 * @covers \FireflyIII\Api\V1\Requests\Request961 */962 public function testStoreFailNotAsset(): void963 {964 // expense account:965 $expenseAccount = $this->getRandomExpense();966 // mock stuff:967 $repository = $this->mock(RecurringRepositoryInterface::class);968 $validator = $this->mock(AccountValidator::class);969 // mock calls:970 $repository->shouldReceive('setUser')->atLeast()->once();971 // mock calls to validator:972 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);973 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([$expenseAccount->id, null])->andReturn(false);974 // data to submit975 $firstDate = new Carbon;976 $firstDate->addDays(2);977 $data = [978 'type' => 'withdrawal',979 'title' => 'Hello',980 'first_date' => $firstDate->format('Y-m-d'),981 'apply_rules' => 1,982 'active' => 1,983 'transactions' => [984 [985 'amount' => '100',986 'currency_id' => '1',987 'description' => 'Test description',988 'source_id' => $expenseAccount->id,989 ],990 ],991 'repetitions' => [992 [993 'type' => 'daily',994 'moment' => '',995 'skip' => '0',996 'weekend' => '1',997 ],998 ],999 ];1000 // test API1001 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);1002 $response->assertExactJson(1003 [1004 'message' => 'The given data was invalid.',1005 'errors' => [1006 'transactions.0.source_id' => [1007 null,1008 ],1009 'transactions.0.source_name' => [1010 null,1011 ],1012 ],1013 ]1014 );1015 $response->assertStatus(422);1016 $response->assertHeader('Content-Type', 'application/json');1017 }1018 /**1019 * Submit with an invalid asset account name.1020 *1021 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController1022 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest1023 * @covers \FireflyIII\Api\V1\Requests\Request1024 */1025 public function testStoreFailNotAssetName(): void1026 {1027 // mock stuff:1028 $repository = $this->mock(RecurringRepositoryInterface::class);1029 $validator = $this->mock(AccountValidator::class);1030 // mock calls:1031 $repository->shouldReceive('setUser')->atLeast()->once();1032 // mock calls to validator:1033 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);1034 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([0, 'Fake name'])->andReturn(false);1035 // data to submit1036 $firstDate = new Carbon;1037 $firstDate->addDays(2);1038 $data = [1039 'type' => 'withdrawal',1040 'title' => 'Hello',1041 'first_date' => $firstDate->format('Y-m-d'),1042 'apply_rules' => 1,1043 'active' => 1,1044 'transactions' => [1045 [1046 'amount' => '100',1047 'currency_id' => '1',1048 'description' => 'Test description',1049 'source_name' => 'Fake name',1050 'source_id' => '0',1051 ],1052 ],1053 'repetitions' => [1054 [1055 'type' => 'daily',1056 'moment' => '',1057 'skip' => '0',1058 'weekend' => '1',1059 ],1060 ],1061 ];1062 // test API1063 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);1064 $response->assertExactJson(1065 [1066 'message' => 'The given data was invalid.',1067 'errors' => [1068 'transactions.0.source_id' => [1069 null,1070 ],1071 'transactions.0.source_name' => [1072 null,1073 ],1074 ],1075 ]1076 );1077 $response->assertStatus(422);1078 $response->assertHeader('Content-Type', 'application/json');1079 }1080 /**1081 * Dont include enough repetitions.1082 *1083 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController1084 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest1085 * @covers \FireflyIII\Api\V1\Requests\Request1086 */1087 public function testStoreFailRepetitions(): void1088 {1089 // mock stuff:1090 $repository = $this->mock(RecurringRepositoryInterface::class);1091 $validator = $this->mock(AccountValidator::class);1092 // mock calls:1093 $repository->shouldReceive('setUser')->atLeast()->once();1094 // mock calls to validator:1095 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['withdrawal']);1096 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([1, null])->andReturn(true);1097 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([null, null])->andReturn(true);1098 // data to submit1099 $firstDate = new Carbon;1100 $firstDate->addDays(2);1101 $data = [1102 'type' => 'withdrawal',1103 'title' => 'Hello',1104 'first_date' => $firstDate->format('Y-m-d'),1105 'apply_rules' => 1,1106 'active' => 1,1107 'transactions' => [1108 [1109 'amount' => '100',1110 'currency_id' => '1',1111 'description' => 'Test description',1112 'source_id' => '1',1113 ],1114 ],1115 'repetitions' => [],1116 ];1117 // test API1118 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);1119 $response->assertExactJson(1120 [1121 'message' => 'The given data was invalid.',1122 'errors' => [1123 'repetitions' => [1124 'Need at least one repetition.',1125 ],1126 ],1127 ]1128 );1129 $response->assertStatus(422);1130 $response->assertHeader('Content-Type', 'application/json');1131 }1132 /**1133 * Dont include enough repetitions.1134 *1135 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController1136 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest1137 * @covers \FireflyIII\Api\V1\Requests\Request1138 */1139 public function testStoreFailTransactions(): void1140 {1141 // mock stuff:1142 $repository = $this->mock(RecurringRepositoryInterface::class);1143 $this->mock(AccountValidator::class);1144 // mock calls:1145 $repository->shouldReceive('setUser')->atLeast()->once();1146 // data to submit1147 $firstDate = new Carbon;1148 $firstDate->addDays(2);1149 $data = [1150 'type' => 'withdrawal',1151 'title' => 'Hello',1152 'first_date' => $firstDate->format('Y-m-d'),1153 'apply_rules' => 1,1154 'active' => 1,1155 'transactions' => [1156 ],1157 'repetitions' => [1158 [1159 'type' => 'daily',1160 'moment' => '',1161 'skip' => '0',1162 'weekend' => '1',1163 ],1164 ],1165 ];1166 // test API1167 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);1168 $response->assertExactJson(1169 [1170 'message' => 'The given data was invalid.',1171 'errors' => [1172 'transactions' => [1173 'Need at least one transaction.',1174 ],1175 ],1176 ]1177 );1178 $response->assertStatus(422);1179 $response->assertHeader('Content-Type', 'application/json');1180 }1181 /**1182 * Submit a transfer. Since most validators have been tested in other methods, dont bother too much.1183 *1184 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController1185 * @covers \FireflyIII\Api\V1\Requests\RecurrenceStoreRequest1186 * @covers \FireflyIII\Api\V1\Requests\Request1187 */1188 public function testStoreTransfer(): void1189 {1190 /** @var Recurrence $recurrence */1191 $recurrence = $this->user()->recurrences()->first();1192 // mock stuff:1193 $repository = $this->mock(RecurringRepositoryInterface::class);1194 $transformer = $this->mock(RecurrenceTransformer::class);1195 $validator = $this->mock(AccountValidator::class);1196 $assetAccount = $this->getRandomAsset();1197 $otherAssetAccount = $this->getRandomAsset($assetAccount->id);1198 // mock calls to transformer:1199 $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();1200 $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();1201 $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);1202 $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);1203 $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);1204 // mock calls to validator:1205 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['transfer']);1206 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([$assetAccount->id, null])->andReturn(true);1207 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([$otherAssetAccount->id, null])->andReturn(true);1208 // mock calls:1209 $repository->shouldReceive('setUser')->atLeast()->once();1210 $repository->shouldReceive('store')->once()->andReturn($recurrence);1211 // data to submit1212 $firstDate = new Carbon;1213 $firstDate->addDays(2);1214 $data = [1215 'type' => 'transfer',1216 'title' => 'Hello',1217 'first_date' => $firstDate->format('Y-m-d'),1218 'apply_rules' => 1,1219 'active' => 1,1220 'transactions' => [1221 [1222 'amount' => '100',1223 'currency_id' => '1',1224 'description' => 'Test description transfer',1225 'source_id' => $assetAccount->id,1226 'destination_id' => $otherAssetAccount->id,1227 ],1228 ],1229 'repetitions' => [1230 [1231 'type' => 'daily',1232 'moment' => '',1233 'skip' => '0',1234 'weekend' => '1',1235 ],1236 ],1237 ];1238 // test API1239 $response = $this->post(route('api.v1.recurrences.store'), $data, ['Accept' => 'application/json']);1240 $response->assertStatus(200);1241 $response->assertHeader('Content-Type', 'application/vnd.api+json');1242 }1243 /**1244 * Just a basic test because the store() tests cover everything.1245 *1246 * @covers \FireflyIII\Api\V1\Controllers\RecurrenceController1247 * @covers \FireflyIII\Api\V1\Requests\RecurrenceUpdateRequest1248 * @covers \FireflyIII\Api\V1\Requests\Request1249 */1250 public function testUpdate(): void1251 {1252 /** @var Recurrence $recurrence */1253 $recurrence = $this->user()->recurrences()->first();1254 // mock stuff:1255 $repository = $this->mock(RecurringRepositoryInterface::class);1256 $transformer = $this->mock(RecurrenceTransformer::class);1257 $validator = $this->mock(AccountValidator::class);1258 // mock calls to transformer:1259 $transformer->shouldReceive('setParameters')->withAnyArgs()->atLeast()->once();1260 $transformer->shouldReceive('setCurrentScope')->withAnyArgs()->atLeast()->once()->andReturnSelf();1261 $transformer->shouldReceive('getDefaultIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);1262 $transformer->shouldReceive('getAvailableIncludes')->withAnyArgs()->atLeast()->once()->andReturn([]);1263 $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 5]);1264 // mock calls to validator:1265 $validator->shouldReceive('setTransactionType')->atLeast()->once()->withArgs(['deposit']);1266 $validator->shouldReceive('validateSource')->atLeast()->once()->withArgs([null, 'Some expense account'])->andReturn(true);1267 $validator->shouldReceive('validateDestination')->atLeast()->once()->withArgs([1, null])->andReturn(true);1268 // mock calls:1269 $repository->shouldReceive('setUser')->atLeast()->once();1270 $repository->shouldReceive('update')->once()->andReturn($recurrence);1271 // data to submit1272 $firstDate = new Carbon;1273 $firstDate->addDays(2);1274 $data = [1275 'type' => 'deposit',1276 'title' => 'Hello',1277 'first_date' => $firstDate->format('Y-m-d'),1278 'apply_rules' => 1,1279 'active' => 1,1280 'transactions' => [1281 [...

Full Screen

Full Screen

TransactionControllerTest.php

Source:TransactionControllerTest.php Github

copy

Full Screen

...70 $repository->shouldReceive('setUser')->atLeast()->once();71 $apiRepos->shouldReceive('setUser')->atLeast()->once();72 // validator:73 $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();74 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);75 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);76 $data = [77 'transactions' => [78 [79 'description' => '',80 'date' => '2018-01-01',81 'type' => 'withdrawal',82 'amount' => '10',83 'source_id' => $source->id,84 ],85 ],86 ];87 // test API88 $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);89 $response->assertStatus(422);90 $response->assertExactJson(91 [92 'errors' => [93 'transactions.0.description' => ['The description field is required.'],94 ],95 'message' => 'The given data was invalid.',96 ]97 );98 }99 /**100 * Fail the valid destination information test.101 *102 * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest103 * @covers \FireflyIII\Api\V1\Controllers\TransactionController104 */105 public function testStoreFailDestination(): void106 {107 // mock data:108 $source = $this->getRandomAsset();109 // mock repository110 $repository = $this->mock(TransactionGroupRepositoryInterface::class);111 $journalRepos = $this->mock(JournalRepositoryInterface::class);112 $validator = $this->mock(AccountValidator::class);113 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);114 // some mock calls:115 $journalRepos->shouldReceive('setUser')->atLeast()->once();116 $repository->shouldReceive('setUser')->atLeast()->once();117 $apiRepos->shouldReceive('setUser')->atLeast()->once();118 // validator:119 $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();120 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);121 /** fail destination */122 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(false)123 ->andSet('destError', 'Some error');124 $data = [125 'transactions' => [126 [127 'description' => 'Fails anyway',128 'date' => '2018-01-01',129 'type' => 'withdrawal',130 'amount' => '10',131 'source_id' => $source->id,132 ],133 ],134 ];135 // test API136 $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);137 $response->assertStatus(422);138 $response->assertExactJson(139 [140 'errors' => [141 'transactions.0.destination_id' => ['Some error'],142 'transactions.0.destination_name' => ['Some error'],143 ],144 'message' => 'The given data was invalid.',145 ]146 );147 }148 /**149 * Submit foreign currency info, but no foreign currency amount.150 *151 * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest152 * @covers \FireflyIII\Api\V1\Controllers\TransactionController153 */154 public function testStoreFailForeignCurrencyAmount(): void155 {156 // mock data:157 $source = $this->getRandomAsset();158 // mock repository159 $repository = $this->mock(TransactionGroupRepositoryInterface::class);160 $journalRepos = $this->mock(JournalRepositoryInterface::class);161 $validator = $this->mock(AccountValidator::class);162 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);163 // some mock calls:164 $journalRepos->shouldReceive('setUser')->atLeast()->once();165 $repository->shouldReceive('setUser')->atLeast()->once();166 $apiRepos->shouldReceive('setUser')->atLeast()->once();167 // validator:168 $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();169 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);170 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);171 $data = [172 'transactions' => [173 [174 'description' => 'Test',175 'date' => '2018-01-01',176 'type' => 'withdrawal',177 'amount' => '10',178 'foreign_currency_code' => 'USD',179 'source_id' => $source->id,180 ],181 ],182 ];183 // test API184 $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);185 $response->assertStatus(422);186 $response->assertExactJson(187 [188 'errors' => [189 'transactions.0.foreign_amount' => ['The content of this field is invalid without foreign amount information.'],190 ],191 'message' => 'The given data was invalid.',192 ]193 );194 }195 /**196 * Submit foreign currency, but no foreign currency info.197 *198 * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest199 * @covers \FireflyIII\Api\V1\Controllers\TransactionController200 */201 public function testStoreFailForeignCurrencyInfo(): void202 {203 // mock data:204 $source = $this->getRandomAsset();205 // mock repository206 $repository = $this->mock(TransactionGroupRepositoryInterface::class);207 $journalRepos = $this->mock(JournalRepositoryInterface::class);208 $validator = $this->mock(AccountValidator::class);209 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);210 // some mock calls:211 $journalRepos->shouldReceive('setUser')->atLeast()->once();212 $repository->shouldReceive('setUser')->atLeast()->once();213 $apiRepos->shouldReceive('setUser')->atLeast()->once();214 // validator:215 $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();216 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);217 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);218 $data = [219 'transactions' => [220 [221 'description' => 'Test',222 'date' => '2018-01-01',223 'type' => 'withdrawal',224 'amount' => '10',225 'foreign_amount' => '11',226 'source_id' => $source->id,227 ],228 ],229 ];230 // test API231 $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);232 $response->assertStatus(422);233 $response->assertExactJson(234 [235 'errors' => [236 'transactions.0.foreign_amount' => ['The content of this field is invalid without currency information.'],237 ],238 'message' => 'The given data was invalid.',239 ]240 );241 }242 /**243 * Fail the valid source information test.244 *245 * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest246 * @covers \FireflyIII\Api\V1\Controllers\TransactionController247 */248 public function testStoreFailSource(): void249 {250 // mock data:251 $source = $this->getRandomAsset();252 // mock repository253 $repository = $this->mock(TransactionGroupRepositoryInterface::class);254 $journalRepos = $this->mock(JournalRepositoryInterface::class);255 $validator = $this->mock(AccountValidator::class);256 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);257 // some mock calls:258 $journalRepos->shouldReceive('setUser')->atLeast()->once();259 $repository->shouldReceive('setUser')->atLeast()->once();260 $apiRepos->shouldReceive('setUser')->atLeast()->once();261 // validator:262 $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();263 /** source info returns FALSE **/264 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(false)265 ->andSet('sourceError', 'Some error');266 $data = [267 'transactions' => [268 [269 'description' => 'Some withdrawal ',270 'date' => '2018-01-01',271 'type' => 'withdrawal',272 'amount' => '10',273 'source_id' => $source->id,274 ],275 ],276 ];277 // test API278 $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);279 $response->assertStatus(422);280 $response->assertExactJson(281 [282 'errors' => [283 'transactions.0.source_id' => ['Some error'],284 'transactions.0.source_name' => ['Some error'],285 ],286 'message' => 'The given data was invalid.',287 ]288 );289 }290 /**291 * Submit multiple transactions but no group title.292 *293 * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest294 * @covers \FireflyIII\Api\V1\Controllers\TransactionController295 */296 public function testStoreFailStoreGroupTitle(): void297 {298 // mock data:299 $source = $this->getRandomAsset();300 // mock repository301 $repository = $this->mock(TransactionGroupRepositoryInterface::class);302 $journalRepos = $this->mock(JournalRepositoryInterface::class);303 $validator = $this->mock(AccountValidator::class);304 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);305 // some mock calls:306 $journalRepos->shouldReceive('setUser')->atLeast()->once();307 $repository->shouldReceive('setUser')->atLeast()->once();308 $apiRepos->shouldReceive('setUser')->atLeast()->once();309 // validator:310 $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();311 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);312 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);313 $data = [314 'transactions' => [315 [316 'description' => 'Some description',317 'date' => '2018-01-01',318 'type' => 'withdrawal',319 'amount' => '10',320 'source_id' => $source->id,321 ],322 [323 'description' => 'Some description',324 'date' => '2018-01-01',325 'type' => 'withdrawal',326 'amount' => '10',327 'source_id' => $source->id,328 ],329 ],330 ];331 // test API332 $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);333 $response->assertStatus(422);334 $response->assertExactJson(335 [336 'errors' => [337 'group_title' => ['A group title is mandatory when there is more than one transaction.'],338 ],339 'message' => 'The given data was invalid.',340 ]341 );342 }343 /**344 * Submit multiple transactions but no group title.345 *346 * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest347 * @covers \FireflyIII\Api\V1\Controllers\TransactionController348 */349 public function testStoreFailStoreNoTransactions(): void350 {351 // mock repository352 $repository = $this->mock(TransactionGroupRepositoryInterface::class);353 $journalRepos = $this->mock(JournalRepositoryInterface::class);354 $this->mock(AccountValidator::class);355 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);356 // some mock calls:357 $journalRepos->shouldReceive('setUser')->atLeast()->once();358 $repository->shouldReceive('setUser')->atLeast()->once();359 $apiRepos->shouldReceive('setUser')->atLeast()->once();360 $data = [361 'transactions' => [362 ],363 ];364 // test API365 $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);366 $response->assertStatus(422);367 $response->assertExactJson(368 [369 'errors' => [370 'transactions.0.description' => ['Need at least one transaction.', 'The description field is required.'],371 'transactions.0.type' => ['Invalid transaction type.'],372 ],373 'message' => 'The given data was invalid.',374 ]375 );376 }377 /**378 * Try to submit different transaction types for a withdrawal.379 *380 * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest381 * @covers \FireflyIII\Api\V1\Controllers\TransactionController382 */383 public function testStoreFailTypes(): void384 {385 // mock data:386 $source = $this->getRandomAsset();387 // mock repository388 $repository = $this->mock(TransactionGroupRepositoryInterface::class);389 $journalRepos = $this->mock(JournalRepositoryInterface::class);390 $validator = $this->mock(AccountValidator::class);391 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);392 // some mock calls:393 $journalRepos->shouldReceive('setUser')->atLeast()->once();394 $repository->shouldReceive('setUser')->atLeast()->once();395 $apiRepos->shouldReceive('setUser')->atLeast()->once();396 // validator:397 $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();398 $validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();399 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);400 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);401 $data = [402 'group_title' => 'Hi there',403 'transactions' => [404 [405 'description' => 'Some description',406 'date' => '2018-01-01',407 'type' => 'withdrawal',408 'amount' => '10',409 'source_id' => $source->id,410 ],411 [412 'description' => 'Some description',413 'date' => '2018-01-01',414 'type' => 'deposit',415 'amount' => '10',416 'destination_id' => $source->id,417 ],418 ],419 ];420 // test API421 $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);422 $response->assertStatus(422);423 $response->assertExactJson(424 [425 'errors' => [426 'transactions.0.source_id' => ['All accounts in this field must be equal.'],427 'transactions.0.type' => ['All splits must be of the same type.'],428 ],429 'message' => 'The given data was invalid.',430 ]431 );432 }433 /**434 * Try to submit different transaction types for a deposit.435 *436 * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest437 * @covers \FireflyIII\Api\V1\Controllers\TransactionController438 */439 public function testStoreFailTypesDeposit(): void440 {441 // mock data:442 $source = $this->getRandomAsset();443 // mock repository444 $repository = $this->mock(TransactionGroupRepositoryInterface::class);445 $journalRepos = $this->mock(JournalRepositoryInterface::class);446 $validator = $this->mock(AccountValidator::class);447 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);448 // some mock calls:449 $journalRepos->shouldReceive('setUser')->atLeast()->once();450 $repository->shouldReceive('setUser')->atLeast()->once();451 $apiRepos->shouldReceive('setUser')->atLeast()->once();452 // validator:453 $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();454 $validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();455 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);456 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);457 $data = [458 'group_title' => 'Hi there',459 'transactions' => [460 [461 'description' => 'Some description',462 'date' => '2018-01-01',463 'type' => 'deposit',464 'amount' => '10',465 'destination_id' => $source->id,466 ],467 [468 'description' => 'Some description',469 'date' => '2018-01-01',470 'type' => 'withdrawal',471 'amount' => '10',472 'source_id' => $source->id,473 ],474 ],475 ];476 // test API477 $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);478 $response->assertStatus(422);479 $response->assertExactJson(480 [481 'errors' => [482 'transactions.0.destination_id' => ['All accounts in this field must be equal.'],483 'transactions.0.type' => ['All splits must be of the same type.'],484 ],485 'message' => 'The given data was invalid.',486 ]487 );488 }489 /**490 * Try to submit different transaction types for a transfer.491 *492 * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest493 * @covers \FireflyIII\Api\V1\Controllers\TransactionController494 */495 public function testStoreFailTypesTransfer(): void496 {497 // mock data:498 $source = $this->getRandomAsset();499 $dest = $this->getRandomAsset($source->id);500 // mock repository501 $repository = $this->mock(TransactionGroupRepositoryInterface::class);502 $journalRepos = $this->mock(JournalRepositoryInterface::class);503 $validator = $this->mock(AccountValidator::class);504 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);505 // some mock calls:506 $journalRepos->shouldReceive('setUser')->atLeast()->once();507 $repository->shouldReceive('setUser')->atLeast()->once();508 $apiRepos->shouldReceive('setUser')->atLeast()->once();509 // validator:510 $validator->shouldReceive('setTransactionType')->withArgs(['transfer'])->atLeast()->once();511 $validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();512 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);513 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);514 $data = [515 'group_title' => 'Hi there',516 'transactions' => [517 [518 'description' => 'Some description',519 'date' => '2018-01-01',520 'type' => 'transfer',521 'amount' => '10',522 'destination_id' => $source->id,523 'source_id' => $dest->id,524 ],525 [526 'description' => 'Some description',527 'date' => '2018-01-01',528 'type' => 'deposit',529 'amount' => '10',530 'destination_id' => $dest->id,531 'source_id' => $source->id,532 ],533 ],534 ];535 // test API536 $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);537 $response->assertStatus(422);538 $response->assertExactJson(539 [540 'errors' => [541 'transactions.0.destination_id' => ['All accounts in this field must be equal.'],542 'transactions.0.source_id' => ['All accounts in this field must be equal.'],543 'transactions.0.type' => ['All splits must be of the same type.'],544 ],545 'message' => 'The given data was invalid.',546 ]547 );548 }549 /**550 * Submit the minimum amount of data required to create a single, unsplit withdrawal.551 *552 * @covers \FireflyIII\Api\V1\Requests\TransactionStoreRequest553 * @covers \FireflyIII\Api\V1\Controllers\TransactionController554 */555 public function testStoreOK(): void556 {557 // mock data:558 $source = $this->getRandomAsset();559 $group = $this->getRandomWithdrawalGroup();560 // mock repository561 $repository = $this->mock(TransactionGroupRepositoryInterface::class);562 $journalRepos = $this->mock(JournalRepositoryInterface::class);563 $transformer = $this->mock(TransactionGroupTransformer::class);564 $validator = $this->mock(AccountValidator::class);565 $collector = $this->mock(GroupCollectorInterface::class);566 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);567 // some mock calls:568 $journalRepos->shouldReceive('setUser')->atLeast()->once();569 $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();570 $repository->shouldReceive('setUser')->atLeast()->once();571 $apiRepos->shouldReceive('setUser')->atLeast()->once();572 // validator:573 $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();574 $validator->shouldReceive('validateSource')->atLeast()->once()->andReturn(true);575 $validator->shouldReceive('validateDestination')->atLeast()->once()->andReturn(true);576 // transformer is called:577 $transformer->shouldReceive('setParameters')->atLeast()->once();578 $transformer->shouldReceive('setCurrentScope')->atLeast()->once();579 $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 1]);580 $transformer->shouldReceive('getDefaultIncludes')->atLeast()->once()->andReturn([]);581 $transformer->shouldReceive('getAvailableIncludes')->atLeast()->once()->andReturn([]);582 // collector is called:583 $collector->shouldReceive('setTransactionGroup')->atLeast()->once()->andReturnSelf();584 $collector->shouldReceive('withAPIInformation')->atLeast()->once()->andReturnSelf();585 $collector->shouldReceive('getGroups')->atLeast()->once()->andReturn(new Collection([[]]));586 // expect to store the group:587 $repository->shouldReceive('store')->atLeast()->once()->andReturn($group);588 // expect the event:589 try {590 $this->expectsEvents(StoredTransactionGroup::class);591 } catch (Exception $e) {592 Log::error($e->getMessage());593 Log::error($e->getTraceAsString());594 $this->assertTrue(false, $e->getMessage());595 }596 $data = [597 'transactions' => [598 [599 'description' => 'Some description',600 'date' => '2018-01-01',601 'type' => 'withdrawal',602 'amount' => '10',603 'source_id' => $source->id,604 ],605 ],606 ];607 // test API608 $response = $this->post(route('api.v1.transactions.store'), $data, ['Accept' => 'application/json']);609 $response->assertStatus(200);610 $response->assertExactJson(611 [612 'data' => [613 'attributes' => [],614 'id' => '1',615 'links' => [616 'self' => 'http://localhost/api/v1/transactions/1',617 ],618 'type' => 'transactions',619 ],620 ]621 );622 }623 /**624 * Submit a bad journal ID during update.625 *626 * @covers \FireflyIII\Api\V1\Requests\TransactionUpdateRequest627 * @covers \FireflyIII\Api\V1\Controllers\TransactionController628 */629 public function testUpdateFailBadJournal(): void630 {631 // mock data:632 $group = $this->getRandomWithdrawalGroup();633 // mock repository634 $repository = $this->mock(TransactionGroupRepositoryInterface::class);635 $journalRepos = $this->mock(JournalRepositoryInterface::class);636 $validator = $this->mock(AccountValidator::class);637 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);638 // some mock calls:639 $journalRepos->shouldReceive('setUser')->atLeast()->once();640 $repository->shouldReceive('setUser')->atLeast()->once();641 $apiRepos->shouldReceive('setUser')->atLeast()->once();642 $validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();643 //$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);644 //$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);645 $data = [646 'group_title' => 'Empty',647 'transactions' => [648 [649 'order' => 0,650 'transaction_journal_id' => -1,651 'reconciled' => 'false',652 'tags' => [],653 'interest_date' => '2019-01-01',654 'description' => 'Some new description',655 ],656 [657 'order' => 0,658 'transaction_journal_id' => -1,659 'reconciled' => 'false',660 'tags' => [],661 'interest_date' => '2019-01-01',662 'description' => 'Some new description',663 ],664 ],665 ];666 // test API667 $response = $this->put(sprintf('/api/v1/transactions/%d', $group->id), $data, ['Accept' => 'application/json']);668 $response->assertStatus(422);669 $response->assertExactJson(670 [671 'errors' => [672 'transactions.0.source_name' => ['Each split must have transaction_journal_id (either valid ID or 0).'],673 'transactions.1.source_name' => ['Each split must have transaction_journal_id (either valid ID or 0).'],674 ],675 'message' => 'The given data was invalid.',676 ]677 );678 }679 /**680 * Update transaction but fail to submit equal transaction types.681 *682 * @covers \FireflyIII\Api\V1\Requests\TransactionUpdateRequest683 * @covers \FireflyIII\Api\V1\Controllers\TransactionController684 */685 public function testUpdateFailTypes(): void686 {687 // mock data:688 $group = $this->getRandomWithdrawalGroup();689 // mock repository690 $repository = $this->mock(TransactionGroupRepositoryInterface::class);691 $journalRepos = $this->mock(JournalRepositoryInterface::class);692 $validator = $this->mock(AccountValidator::class);693 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);694 $validator->shouldReceive('setTransactionType')->withArgs(['withdrawal'])->atLeast()->once();695 $validator->shouldReceive('setTransactionType')->withArgs(['deposit'])->atLeast()->once();696 //$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);697 //$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);698 // some mock calls:699 $journalRepos->shouldReceive('setUser')->atLeast()->once();700 $repository->shouldReceive('setUser')->atLeast()->once();701 $apiRepos->shouldReceive('setUser')->atLeast()->once();702 $data = [703 'group_title' => 'Empty',704 'transactions' => [705 [706 'transaction_journal_id' => 0,707 'order' => 0,708 'reconciled' => 'false',709 'tags' => [],710 'interest_date' => '2019-01-01',711 'type' => 'withdrawal',712 'description' => 'Some new description',713 ],714 [715 'transaction_journal_id' => 0,716 'order' => 0,717 'reconciled' => 'false',718 'tags' => [],719 'interest_date' => '2019-01-01',720 'type' => 'deposit',721 'description' => 'Some new description',722 ],723 ],724 ];725 // test API726 $response = $this->put(sprintf('/api/v1/transactions/%d', $group->id), $data, ['Accept' => 'application/json']);727 $response->assertExactJson(728 [729 'errors' => [730 'transactions.0.type' => ['All splits must be of the same type.'],731 ],732 'message' => 'The given data was invalid.',733 ]734 );735 $response->assertStatus(422);736 }737 /**738 * Submit the minimum amount of data to update a single withdrawal.739 *740 * @covers \FireflyIII\Api\V1\Requests\TransactionUpdateRequest741 * @covers \FireflyIII\Api\V1\Controllers\TransactionController742 */743 public function testUpdateOK(): void744 {745 // mock data:746 $group = $this->getRandomWithdrawalGroup();747 // mock repository748 $repository = $this->mock(TransactionGroupRepositoryInterface::class);749 $journalRepos = $this->mock(JournalRepositoryInterface::class);750 $transformer = $this->mock(TransactionGroupTransformer::class);751 $validator = $this->mock(AccountValidator::class);752 $collector = $this->mock(GroupCollectorInterface::class);753 $apiRepos = $this->mock(JournalAPIRepositoryInterface::class);754 $validator->shouldReceive('setTransactionType')->withArgs(['invalid'])->atLeast()->once();755 //$validator->shouldReceive('validateSource')->withArgs([null, null])->atLeast()->once()->andReturn(true);756 //$validator->shouldReceive('validateDestination')->withArgs([null, null])->atLeast()->once()->andReturn(true);757 // some mock calls:758 $journalRepos->shouldReceive('setUser')->atLeast()->once();759 $collector->shouldReceive('setUser')->atLeast()->once()->andReturnSelf();760 $repository->shouldReceive('setUser')->atLeast()->once();761 $apiRepos->shouldReceive('setUser')->atLeast()->once();762 // call stuff:763 $repository->shouldReceive('update')->atLeast()->once()->andReturn($group);764 // transformer is called:765 $transformer->shouldReceive('setParameters')->atLeast()->once();766 $transformer->shouldReceive('setCurrentScope')->atLeast()->once();767 $transformer->shouldReceive('transform')->atLeast()->once()->andReturn(['id' => 1]);768 $transformer->shouldReceive('getDefaultIncludes')->atLeast()->once()->andReturn([]);769 $transformer->shouldReceive('getAvailableIncludes')->atLeast()->once()->andReturn([]);770 // collector is called:...

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1$atleast = new AtLeast();2$atleast->validate($data, $rules);3$atleast = new AtLeast();4$atleast->validate($data, $rules);5$atleast = new AtLeast();6$atleast->validate($data, $rules);7$atleast = new AtLeast();8$atleast->validate($data, $rules);9$atleast = new AtLeast();10$atleast->validate($data, $rules);11$atleast = new AtLeast();12$atleast->validate($data, $rules);13$atleast = new AtLeast();14$atleast->validate($data, $rules);15$atleast = new AtLeast();16$atleast->validate($data, $rules);17$atleast = new AtLeast();18$atleast->validate($data, $rules);19$atleast = new AtLeast();20$atleast->validate($data, $rules);21 (22 (23 (24 (25 (26 (27 (28 (29 (

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1$validator = new AtLeast(2);2$validator->validate(array(1,2,3));3$validator = new AtLeast(2);4$validator->validate(array(1,2));5$validator = new AtLeast(2);6$validator->validate(array(1));7public function validate($input) {8 $errors = array();9 if (count($input) < $this->count) {10 $errors[] = "AtLeast constraint failed.";11 }12 return $errors;13 }14if (count($input) < $this->count) {15 $errors[] = "AtLeast constraint failed.";16}17return $errors;18$validator = new AtLeast(2);19$validator->validate(array(1,2,3));20foreach ($errors as $error) {21";22}23$validator->validate(array(1,

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1$validator = new AtLeast(2);2$validator->validate(array('a', 'b', 'c'));3$validator->validate(array('a', 'b'));4$validator = new AtLeast(2);5$validator->validate(array('a', 'b', 'c'));6$validator->validate(array('a', 'b'));7$validator = new AtLeast(2);8$validator->validate(array('a', 'b', 'c'));9$validator->validate(array('a', 'b'));10$validator = new AtLeast(2);11$validator->validate(array('a', 'b', 'c'));12$validator->validate(array('a', 'b'));13$validator = new AtLeast(2);14$validator->validate(array('a', 'b', 'c'));15$validator->validate(array('a', 'b'));16$validator = new AtLeast(2);17$validator->validate(array('a', 'b', 'c'));18$validator->validate(array('a', 'b'));19$validator = new AtLeast(2);20$validator->validate(array('a', 'b', 'c'));21$validator->validate(array('a', 'b'));22$validator = new AtLeast(2);23$validator->validate(array('a', 'b', 'c'));24$validator->validate(array('a', 'b'));25$validator = new AtLeast(2);26$validator->validate(array('a', '

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1require_once 'AtLeast.php';2$atleast = new AtLeast();3$atleast->validate(5, 4, 3, 2, 1, 0);4require_once 'AtLeast.php';5$atleast = new AtLeast();6$atleast->validate(5, 4, 3, 2, 1, 6);7require_once 'AtLeast.php';8$atleast = new AtLeast();9$atleast->validate(5, 4, 3, 2, 1);

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1$atleast = new AtLeast();2$atleast->validate($value, array('min' => 5, 'max' => 10));3$atleast = new AtLeast();4$atleast->validate($value, array('min' => 5, 'max' => 10));5$atleast = new AtLeast();6$atleast->validate($value, array('min' => 5, 'max' => 10));

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1$at_least = new AtLeast();2$at_least->validate('abc', 5, 'password');3$at_least = new AtLeast();4$at_least->validate('abc', 5, 'password');5$at_least = new AtLeast();6$at_least->validate('abc', 5, 'password');7$at_least = new AtLeast();8$at_least->validate('abc', 5, 'password');9$at_least = new AtLeast();10$at_least->validate('abc', 5, 'password');11$at_least = new AtLeast();12$at_least->validate('abc', 5, 'password');13$at_least = new AtLeast();14$at_least->validate('abc', 5, 'password');15$at_least = new AtLeast();16$at_least->validate('abc', 5, 'password');17$at_least = new AtLeast();18$at_least->validate('abc', 5, 'password');19$at_least = new AtLeast();20$at_least->validate('abc', 5, 'password');

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1$atleast = new AtLeast();2if($atleast->validate(4, 2, 6, 8, 9, 10, 12, 15, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100)) {3 echo "At least 4 of the numbers are greater than 0";4} else {5 echo "At least 4 of the numbers are not greater than 0";6}

Full Screen

Full Screen

validate

Using AI Code Generation

copy

Full Screen

1$validate= new AtLeast();2$validate->validate('password', 'Password', 'required|at_least:5');3$validate= new AtLeast();4$validate->validate('password', 'Password', 'required|at_least:5|at_least:6');5$validate= new AtLeast();6$validate->validate('password', 'Password', 'required|at_least:5|at_least:6|at_least:7');7 (8 (9 (10 (

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Mockery automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in AtLeast

Trigger validate code on LambdaTest Cloud Grid

Execute automation tests with validate on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful