artisan('db:seed'); }); test('resource has expected keys', function () { $country = Country::first(); $array = (new CountryResource($country))->toArray(new Request); $this->assertSame([ 'id', 'name', 'full_name', 'capital', 'citizenship', 'country_code', 'currency', 'currency_code', 'currency_sub_unit', 'currency_symbol', 'iso_3166_2', 'iso_3166_3', 'region_code', 'sub_region_code', 'eea', 'calling_code', 'flag', ], array_keys($array)); }); test('flag resolves to url when set', function () { $country = Country::first(); $country->flag = 'UK.png'; $array = (new CountryResource($country))->toArray(new Request); $this->assertStringContainsString('flags/UK.png', $array['flag']); }); test('flag is null when missing', function () { $country = Country::first(); $country->flag = null; $array = (new CountryResource($country))->toArray(new Request); $this->assertNull($array['flag']); }); test('numeric casts', function () { $country = Country::first(); $array = (new CountryResource($country))->toArray(new Request); $this->assertIsInt($array['id']); $this->assertIsInt($array['country_code']); $this->assertIsInt($array['region_code']); $this->assertIsBool($array['eea']); });