|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use ThomasNetScraper\DTO\Address; |
| 6 | + |
| 7 | +it('creates address from complete data', function () { |
| 8 | + $data = [ |
| 9 | + 'address1' => '300 New Jersey Avenue, N.W.', |
| 10 | + 'address2' => 'Suite 1000', |
| 11 | + 'city' => 'Washington', |
| 12 | + 'state' => 'DC', |
| 13 | + 'stateName' => 'District of Columbia', |
| 14 | + 'zip' => '20001', |
| 15 | + 'country' => 'USA', |
| 16 | + 'latitude' => 38.91076058, |
| 17 | + 'longitude' => -77.0167462, |
| 18 | + ]; |
| 19 | + |
| 20 | + $address = Address::fromArray($data); |
| 21 | + |
| 22 | + expect($address->address1)->toBe('300 New Jersey Avenue, N.W.') |
| 23 | + ->and($address->address2)->toBe('Suite 1000') |
| 24 | + ->and($address->city)->toBe('Washington') |
| 25 | + ->and($address->state)->toBe('DC') |
| 26 | + ->and($address->stateName)->toBe('District of Columbia') |
| 27 | + ->and($address->zip)->toBe('20001') |
| 28 | + ->and($address->country)->toBe('USA') |
| 29 | + ->and($address->latitude)->toBe(38.91076058) |
| 30 | + ->and($address->longitude)->toBe(-77.0167462); |
| 31 | +}); |
| 32 | + |
| 33 | +it('handles missing optional fields', function () { |
| 34 | + $address = Address::fromArray([ |
| 35 | + 'city' => 'Austin', |
| 36 | + 'state' => 'TX', |
| 37 | + ]); |
| 38 | + |
| 39 | + expect($address->city)->toBe('Austin') |
| 40 | + ->and($address->state)->toBe('TX') |
| 41 | + ->and($address->address1)->toBeNull() |
| 42 | + ->and($address->address2)->toBeNull() |
| 43 | + ->and($address->zip)->toBeNull() |
| 44 | + ->and($address->latitude)->toBeNull() |
| 45 | + ->and($address->longitude)->toBeNull(); |
| 46 | +}); |
| 47 | + |
| 48 | +it('creates empty address from empty array', function () { |
| 49 | + $address = Address::fromArray([]); |
| 50 | + |
| 51 | + expect($address->address1)->toBeNull() |
| 52 | + ->and($address->city)->toBeNull() |
| 53 | + ->and($address->state)->toBeNull() |
| 54 | + ->and($address->country)->toBeNull(); |
| 55 | +}); |
| 56 | + |
| 57 | +it('casts coordinates to float', function () { |
| 58 | + $address = Address::fromArray([ |
| 59 | + 'latitude' => '38.91076058', |
| 60 | + 'longitude' => '-77.0167462', |
| 61 | + ]); |
| 62 | + |
| 63 | + expect($address->latitude)->toBeFloat() |
| 64 | + ->and($address->longitude)->toBeFloat(); |
| 65 | +}); |
0 commit comments