From 0d180d995f4806098db65afa628199b39235ba77 Mon Sep 17 00:00:00 2001 From: Lorenzo Ruozzi Date: Thu, 15 Feb 2024 16:36:34 +0100 Subject: [PATCH] Fix Spec tests (#199) --- spec/Converter/ValueConverterSpec.php | 73 ++++++++++++++------------- 1 file changed, 38 insertions(+), 35 deletions(-) diff --git a/spec/Converter/ValueConverterSpec.php b/spec/Converter/ValueConverterSpec.php index 0cd9dda5..ef8b4116 100644 --- a/spec/Converter/ValueConverterSpec.php +++ b/spec/Converter/ValueConverterSpec.php @@ -4,6 +4,8 @@ namespace spec\Webgriffe\SyliusAkeneoPlugin\Converter; +use InvalidArgumentException; +use LogicException; use PhpSpec\ObjectBehavior; use Sylius\Component\Attribute\AttributeType\CheckboxAttributeType; use Sylius\Component\Attribute\AttributeType\DatetimeAttributeType; @@ -28,13 +30,14 @@ public function let( AttributeInterface $integerAttribute, AttributeInterface $selectAttribute, AttributeInterface $datetimeAttribute - ) { + ): void { $translator->trans('webgriffe_sylius_akeneo.ui.metric_amount_unit', ['unit' => 'INCH', 'amount' => '23'], null, 'it')->willReturn('23"'); $textAttribute->getType()->willReturn(TextAttributeType::TYPE); $integerAttribute->getType()->willReturn(IntegerAttributeType::TYPE); $textareaAttribute->getType()->willReturn(TextareaAttributeType::TYPE); $checkboxAttribute->getType()->willReturn(CheckboxAttributeType::TYPE); + $selectAttribute->getCode()->willReturn('brand'); $selectAttribute->getType()->willReturn(SelectAttributeType::TYPE); $datetimeAttribute->getType()->willReturn(DatetimeAttributeType::TYPE); @@ -52,21 +55,21 @@ public function let( $this->beConstructedWith($translator); } - function it_is_initializable() + public function it_is_initializable(): void { $this->shouldHaveType(ValueConverter::class); } - function it_implements_value_converter_interface() + public function it_implements_value_converter_interface(): void { $this->shouldHaveType(ValueConverterInterface::class); } - function it_throws_exception_during_convert_when_value_not_contains_amount_key( + public function it_throws_exception_during_convert_when_value_not_contains_amount_key( AttributeInterface $textAttribute - ) { + ): void { $this->shouldThrow( - new \LogicException('Amount key not found') + new LogicException('Amount key not found') )->during('convert', [ $textAttribute, [ @@ -76,11 +79,11 @@ function it_throws_exception_during_convert_when_value_not_contains_amount_key( ]); } - function it_throws_exception_during_convert_when_value_contains_amount_key_and_not_contains_unit_key( + public function it_throws_exception_during_convert_when_value_contains_amount_key_and_not_contains_unit_key( AttributeInterface $textAttribute - ) { + ): void { $this->shouldThrow( - new \LogicException('Unit key not found') + new LogicException('Unit key not found') )->during('convert', [ $textAttribute, [ @@ -91,9 +94,9 @@ function it_throws_exception_during_convert_when_value_contains_amount_key_and_n ]); } - function it_converts_metric_value_from_akeneo_to_text_value_translated_when_translator_is_injected( + public function it_converts_metric_value_from_akeneo_to_text_value_translated_when_translator_is_injected( AttributeInterface $textAttribute - ) { + ): void { $this->convert( $textAttribute, [ @@ -104,89 +107,89 @@ function it_converts_metric_value_from_akeneo_to_text_value_translated_when_tran )->shouldReturn('23"'); } - function it_converts_text_value_from_akeneo_to_text_value( + public function it_converts_text_value_from_akeneo_to_text_value( AttributeInterface $textAttribute - ) { + ): void { $value = 'Agape'; $this->convert($textAttribute, $value, self::IT_LOCALE_CODE)->shouldReturn($value); } - function it_converts_integer_value_from_akeneo_to_integer_value( + public function it_converts_integer_value_from_akeneo_to_integer_value( AttributeInterface $integerAttribute - ) { + ): void { $value = 123; $this->convert($integerAttribute, $value, self::IT_LOCALE_CODE)->shouldReturn($value); } - function it_converts_textarea_value_from_akeneo_to_textarea_value( + public function it_converts_textarea_value_from_akeneo_to_textarea_value( AttributeInterface $textareaAttribute - ) { + ): void { $value = 'Lorem ipsum dolor sit amet'; $this->convert($textareaAttribute, $value, self::IT_LOCALE_CODE)->shouldReturn($value); } - function it_converts_boolean_value_from_akeneo_to_checkbox_value( + public function it_converts_boolean_value_from_akeneo_to_checkbox_value( AttributeInterface $checkboxAttribute - ) { + ): void { $value = true; $this->convert($checkboxAttribute, $value, self::IT_LOCALE_CODE)->shouldReturn($value); } - function it_converts_select_value_from_akeneo_to_select_value( + public function it_converts_select_value_from_akeneo_to_select_value( AttributeInterface $selectAttribute - ) { + ): void { $value = ['brand_agape_IT']; $this->convert($selectAttribute, $value, self::IT_LOCALE_CODE)->shouldReturn($value); } - function it_throws_error_when_select_value_is_not_an_existing_option( + public function it_throws_error_when_select_value_is_not_an_existing_option( AttributeInterface $selectAttribute - ) { + ): void { $value = ['brand_not_existing']; $this ->shouldThrow( - new \InvalidArgumentException( + new InvalidArgumentException( 'This select attribute can only save existing attribute options. ' . - 'Attribute option codes [brand_not_existing] do not exist.', + 'Attribute option codes [brand_not_existing] for attribute "brand" does not exist.', ) ) ->during('convert', [$selectAttribute, $value, self::IT_LOCALE_CODE]); } - function it_throws_error_when_select_values_are_not_existing_options( + public function it_throws_error_when_select_values_are_not_existing_options( AttributeInterface $selectAttribute - ) { + ): void { $value = ['brand_not_existing', 'brand_not_existing_2']; $this ->shouldThrow( - new \InvalidArgumentException( + new InvalidArgumentException( 'This select attribute can only save existing attribute options. ' . - 'Attribute option codes [brand_not_existing, brand_not_existing_2] do not exist.', + 'Attribute option codes [brand_not_existing, brand_not_existing_2] for attribute "brand" does not exist.', ) ) ->during('convert', [$selectAttribute, $value, self::IT_LOCALE_CODE]); } - function it_throws_error_when_select_values_are_not_all_existing_options( + public function it_throws_error_when_select_values_are_not_all_existing_options( AttributeInterface $selectAttribute - ) { + ): void { $value = ['brand_agape', 'brand_not_existing']; $this ->shouldThrow( - new \InvalidArgumentException( + new InvalidArgumentException( 'This select attribute can only save existing attribute options. ' . - 'Attribute option codes [brand_not_existing] do not exist.', + 'Attribute option codes [brand_agape, brand_not_existing] for attribute "brand" does not exist.', ) ) ->during('convert', [$selectAttribute, $value, self::IT_LOCALE_CODE]); } - function it_converts_datetime_value_from_akeneo_to_datetime_value( + public function it_converts_datetime_value_from_akeneo_to_datetime_value( AttributeInterface $datetimeAttribute - ) { + ): void { $value = '2020-01-01 11:12:32'; $this->convert($datetimeAttribute, $value, self::IT_LOCALE_CODE)->shouldReturn($value); }