Skip to content

Commit 3a57244

Browse files
authored
Merge pull request #5 from BitBagCommerce/dev
Add Behat and PhpSpec
2 parents 13c66f3 + 7f9849e commit 3a57244

File tree

58 files changed

+3112
-29
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+3112
-29
lines changed

.travis.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ php:
88
- 7.1
99
- 7.2
1010

11+
addons:
12+
apt:
13+
sources:
14+
- elasticsearch-5.x
15+
packages:
16+
- elasticsearch
17+
18+
services:
19+
- elasticsearch
20+
1121
cache:
1222
yarn: true
1323
directories:
@@ -32,6 +42,7 @@ before_script:
3242
- (cd tests/Application && bin/console doctrine:database:create --env=test -vvv)
3343
- (cd tests/Application && bin/console doctrine:schema:create --env=test -vvv)
3444
- (cd tests/Application && bin/console assets:install web --env=test -vvv)
45+
- (cd tests/Application && bin/console fos:elastica:populate --env=test)
3546
- (cd tests/Application && yarn run gulp)
3647

3748
# Configure display

features/shop/filtering_products.feature

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,62 @@ Feature: Filtering products
66

77
Background:
88
Given the store operates on a channel named "Web-US" in "USD" currency
9-
And there are 15 t-shirts in the store
9+
And the store classifies its products as "T-Shirts"
10+
And there are 45 t-shirts in the store
11+
And these products belongs to "T-Shirts" taxon
1012
And 5 of these products are priced between "$10" and "$15"
1113
And 10 of these products are priced between "$15" and "$35"
12-
And these "products" have "size" option
13-
And 3 of these products have "size" option with "S" value
14-
And 5 of these products have "size" option with "M" value
15-
And 7 of these products have "size" option with "M" value
16-
And these "products" have "color" attribute
17-
And 3 of these products have "color" attribute with "Red" value
18-
And 5 of these products have "color" attribute with "Green" value
19-
And 7 of these products have "color" attribute with "Blue" value
14+
And these products have "Size" option with values "S,M,L"
15+
And 3 of these products have "Size" option with "S" value
16+
And 5 of these products have "Size" option with "M" value
17+
And 7 of these products have "Size" option with "L" value
18+
And these products have text attribute "color"
19+
And 3 of these products have text attribute "color" with "Red" value
20+
And 5 of these products have text attribute "color" with "Green" value
21+
And 7 of these products have text attribute "color" with "Blue" value
22+
And the data is populated to elasticsearch
2023

2124
@ui
2225
Scenario: Filtering products by name
23-
When I go to the shop products page
26+
When I go to the shop products page for "T-Shirts" taxon
2427
And I search the products by "shirt" phase
25-
Then I should see 9 products on the first page
26-
And I should see 6 products on the second page
28+
Then I should see 9 products on 1 page
29+
And I should see 9 products on 2 page
30+
And I should see 9 products on 3 page
31+
And I should see 9 products on 4 page
32+
And I should see 9 products on 5 page
2733

2834
@ui
2935
Scenario: Filtering products by options
30-
When I go to the shop products page
36+
When I go to the shop products page for "T-Shirts" taxon
3137
And I filter products by "S" "Size" option
3238
And I filter products by "M" "Size" option
3339
Then I should see 8 products on the page
3440

3541
@ui
3642
Scenario: Filtering products by attributes
37-
When I go to the shop products page
38-
And I filter products by "Red" "Color" attribute
39-
And I filter products by "Green" "Color" attribute
43+
When I go to the shop products page for "T-Shirts" taxon
44+
And I filter products by "Red" "color" attribute
45+
And I filter products by "Green" "color" attribute
4046
Then I should see 8 products on the page
4147

4248
@ui
4349
Scenario: Filtering products by price
44-
When I go to the shop products page
50+
When I go to the shop products page for "T-Shirts" taxon
4551
And I filter product price between 10 and 15
4652
Then I should see 5 products on the page
4753

4854
@ui
4955
Scenario: Changing limit from 9 to 18
50-
Given there are 40 more products in the store
51-
When I go to the products page
56+
When I go to the shop products page for "T-Shirts" taxon
5257
And I change the limit to 18
53-
Then I should see 18 products on the first page
54-
And I should see 18 products on the second page
55-
And I should see 9 products on the third page
58+
Then I should see 18 products on 1 page
59+
And I should see 18 products on 2 page
60+
And I should see 9 products on 3 page
5661

