Skip to content

Commit

Permalink
Make tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
pamil committed Aug 21, 2018
1 parent 486ea45 commit f23bd51
Show file tree
Hide file tree
Showing 85 changed files with 371 additions and 408 deletions.
2 changes: 1 addition & 1 deletion src/Handler/SetDefaultAddressHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public function handle(SetDefaultAddress $setDefaultAddress): void
private function assertCurrentUserIsOwner(AddressInterface $address, ShopUserInterface $user)
{
Assert::notNull($address->getCustomer(), 'Address is not associated with any user.');
Assert::eq($address->getCustomer()->getId(), $user->getId(), 'Current user is not owner of this address.');
Assert::eq($address->getCustomer()->getId(), $user->getCustomer()->getId(), 'Current user is not owner of this address.');
}
}
2 changes: 2 additions & 0 deletions src/Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<import resource="services/queries.xml"/>
</imports>
<services>
<defaults public="true" />

<service id="sylius.shop_api_plugin.checker.promotion_coupon_eligibility_checker" class="Sylius\ShopApiPlugin\Checker\PromotionCouponEligibilityChecker">
<argument type="service" id="sylius.promotion_eligibility_checker"/>
<argument type="service" id="sylius.promotion_coupon_eligibility_checker"/>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/actions/address_book.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius.shop_api_plugin.controller.address_book.create_address_action"
class="Sylius\ShopApiPlugin\Controller\AddressBook\CreateAddressAction"
>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/actions/cart.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius.shop_api_plugin.controller.cart.summarize_action"
class="Sylius\ShopApiPlugin\Controller\Cart\SummarizeAction"
>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/actions/checkout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius.shop_api_plugin.controller.checkout.address_action"
class="Sylius\ShopApiPlugin\Controller\Checkout\AddressAction"
>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/actions/customer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius.shop_api_plugin.controller.customer.resend_verification_token_action"
class="Sylius\ShopApiPlugin\Controller\Customer\ResendVerificationTokenAction"
>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/actions/product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius.shop_api_plugin.controller.product.show_product_details_by_slug_action"
class="Sylius\ShopApiPlugin\Controller\Product\ShowProductDetailsBySlugAction"
>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/actions/taxon.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius.shop_api_plugin.controller.taxon.show_taxon_tree_action"
class="Sylius\ShopApiPlugin\Controller\Taxon\ShowTaxonTreeAction"
>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/factories.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius.shop_api_plugin.factory.image_view_factory" class="Sylius\ShopApiPlugin\Factory\ImageViewFactory">
<argument type="string">%sylius.shop_api.view.image.class%</argument>
</service>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/handlers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius.shop_api_plugin.handler.address_shipment" class="Sylius\ShopApiPlugin\Handler\AddressOrderHandler">
<argument type="service" id="sylius.repository.order"/>
<argument type="service" id="sylius.factory.address"/>
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/queries.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius.shop_api_plugin.view_repository.cart_view_repository" class="Sylius\ShopApiPlugin\ViewRepository\CartViewRepository">
<argument type="service" id="sylius.repository.order" />
<argument type="service" id="sylius.shop_api_plugin.factory.cart_view_factory" />
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/config/services/validators.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<defaults public="true" />

<service id="sylius.shop_api_plugin.validator.channel_exists_validator"
class="Sylius\ShopApiPlugin\Validator\ChannelExistsValidator"
>
Expand Down
2 changes: 1 addition & 1 deletion src/ViewRepository/ProductCatalogViewRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private function getLocaleCode(?string $localeCode, ChannelInterface $channel):
private function findByTaxon(TaxonInterface $taxon, ChannelInterface $channel, PaginatorDetails $paginatorDetails, string $localeCode): PageView
{
$queryBuilder = $this->productRepository->createShopListQueryBuilder($channel, $taxon, $localeCode);
$queryBuilder->addOrderBy('o.id');
$queryBuilder->addOrderBy('productTaxon.position');

$pagerfanta = new Pagerfanta(new DoctrineORMAdapter($queryBuilder));

Expand Down
2 changes: 1 addition & 1 deletion tests/Application/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function registerBundles(): array
new \Sylius\ShopApiPlugin\ShopApiPlugin(),
new \Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle(),

new \Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle(),
new \Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle(),
new \Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle(),
]);

