OP-7: Unit Tests

This commit is contained in:
Gracjan Józefczyk
2022-12-05 22:31:07 +01:00
parent f82f2903ec
commit b19a093c8f
2 changed files with 13 additions and 25 deletions

View File

@@ -10,25 +10,21 @@ declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler;
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContextInterface;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\DataHandlerInterface;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\ShopProductListDataHandler;
use BitBag\SyliusElasticsearchPlugin\Exception\TaxonNotFoundException;
use BitBag\SyliusElasticsearchPlugin\Finder\ProductAttributesFinderInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
final class ShopProductListDataHandlerSpec extends ObjectBehavior
{
function let(
TaxonRepositoryInterface $taxonRepository,
LocaleContextInterface $localeContext,
TaxonContextInterface $taxonContext,
ProductAttributesFinderInterface $attributesFinder
): void {
$this->beConstructedWith(
$taxonRepository,
$localeContext,
$taxonContext,
$attributesFinder,
'name',
'taxons',
@@ -48,35 +44,23 @@ final class ShopProductListDataHandlerSpec extends ObjectBehavior
}
function it_retrieves_data(
LocaleContextInterface $localeContext,
TaxonRepositoryInterface $taxonRepository,
TaxonContextInterface $taxonContext,
TaxonInterface $taxon
): void {
$localeContext->getLocaleCode()->willReturn('en');
$taxonContext->getTaxon()->willReturn($taxon);
$taxon->getCode()->willReturn('book');
$taxonRepository->findOneBySlug('book', 'en')->willReturn($taxon);
$this->retrieveData([
'slug' => 'book',
'name' => 'Book',
'price' => [],
'facets' => [],
])->shouldBeEqualTo([
'name' => 'Book',
'taxons' => 'book',
'taxon' => $taxon,
'facets' => [],
]);
}
function it_throws_taxon_not_found_exception_if_taxon_is_null(
LocaleContextInterface $localeContext,
TaxonInterface $taxon
): void {
$localeContext->getLocaleCode()->willReturn('en');
$taxon->getCode()->willReturn('book');
$this->shouldThrow(TaxonNotFoundException::class)->during('retrieveData', [['slug' => 'book']]);
}
}

View File

@@ -12,6 +12,7 @@ namespace spec\BitBag\SyliusElasticsearchPlugin\Finder;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\PaginationDataHandlerInterface;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\SortDataHandlerInterface;
use BitBag\SyliusElasticsearchPlugin\Facet\RegistryInterface;
use BitBag\SyliusElasticsearchPlugin\Finder\ShopProductsFinder;
use BitBag\SyliusElasticsearchPlugin\Finder\ShopProductsFinderInterface;
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
@@ -25,11 +26,13 @@ final class ShopProductsFinderSpec extends ObjectBehavior
{
function let(
QueryBuilderInterface $shopProductsQueryBuilder,
PaginatedFinderInterface $productFinder
PaginatedFinderInterface $productFinder,
RegistryInterface $facetRegistry
): void {
$this->beConstructedWith(
$shopProductsQueryBuilder,
$productFinder
$productFinder,
$facetRegistry
);
}
@@ -53,6 +56,7 @@ final class ShopProductsFinderSpec extends ObjectBehavior
SortDataHandlerInterface::SORT_INDEX => null,
PaginationDataHandlerInterface::PAGE_INDEX => null,
PaginationDataHandlerInterface::LIMIT_INDEX => null,
'facets' => [],
];
$shopProductsQueryBuilder->buildQuery($data)->willReturn($boolQuery);