Skip to content

Commit

Permalink
Fix Spec tests (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Feb 15, 2024
1 parent 3b367db commit 0d180d9
Showing 1 changed file with 38 additions and 35 deletions.
73 changes: 38 additions & 35 deletions spec/Converter/ValueConverterSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand All @@ -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,
[
Expand All @@ -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,
[
Expand All @@ -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,
[
Expand All @@ -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);
}
Expand Down

0 comments on commit 0d180d9

Please sign in to comment.