From 1c285313579220772a9bd9443d60a01a67f0b36b Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 13 Aug 2024 08:40:57 +0200 Subject: [PATCH] OP-464: Specs --- spec/Assigner/LocalesAssignerSpec.php | 53 ++++++++++++++++++ .../Assigner/ProductsInTaxonsAssignerSpec.php | 54 +++++++++++++++++++ spec/Resolver/ImporterLocalesResolverSpec.php | 48 +++++++++++++++++ .../ImporterProductsInTaxonsResolverSpec.php | 48 +++++++++++++++++ spec/Resolver/ImporterTaxonsResolverSpec.php | 48 +++++++++++++++++ 5 files changed, 251 insertions(+) create mode 100644 spec/Assigner/LocalesAssignerSpec.php create mode 100644 spec/Assigner/ProductsInTaxonsAssignerSpec.php create mode 100644 spec/Resolver/ImporterLocalesResolverSpec.php create mode 100644 spec/Resolver/ImporterProductsInTaxonsResolverSpec.php create mode 100644 spec/Resolver/ImporterTaxonsResolverSpec.php diff --git a/spec/Assigner/LocalesAssignerSpec.php b/spec/Assigner/LocalesAssignerSpec.php new file mode 100644 index 00000000..e757ff87 --- /dev/null +++ b/spec/Assigner/LocalesAssignerSpec.php @@ -0,0 +1,53 @@ +beConstructedWith($localeRepository); + } + + public function it_is_initializable() + { + $this->shouldHaveType(LocalesAssigner::class); + } + + public function it_implements_locales_assigner_interface() + { + $this->shouldImplement(LocalesAssignerInterface::class); + } + + public function it_assigns_locales_to_locale_aware_entity( + RepositoryInterface $localeRepository, + LocaleAwareInterface $localesAware, + LocaleInterface $locale1, + LocaleInterface $locale2 + ) { + $locale1->getCode()->willReturn('en_US'); + $locale2->getCode()->willReturn('fr_FR'); + + $localeRepository->findAll()->willReturn([$locale1, $locale2]); + + $localesAware->addLocale($locale1)->shouldBeCalled(); + $localesAware->addLocale($locale2)->shouldBeCalled(); + + $this->assign($localesAware, ['en_US', 'fr_FR']); + } +} diff --git a/spec/Assigner/ProductsInTaxonsAssignerSpec.php b/spec/Assigner/ProductsInTaxonsAssignerSpec.php new file mode 100644 index 00000000..6d5454f9 --- /dev/null +++ b/spec/Assigner/ProductsInTaxonsAssignerSpec.php @@ -0,0 +1,54 @@ +beConstructedWith($taxonRepository); + } + + public function it_is_initializable() + { + $this->shouldHaveType(ProductsInTaxonsAssigner::class); + } + + public function it_implements_products_in_taxons_assigner_interface() + { + $this->shouldImplement(ProductsInTaxonsAssignerInterface::class); + } + + public function it_assigns_taxons_to_products_in_taxons_aware_entity( + TaxonRepositoryInterface $taxonRepository, + ProductsInTaxonsAwareInterface $productsInTaxonsAware, + TaxonInterface $taxon1, + TaxonInterface $taxon2 + ) { + $taxon1->getCode()->willReturn('taxon_code_1'); + $taxon2->getCode()->willReturn('taxon_code_2'); + + $taxonRepository->findOneBy(['code' => 'taxon_code_1'])->willReturn($taxon1); + $taxonRepository->findOneBy(['code' => 'taxon_code_2'])->willReturn($taxon2); + + $productsInTaxonsAware->addProductsInTaxon($taxon1)->shouldBeCalled(); + $productsInTaxonsAware->addProductsInTaxon($taxon2)->shouldBeCalled(); + + $this->assign($productsInTaxonsAware, ['taxon_code_1', 'taxon_code_2']); + } +} diff --git a/spec/Resolver/ImporterLocalesResolverSpec.php b/spec/Resolver/ImporterLocalesResolverSpec.php new file mode 100644 index 00000000..ed4b4e61 --- /dev/null +++ b/spec/Resolver/ImporterLocalesResolverSpec.php @@ -0,0 +1,48 @@ +beConstructedWith($localesAssigner); + } + + public function it_is_initializable() + { + $this->shouldHaveType(ImporterLocalesResolver::class); + } + + public function it_resolves_locales_for_locale_aware_entity( + LocalesAssignerInterface $localesAssigner, + LocaleAwareInterface $localesAware + ) { + $localesRow = 'en_US, fr_FR'; + $localesAssigner->assign($localesAware, ['en_US', 'fr_FR'])->shouldBeCalled(); + + $this->resolve($localesAware, $localesRow); + } + + public function it_does_not_assign_locales_when_locales_row_is_empty( + LocalesAssignerInterface $localesAssigner, + LocaleAwareInterface $localesAware + ) { + $localesAssigner->assign($localesAware, [])->shouldNotBeCalled(); + + $this->resolve($localesAware, ''); + } +} diff --git a/spec/Resolver/ImporterProductsInTaxonsResolverSpec.php b/spec/Resolver/ImporterProductsInTaxonsResolverSpec.php new file mode 100644 index 00000000..c1ce51ab --- /dev/null +++ b/spec/Resolver/ImporterProductsInTaxonsResolverSpec.php @@ -0,0 +1,48 @@ +beConstructedWith($productsInTaxonsAssigner); + } + + public function it_is_initializable() + { + $this->shouldHaveType(ImporterProductsInTaxonsResolver::class); + } + + public function it_resolves_taxons_for_products_in_taxons_aware_entity( + ProductsInTaxonsAssignerInterface $productsInTaxonsAssigner, + ProductsInTaxonsAwareInterface $productsInTaxonsAware + ) { + $taxonsRow = 'taxon_code_1, taxon_code_2'; + $productsInTaxonsAssigner->assign($productsInTaxonsAware, ['taxon_code_1', 'taxon_code_2'])->shouldBeCalled(); + + $this->resolve($productsInTaxonsAware, $taxonsRow); + } + + public function it_does_not_assign_taxons_when_taxons_row_is_null( + ProductsInTaxonsAssignerInterface $productsInTaxonsAssigner, + ProductsInTaxonsAwareInterface $productsInTaxonsAware + ) { + $productsInTaxonsAssigner->assign($productsInTaxonsAware, [])->shouldNotBeCalled(); + + $this->resolve($productsInTaxonsAware, null); + } +} diff --git a/spec/Resolver/ImporterTaxonsResolverSpec.php b/spec/Resolver/ImporterTaxonsResolverSpec.php new file mode 100644 index 00000000..16bb30e4 --- /dev/null +++ b/spec/Resolver/ImporterTaxonsResolverSpec.php @@ -0,0 +1,48 @@ +beConstructedWith($taxonsAssigner); + } + + public function it_is_initializable() + { + $this->shouldHaveType(ImporterTaxonsResolver::class); + } + + public function it_resolves_taxons_for_taxon_aware_entity( + TaxonsAssignerInterface $taxonsAssigner, + TaxonAwareInterface $taxonsAware + ) { + $taxonsRow = 'taxon_code_1, taxon_code_2'; + $taxonsAssigner->assign($taxonsAware, ['taxon_code_1', 'taxon_code_2'])->shouldBeCalled(); + + $this->resolve($taxonsAware, $taxonsRow); + } + + public function it_does_not_assign_taxons_when_taxons_row_is_null( + TaxonsAssignerInterface $taxonsAssigner, + TaxonAwareInterface $taxonsAware + ) { + $taxonsAssigner->assign($taxonsAware, [])->shouldNotBeCalled(); + + $this->resolve($taxonsAware, null); + } +}