return $bundles;
Expand Down
5 changes: 0 additions & 5 deletions tests/Application/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,3 @@ swiftmailer:
spool:
type: file
path: "%kernel.cache_dir%/spool"

fidry_alice_data_fixtures:
default_purge_mode: no_purge
db_drivers:
doctrine_orm: true
24 changes: 10 additions & 14 deletions tests/Controller/AddressBookCreateAddressApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ final class AddressBookCreateAddressApiTest extends JsonApiTestCase
*/
public function it_allows_user_to_add_new_address_to_address_book()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml']);
$this->logInUser('oliver@queen.com', '123password');

$data =
<<<EOT
Expand All @@ -47,12 +46,12 @@ public function it_allows_user_to_add_new_address_to_address_book()
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);

/** @var CustomerRepositoryInterface $customerRepository */
$customerRepository = $this->get('sylius.repository.customer');
$customerRepository = self::$container->get('sylius.repository.customer');
/** @var Customer $customer */
$customer = $customerRepository->findOneBy(['email' => 'oliver@queen.com']);

/** @var AddressRepositoryInterface $addressRepository */
$addressRepository = $this->get('sylius.repository.address');
$addressRepository = self::$container->get('sylius.repository.address');
/** @var AddressInterface $address */
$address = $addressRepository->findOneBy(['street' => 'Kupreska 12']);

Expand All @@ -66,9 +65,8 @@ public function it_allows_user_to_add_new_address_to_address_book()
*/
public function it_does_not_allow_user_to_add_new_address_to_address_book_without_passing_required_data()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml']);
$this->logInUser('oliver@queen.com', '123password');

$data =
<<<EOT
Expand All @@ -94,9 +92,8 @@ public function it_does_not_allow_user_to_add_new_address_to_address_book_withou
*/
public function it_does_not_allow_user_to_add_new_address_to_address_book_without_passing_correct_country_code()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml']);
$this->logInUser('oliver@queen.com', '123password');

$data =
<<<EOT
Expand All @@ -121,9 +118,8 @@ public function it_does_not_allow_user_to_add_new_address_to_address_book_withou
*/
public function it_does_not_allow_user_to_add_new_address_to_address_book_without_passing_correct_province_code()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml']);
$this->logInUser('oliver@queen.com', '123password');

$data =
<<<EOT
Expand Down
22 changes: 8 additions & 14 deletions tests/Controller/AddressBookRemoveAddressApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ final class AddressBookRemoveAddressApiTest extends JsonApiTestCase
*/
public function it_deletes_address_from_address_book()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->loadFixturesFromFile('address.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml', 'address.yml']);
$this->logInUser('oliver@queen.com', '123password');

/** @var AddressRepositoryInterface $addressRepository */
$addressRepository = $this->get('sylius.repository.address');
$addressRepository = self::$container->get('sylius.repository.address');
/** @var AddressInterface $address */
$address = $addressRepository->findOneBy(['street' => 'Kupreska']);

Expand All @@ -46,10 +44,8 @@ public function it_deletes_address_from_address_book()
*/
public function it_returns_bad_request_exception_if_address_has_not_been_found()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->loadFixturesFromFile('address.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml', 'address.yml']);
$this->logInUser('oliver@queen.com', '123password');

$this->client->request('DELETE', sprintf('/shop-api/address-book/-1'), [], [], self::$acceptAndContentTypeHeader);
$response = $this->client->getResponse();
Expand All @@ -62,13 +58,11 @@ public function it_returns_bad_request_exception_if_address_has_not_been_found()
*/
public function it_validates_if_current_user_is_owner_of_address()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->loadFixturesFromFile('address.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml', 'address.yml']);
$this->logInUser('oliver@queen.com', '123password');

