From 208ed026d6856855da1bbdc8165b26bfb3cb1740 Mon Sep 17 00:00:00 2001 From: Rasmus Nielsen Date: Wed, 29 Sep 2021 14:02:13 +0200 Subject: [PATCH] Add image height to api response --- .phpunit.result.cache | 1 + src/ResponsiveImageFactory.php | 3 ++- tests/Feature/ResponsiveTest.php | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 .phpunit.result.cache diff --git a/.phpunit.result.cache b/.phpunit.result.cache new file mode 100644 index 0000000..9015d01 --- /dev/null +++ b/.phpunit.result.cache @@ -0,0 +1 @@ +C:37:"PHPUnit\Runner\DefaultTestResultCache":5364:{a:2:{s:7:"defects";a:1:{s:94:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::regression__it_handles_none_existent_images";i:3;}s:5:"times";a:50:{s:72:"Makeable\CloudImages\Tests\Feature\CleanupTest::it_deletes_unused_images";d:1.032;s:72:"Makeable\CloudImages\Tests\Feature\CleanupTest::it_preserves_used_images";d:0.101;s:64:"Makeable\CloudImages\Tests\Feature\DeleteTest::it_deletes_images";d:0.056;s:92:"Makeable\CloudImages\Tests\Feature\DeleteTest::it_throws_exception_on_failed_bucket_deletion";d:0.18;s:89:"Makeable\CloudImages\Tests\Feature\DeleteTest::it_throws_exception_on_failed_http_request";d:0.038;s:78:"Makeable\CloudImages\Tests\Feature\DeleteTest::it_dispatches_event_on_deletion";d:0.115;s:109:"Makeable\CloudImages\Tests\Feature\FileSizeOptimizedDimensionCalculatorTest::it_returns_collection_with_sizes";d:0.06;s:126:"Makeable\CloudImages\Tests\Feature\FileSizeOptimizedDimensionCalculatorTest::it_generates_sizes_until_last_image_is_very_small";d:0.061;s:106:"Makeable\CloudImages\Tests\Feature\GeneratePlaceholdersTest::it_generates_placeholders_and_sets_dimensions";d:0.903;s:85:"Makeable\CloudImages\Tests\Feature\HasMultipleImagesTest::it_attaches_to_other_models";d:0.104;s:87:"Makeable\CloudImages\Tests\Feature\HasMultipleImagesTest::it_sorts_attachments_by_order";d:0.242;s:84:"Makeable\CloudImages\Tests\Feature\HasMultipleImagesTest::it_can_rearrange_the_order";d:0.209;s:96:"Makeable\CloudImages\Tests\Feature\HasMultipleImagesTest::it_finds_attachables_for_a_given_model";d:0.125;s:121:"Makeable\CloudImages\Tests\Feature\HasMultipleImagesTest::it_uses_the_specified_image_class_property_for_the_relationship";d:0.149;s:90:"Makeable\CloudImages\Tests\Feature\HasSingleImageTest::it_has_a_getter_for_as_single_image";d:0.158;s:81:"Makeable\CloudImages\Tests\Feature\HasSingleImageTest::it_defaults_to_empty_image";d:0.157;s:85:"Makeable\CloudImages\Tests\Feature\HasSingleImageTest::it_replaces_with_another_image";d:0.119;s:104:"Makeable\CloudImages\Tests\Feature\HasSingleImageTest::it_replaces_with_image_even_if_currently_has_none";d:0.164;s:91:"Makeable\CloudImages\Tests\Feature\HasSingleImageTest::it_can_fetch_an_image_of_a_given_tag";d:0.121;s:76:"Makeable\CloudImages\Tests\Feature\ImageFactoryTest::it_defaults_to_original";d:0.068;s:64:"Makeable\CloudImages\Tests\Feature\ImageFactoryTest::it_can_blur";d:0.061;s:82:"Makeable\CloudImages\Tests\Feature\ImageFactoryTest::it_can_scale_to_max_dimension";d:0.046;s:79:"Makeable\CloudImages\Tests\Feature\ImageFactoryTest::it_can_scale_to_dimensions";d:0.078;s:78:"Makeable\CloudImages\Tests\Feature\ImageFactoryTest::it_can_crop_to_dimensions";d:0.042;s:76:"Makeable\CloudImages\Tests\Feature\ImageFactoryTest::it_can_crop_from_center";d:0.035;s:81:"Makeable\CloudImages\Tests\Feature\ImageFactoryTest::it_accepts_custom_parameters";d:0.074;s:85:"Makeable\CloudImages\Tests\Feature\ImageFactoryTest::it_returns_null_when_url_is_null";d:0.035;s:84:"Makeable\CloudImages\Tests\Feature\ImageTest::it_inserts_uploaded_images_to_database";d:0.083;s:86:"Makeable\CloudImages\Tests\Feature\ImageTest::it_deletes_cloud_image_on_model_deletion";d:0.131;s:68:"Makeable\CloudImages\Tests\Feature\ImageTest::it_can_store_exif_data";d:0.372;s:77:"Makeable\CloudImages\Tests\Feature\ImageTest::it_generates_a_tiny_placeholder";d:0.307;s:83:"Makeable\CloudImages\Tests\Feature\ImageTest::it_casts_to_a_responsive_html_img_tag";d:0.132;s:113:"Makeable\CloudImages\Tests\Feature\ImageTest::it_casts_to_a_responsive_html_img_tag_with_placeholder_when_enabled";d:0.174;s:77:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::it_needs_an_image_instance";d:0.075;s:93:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::it_returns_a_collection_of_image_factories";d:0.178;s:111:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::the_number_of_versions_depends_on_the_transformed_dimensions";d:0.109;s:93:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::it_applies_transformations_across_versions";d:0.149;s:103:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::the_smallest_version_is_a_tiny_placeholder_when_used";d:0.187;s:117:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::the_placeholder_stretches_to_the_dimensions_of_the_generated_image";d:0.148;s:113:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::responsive_factory_casts_to_an_array_suitable_for_api_response";d:0.165;s:109:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::responsive_factory_casts_to_json_suitable_for_api_response";d:0.103;s:89:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::regression__it_always_returns_integers";d:0.158;s:105:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::regression__it_also_scales_original_sizes_responsively";d:0.165;s:94:"Makeable\CloudImages\Tests\Feature\ResponsiveTest::regression__it_handles_none_existent_images";d:0.131;s:64:"Makeable\CloudImages\Tests\Feature\UploadTest::it_uploads_images";d:0.049;s:76:"Makeable\CloudImages\Tests\Feature\UploadTest::it_hashes_filename_on_default";d:0.113;s:69:"Makeable\CloudImages\Tests\Feature\UploadTest::it_accepts_a_file_path";d:0.027;s:83:"Makeable\CloudImages\Tests\Feature\UploadTest::it_throws_exception_on_failed_upload";d:0.044;s:76:"Makeable\CloudImages\Tests\Feature\UploadTest::it_dispatches_event_on_upload";d:0.106;s:67:"Makeable\CloudImages\Tests\Feature\UploadTest::it_can_be_set_public";d:0.065;}}} \ No newline at end of file diff --git a/src/ResponsiveImageFactory.php b/src/ResponsiveImageFactory.php index f1f7625..403258e 100644 --- a/src/ResponsiveImageFactory.php +++ b/src/ResponsiveImageFactory.php @@ -122,7 +122,8 @@ public function toArray() return [ 'src' => $this->getSrc(), 'srcset' => $this->getSrcset(), - 'width' => Arr::get($this->getDimensions(), 0), + 'width' => Arr::get($dimensions = $this->getDimensions(), 0), + 'height' => Arr::get($dimensions, 1), ]; } diff --git a/tests/Feature/ResponsiveTest.php b/tests/Feature/ResponsiveTest.php index 45c80bc..73a6094 100644 --- a/tests/Feature/ResponsiveTest.php +++ b/tests/Feature/ResponsiveTest.php @@ -92,6 +92,7 @@ public function responsive_factory_casts_to_an_array_suitable_for_api_response() $this->assertArrayHasKey('src', $response); $this->assertArrayHasKey('srcset', $response); $this->assertArrayHasKey('width', $response); + $this->assertArrayHasKey('height', $response); } /** @test **/ @@ -151,6 +152,7 @@ public function regression__it_handles_none_existent_images() 'src' => null, 'srcset' => '', 'width' => null, + 'height' => null, ], $responsive->toArray()); } }