5762
@ui
5863
Scenario: Changing limit from 9 to 36
59-
Given there are 40 more products in the store
60-
When I go to the products page
64+
When I go to the shop products page for "T-Shirts" taxon
6165
And I change the limit to 36
62-
Then I should see 36 products on the first page
63-
And I should see 9 products on the second page
66+
Then I should see 36 products on 1 page
67+
And I should see 9 products on 2 page
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file has been created by developers from BitBag.
5+
* Feel free to contact us once you face any issues or want to start
6+
* another great project.
7+
* You can find more information about us on https://bitbag.shop and write us
8+
* an email on mikolaj.krol@bitbag.pl.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace spec\BitBag\SyliusElasticsearchPlugin\Context;
14+
15+
use BitBag\SyliusElasticsearchPlugin\Context\ProductAttributesContext;
16+
use BitBag\SyliusElasticsearchPlugin\Context\ProductAttributesContextInterface;
17+
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContextInterface;
18+
use BitBag\SyliusElasticsearchPlugin\Finder\ProductAttributesFinderInterface;
19+
use PhpSpec\ObjectBehavior;
20+
use Sylius\Component\Core\Model\TaxonInterface;
21+
22+
final class ProductAttributesContextSpec extends ObjectBehavior
23+
{
24+
function let(
25+
TaxonContextInterface $taxonContext,
26+
ProductAttributesFinderInterface $attributesFinder
27+
): void {
28+
$this->beConstructedWith($taxonContext, $attributesFinder);
29+
}
30+
31+
function it_is_initializable(): void
32+
{
33+
$this->shouldHaveType(ProductAttributesContext::class);
34+
}
35+
36+
function it_implements_product_attributes_context_interface(): void
37+
{
38+
$this->shouldHaveType(ProductAttributesContextInterface::class);
39+
}
40+
41+
function it_gets_attributes(
42+
TaxonContextInterface $taxonContext,
43+
ProductAttributesFinderInterface $attributesFinder,
44+
TaxonInterface $taxon
45+
): void {
46+
$taxonContext->getTaxon()->willReturn($taxon);
47+
48+
$attributesFinder->findByTaxon($taxon)->willReturn([]);
49+
50+
$this->getAttributes()->shouldBeEqualTo([]);
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file has been created by developers from BitBag.
5+
* Feel free to contact us once you face any issues or want to start
6+
* another great project.
7+
* You can find more information about us on https://bitbag.shop and write us
8+
* an email on mikolaj.krol@bitbag.pl.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace spec\BitBag\SyliusElasticsearchPlugin\Context;
14+
15+
use BitBag\SyliusElasticsearchPlugin\Context\ProductOptionsContext;
16+
use BitBag\SyliusElasticsearchPlugin\Context\ProductOptionsContextInterface;
17+
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContextInterface;
18+
use BitBag\SyliusElasticsearchPlugin\Finder\ProductOptionsFinderInterface;
19+
use PhpSpec\ObjectBehavior;
20+
use Sylius\Component\Core\Model\TaxonInterface;
21+
22+
final class ProductOptionsContextSpec extends ObjectBehavior
23+
{
24+
function let(
25+
TaxonContextInterface $taxonContext,
26+
ProductOptionsFinderInterface $optionsFinder
27+
): void {
28+
$this->beConstructedWith($taxonContext, $optionsFinder);
29+
}
30+
31+
function it_is_initializable(): void
32+
{
33+
$this->shouldHaveType(ProductOptionsContext::class);
34+
}
35+
36+
function it_implements_product_options_context_interface(): void
37+
{
38+
$this->shouldHaveType(ProductOptionsContextInterface::class);
39+
}
40+
41+
function it_gets_options(
42+
TaxonContextInterface $taxonContext,
43+
ProductOptionsFinderInterface $optionsFinder,
44+
TaxonInterface $taxon
45+
): void {
46+
$taxonContext->getTaxon()->willReturn($taxon);
47+
48+
$optionsFinder->findByTaxon($taxon)->willReturn([]);
49+
50+
$this->getOptions()->shouldBeEqualTo([]);
51+
}
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/*
4+
* This file has been created by developers from BitBag.
5+
* Feel free to contact us once you face any issues or want to start
6+
* another great project.
7+
* You can find more information about us on https://bitbag.shop and write us
8+
* an email on mikolaj.krol@bitbag.pl.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace spec\BitBag\SyliusElasticsearchPlugin\Context;
14+
15+
use BitBag\SyliusElasticsearchPlugin\Context\ProductAttributesContextInterface;
16+
use BitBag\SyliusElasticsearchPlugin\Context\ProductProductAttributesContext;
17+
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContextInterface;
18+
use BitBag\SyliusElasticsearchPlugin\Finder\ProductAttributesFinderInterface;
19+
use PhpSpec\ObjectBehavior;
20+
use Sylius\Component\Core\Model\TaxonInterface;
21+
22+
final class ProductProductAttributesContextSpec extends ObjectBehavior
23+
{
24+
function let(
25+
TaxonContextInterface $taxonContext,
26+
ProductAttributesFinderInterface $attributesFinder
27+
): void {
28+
$this->beConstructedWith($taxonContext, $attributesFinder);
29+
}
30+
31+
function it_is_initializable(): void
32+
{
33+
$this->shouldHaveType(ProductProductAttributesContext::class);
34+
}
35+
36+
function it_implements_product_attributes_context_interface(): void
37+
{
38+
$this->shouldHaveType(ProductAttributesContextInterface::class);
39+
}
40+
41+
function it_gets_attributes(
42+
TaxonContextInterface $taxonContext,
43+
ProductAttributesFinderInterface $attributesFinder,
44+
TaxonInterface $taxon
45+
): void {
46+
$taxonContext->getTaxon()->willReturn($taxon);
47+
48+
$attributesFinder->findByTaxon($taxon)->willReturn([]);
49+
50+
$this->getAttributes()->shouldBeEqualTo([]);
51+
}
52+
}

spec/Context/TaxonContextSpec.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/*
4+
* This file has been created by developers from BitBag.
5+
* Feel free to contact us once you face any issues or want to start
6+
* another great project.
7+
* You can find more information about us on https://bitbag.shop and write us
8+
* an email on mikolaj.krol@bitbag.pl.
9+
*/
10+
11+
declare(strict_types=1);
12+
13+
namespace spec\BitBag\SyliusElasticsearchPlugin\Context;
14+
15+
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContext;
16+
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContextInterface;
17+
use BitBag\SyliusElasticsearchPlugin\Exception\TaxonNotFoundException;
18+
use PhpSpec\ObjectBehavior;
19+
use Sylius\Component\Core\Model\TaxonInterface;
20+
use Sylius\Component\Locale\Context\LocaleContextInterface;
21+
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
22+
use Symfony\Component\HttpFoundation\Request;
23+
use Symfony\Component\HttpFoundation\RequestStack;
24+
25+
final class TaxonContextSpec extends ObjectBehavior
26+
{
27+
function let(
28+
RequestStack $requestStack,
29+
TaxonRepositoryInterface $taxonRepository,
30+
LocaleContextInterface $localeContext
31+
): void {
32+
$this->beConstructedWith($requestStack, $taxonRepository, $localeContext);
33+
}
34+
35+
function it_is_initializable(): void
36+
{
37+
$this->shouldHaveType(TaxonContext::class);
38+
}
39+
40+
function it_implements_taxon_context_interface(): void
41+
{
42+
$this->shouldHaveType(TaxonContextInterface::class);
43+
}
44+
45+
function it_gets_taxon(
46+
RequestStack $requestStack,
47+
TaxonRepositoryInterface $taxonRepository,
48+
LocaleContextInterface $localeContext,
49+
Request $request,
50+
TaxonInterface $taxon
51+
): void {
52+
$request->get('slug')->willReturn('book');
53+
54+
$requestStack->getCurrentRequest()->willReturn($request);
55+
56+
$localeContext->getLocaleCode()->willReturn('en');
57+
58+
$taxonRepository->findOneBySlug('book', 'en')->willReturn($taxon);
59+
60+
$this->getTaxon()->shouldBeEqualTo($taxon);
61+
}
62+
63+
function it_throws_taxon_not_found_exception_if_taxon_is_null(
64+
RequestStack $requestStack,
65+
TaxonRepositoryInterface $taxonRepository,
66+
LocaleContextInterface $localeContext,
67+
Request $request
68+
): void {
69+
$request->get('slug')->willReturn('book');
70+
71+
$requestStack->getCurrentRequest()->willReturn($request);
72+
73+
$localeContext->getLocaleCode()->willReturn('en');
74+
75+
$taxonRepository->findOneBySlug('book', 'en')->willReturn(null);
76+
77+
$this->shouldThrow(TaxonNotFoundException::class)->during('getTaxon');
78+
}
79+
}

0 commit comments

Comments
 (0)