/** @var AddressRepositoryInterface $addressRepository */
$addressRepository = $this->get('sylius.repository.address');
$addressRepository = self::$container->get('sylius.repository.address');
/** @var AddressInterface $address */
$address = $addressRepository->findOneBy(['street' => 'Vukovarska']);

Expand Down
10 changes: 4 additions & 6 deletions tests/Controller/AddressBookSetDefaultAddressApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ final class AddressBookSetDefaultAddressApiTest extends JsonApiTestCase
*/
public function it_sets_given_address_as_default()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->loadFixturesFromFile('address.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml', 'address.yml']);
$this->logInUser('oliver@queen.com', '123password');

/** @var AddressRepositoryInterface $addressRepository */
$addressRepository = $this->get('sylius.repository.address');
$addressRepository = self::$container->get('sylius.repository.address');
/** @var ResourceInterface $address */
$address = $addressRepository->findOneBy(['street' => 'Kupreska']);

Expand All @@ -39,7 +37,7 @@ public function it_sets_given_address_as_default()
$this->assertResponseCode($response, Response::HTTP_NO_CONTENT);

/** @var UserRepositoryInterface $userRepository */
$userRepository = $this->get('sylius.repository.shop_user');
$userRepository = self::$container->get('sylius.repository.shop_user');
/** @var ShopUser $address */
$shopUser = $userRepository->findOneBy(['username' => 'oliver@queen.com']);

Expand Down
6 changes: 2 additions & 4 deletions tests/Controller/AddressBookShowApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ final class AddressBookShowApiTest extends JsonApiTestCase
*/
public function it_shows_address_book()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->loadFixturesFromFile('address.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml', 'address.yml']);
$this->logInUser('oliver@queen.com', '123password');

$this->client->request('GET', '/shop-api/address-book', [], [], ['ACCEPT' => 'application/json']);
$response = $this->client->getResponse();
Expand Down
24 changes: 9 additions & 15 deletions tests/Controller/AddressBookUpdateAddressApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ final class AddressBookUpdateAddressApiTest extends JsonApiTestCase
*/
public function it_updates_address_in_address_book()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->loadFixturesFromFile('address.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml', 'address.yml']);
$this->logInUser('oliver@queen.com', '123password');

/** @var AddressRepositoryInterface $addressRepository */
$addressRepository = $this->get('sylius.repository.address');
$addressRepository = self::$container->get('sylius.repository.address');
/** @var AddressInterface $address */
$address = $addressRepository->findOneBy(['street' => 'Kupreska']);

Expand Down Expand Up @@ -67,13 +65,11 @@ public function it_updates_address_in_address_book()
*/
public function it_does_not_allow_to_update_address_if_country_or_province_code_are_not_valid()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->loadFixturesFromFile('address.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml', 'address.yml']);
$this->logInUser('oliver@queen.com', '123password');

/** @var AddressRepositoryInterface $addressRepository */
$addressRepository = $this->get('sylius.repository.address');
$addressRepository = self::$container->get('sylius.repository.address');
/** @var AddressInterface $address */
$address = $addressRepository->findOneBy(['street' => 'Kupreska']);

Expand Down Expand Up @@ -102,13 +98,11 @@ public function it_does_not_allow_to_update_address_if_country_or_province_code_
*/
public function it_does_not_allow_to_update_address_without_passing_required_data()
{
$this->loadFixturesFromFile('customer.yml');
$this->loadFixturesFromFile('country.yml');
$this->loadFixturesFromFile('address.yml');
$this->logInUser('oliver@queen.com', '123pa$$word');
$this->loadFixturesFromFiles(['customer.yml', 'country.yml', 'address.yml']);
$this->logInUser('oliver@queen.com', '123password');

/** @var AddressRepositoryInterface $addressRepository */
$addressRepository = $this->get('sylius.repository.address');
$addressRepository = self::$container->get('sylius.repository.address');
/** @var AddressInterface $address */
$address = $addressRepository->findOneBy(['street' => 'Kupreska']);

Expand Down
Loading

0 comments on commit f23bd51

Please sign in to comment.