|
| 1 | +<?php |
| 2 | +namespace GrShareCode\Tests\Unit\Domain\Contact; |
| 3 | + |
| 4 | +use GrShareCode\Contact\AddContactCommand; |
| 5 | +use GrShareCode\Contact\ContactCustomFieldsCollection; |
| 6 | +use GrShareCode\Tests\Unit\BaseTestCase; |
| 7 | +use GrShareCode\Validation\Assert\InvalidArgumentException; |
| 8 | + |
| 9 | +/** |
| 10 | + * Class AddContactCommandTest |
| 11 | + * @package GrShareCode\Contact |
| 12 | + */ |
| 13 | +class AddContactCommandTest extends BaseTestCase |
| 14 | +{ |
| 15 | + |
| 16 | + /** |
| 17 | + * @test |
| 18 | + * @dataProvider validDataProvider |
| 19 | + * @param string $email |
| 20 | + * @param string $name |
| 21 | + * @param string $contactListId |
| 22 | + * @param int $dayOfCycle |
| 23 | + * @param ContactCustomFieldsCollection $customFieldsCollection |
| 24 | + * @param string $originValue |
| 25 | + */ |
| 26 | + public function shouldCreateValidInstance($email, $name, $contactListId, $dayOfCycle, $customFieldsCollection, $originValue) |
| 27 | + { |
| 28 | + self::assertInstanceOf( |
| 29 | + AddContactCommand::class, |
| 30 | + new AddContactCommand( |
| 31 | + $email, |
| 32 | + $name, |
| 33 | + $contactListId, |
| 34 | + $dayOfCycle, |
| 35 | + $customFieldsCollection, |
| 36 | + $originValue |
| 37 | + ) |
| 38 | + ); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @return array |
| 43 | + */ |
| 44 | + public function validDataProvider() |
| 45 | + { |
| 46 | + return [ |
| 47 | + [ |
| 48 | + 'email' => 'noone@example.com', |
| 49 | + 'name' => 'name', |
| 50 | + 'contact_list_id' => 'va1', |
| 51 | + 'day_of_cycle' => 0, |
| 52 | + new ContactCustomFieldsCollection(), |
| 53 | + 'origin' |
| 54 | + ], |
| 55 | + [ |
| 56 | + 'email' => 'noone@example.com', |
| 57 | + 'name' => '', |
| 58 | + 'contact_list_id' => 'va1', |
| 59 | + 'day_of_cycle' => 0, |
| 60 | + new ContactCustomFieldsCollection(), |
| 61 | + 'origin' |
| 62 | + ], |
| 63 | + |
| 64 | + ]; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @test |
| 69 | + * @dataProvider invalidDataProvider |
| 70 | + * @param string $email |
| 71 | + * @param string $name |
| 72 | + * @param string $contactListId |
| 73 | + * @param int $dayOfCycle |
| 74 | + * @param ContactCustomFieldsCollection $customFieldsCollection |
| 75 | + * @param string $originValue |
| 76 | + */ |
| 77 | + public function shouldThrowExceptionWhenInvalidParameters($email, $name, $contactListId, $dayOfCycle, $customFieldsCollection, $originValue) |
| 78 | + { |
| 79 | + self::expectException(InvalidArgumentException::class); |
| 80 | + |
| 81 | + new AddContactCommand( |
| 82 | + $email, |
| 83 | + $name, |
| 84 | + $contactListId, |
| 85 | + $dayOfCycle, |
| 86 | + $customFieldsCollection, |
| 87 | + $originValue |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + public function invalidDataProvider() |
| 92 | + { |
| 93 | + return [ |
| 94 | + [ |
| 95 | + 'email' => null, |
| 96 | + 'name' => 'name', |
| 97 | + 'contact_list_id' => 'va1', |
| 98 | + 'day_of_cycle' => 0, |
| 99 | + new ContactCustomFieldsCollection(), |
| 100 | + 'origin' |
| 101 | + ], |
| 102 | + [ |
| 103 | + 'email' => '', |
| 104 | + 'name' => 'name', |
| 105 | + 'contact_list_id' => 'va1', |
| 106 | + 'day_of_cycle' => 0, |
| 107 | + new ContactCustomFieldsCollection(), |
| 108 | + 'origin' |
| 109 | + ], |
| 110 | + [ |
| 111 | + 'email' => 'nonoe@example.com', |
| 112 | + 'name' => 'name', |
| 113 | + 'contact_list_id' => '', |
| 114 | + 'day_of_cycle' => 0, |
| 115 | + new ContactCustomFieldsCollection(), |
| 116 | + 'origin' |
| 117 | + ], |
| 118 | + [ |
| 119 | + 'email' => 'nonoe@example.com', |
| 120 | + 'name' => 'name', |
| 121 | + 'contact_list_id' => null, |
| 122 | + 'day_of_cycle' => 0, |
| 123 | + new ContactCustomFieldsCollection(), |
| 124 | + 'origin' |
| 125 | + ], |
| 126 | + [ |
| 127 | + 'email' => 'nonoe@example.com', |
| 128 | + 'name' => 'name', |
| 129 | + 'contact_list_id' => false, |
| 130 | + 'day_of_cycle' => 0, |
| 131 | + new ContactCustomFieldsCollection(), |
| 132 | + 'origin' |
| 133 | + ], |
| 134 | + ]; |
| 135 | + } |
| 136 | +} |
0 commit comments