Skip to content

Commit

Permalink
Random codebase enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
pamil committed Oct 16, 2017
1 parent 06f5417 commit 0d43251
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 28 deletions.
5 changes: 4 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ parameters:
# Specs autoloading - needs a project-wide change to Sylius\Foo\Bar\spec\...
- '/Class spec\\Sylius\\[^ ]++ was not found while trying to analyse it - autoloading is not probably configured properly./'

# Webmozart assertions (methods defined by docblocks on class are not recognised)
# Magic calls
- '/Call to an undefined static method Webmozart\\Assert\\Assert::all/'
- '/Call to an undefined static method Webmozart\\Assert\\Assert::nullOr/'
- '/Call to an undefined method Faker\\Generator::/'
- '/Access to an undefined property Faker\\Generator::/'
- '/Method Mockery\\MockInterface::shouldReceive\(\) invoked with 1 parameter, 0 required/'

# These packages aren't in require-dev of the global package
- '/Class Doctrine\\Bundle\\MongoDBBundle/'
Expand Down
16 changes: 8 additions & 8 deletions src/Sylius/Behat/Context/Setup/OrderContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Model\PromotionCouponInterface;
use Sylius\Component\Core\Model\ShippingMethodInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\Core\OrderCheckoutTransitions;
use Sylius\Component\Core\OrderPaymentTransitions;
use Sylius\Component\Core\Repository\OrderRepositoryInterface;
Expand All @@ -39,7 +40,6 @@
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Sylius\Component\Shipping\ShipmentTransitions;
use Sylius\Component\User\Model\UserInterface;

/**
* @author Łukasz Chruściel <[email protected]>
Expand Down Expand Up @@ -160,8 +160,8 @@ public function theGuestCustomerPlacedOrderWithForAndBasedShippingAddress(
/** @var CustomerInterface $customer */
$customer = $this->customerFactory->createNew();
$customer->setEmail($email);
$customer->setFirstname('John');
$customer->setLastname('Doe');
$customer->setFirstName('John');
$customer->setLastName('Doe');

$this->customerRepository->add($customer);

Expand All @@ -184,7 +184,7 @@ public function customerStartedCheckout(CustomerInterface $customer)
/**
* @Given /^(I) placed (an order "[^"]+")$/
*/
public function iPlacedAnOrder(UserInterface $user, $orderNumber)
public function iPlacedAnOrder(ShopUserInterface $user, $orderNumber)
{
$customer = $user->getCustomer();
$order = $this->createOrder($customer, $orderNumber);
Expand Down Expand Up @@ -401,7 +401,7 @@ public function iUsedCoupon(PromotionCouponInterface $coupon)
* @Given /^(I) have already placed (\d+) orders choosing ("[^"]+" product), ("[^"]+" shipping method) (to "[^"]+") with ("[^"]+" payment)$/
*/
public function iHaveAlreadyPlacedOrderNthTimes(
UserInterface $user,
ShopUserInterface $user,
$numberOfOrders,
ProductInterface $product,
ShippingMethodInterface $shippingMethod,
Expand Down Expand Up @@ -764,8 +764,8 @@ private function createCart(
$order = $this->orderFactory->createNew();

$order->setCustomer($customer);
$order->setChannel((null !== $channel) ? $channel : $this->sharedStorage->get('channel'));
$order->setLocaleCode((null !== $localeCode) ? $localeCode : $this->sharedStorage->get('locale')->getCode());
$order->setChannel($channel ?? $this->sharedStorage->get('channel'));
$order->setLocaleCode($localeCode ?? $this->sharedStorage->get('locale')->getCode());
$order->setCurrencyCode($order->getChannel()->getBaseCurrency()->getCode());

return $order;
Expand Down Expand Up @@ -990,7 +990,7 @@ private function placeOrder(
/** @var ChannelPricingInterface $channelPricing */
$channelPricing = $variant->getChannelPricingForChannel($this->sharedStorage->get('channel'));

/** @var \Sylius\Component\Order\Model\OrderItemInterface $item */
/** @var OrderItemInterface $item */
$item = $this->orderItemFactory->createNew();
$item->setVariant($variant);
$item->setUnitPrice($channelPricing->getPrice());
Expand Down
7 changes: 5 additions & 2 deletions src/Sylius/Behat/Context/Setup/ProductContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,9 @@ public function productVariantBelongsToTaxCategory(
TaxCategoryInterface $taxCategory
) {
$productVariant->setTaxCategory($taxCategory);
$this->objectManager->flush($productVariant);

$this->objectManager->persist($productVariant);
$this->objectManager->flush();
}

/**
Expand Down Expand Up @@ -754,7 +756,8 @@ public function thisProductHasAnImageWithType(ProductInterface $product, $imageP

$product->addImage($productImage);

$this->objectManager->flush($product);
$this->objectManager->persist($product);
$this->objectManager->flush();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Sylius/Behat/Context/Setup/ProductTaxonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public function itBelongsTo(ProductInterface $product, TaxonInterface $taxon, $p
$productTaxon = $this->createProductTaxon($taxon, $product, (int) $position - 1);
$product->addProductTaxon($productTaxon);

$this->objectManager->flush($product);
$this->objectManager->persist($product);
$this->objectManager->flush();
}

/**
Expand Down
6 changes: 4 additions & 2 deletions src/Sylius/Behat/Context/Setup/TaxonomyContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ public function theTaxonHasAnImageWithType(TaxonInterface $taxon, $imagePath, $i

$taxon->addImage($taxonImage);

$this->objectManager->flush($taxon);
$this->objectManager->persist($taxon);
$this->objectManager->flush();
}

/**
Expand All @@ -155,7 +156,8 @@ public function theTaxonHasChildrenTaxonAnd(TaxonInterface $taxon, $firstTaxonNa
$taxon->addChild($this->createTaxon($firstTaxonName));
$taxon->addChild($this->createTaxon($secondTaxonName));

$this->objectManager->flush($taxon);
$this->objectManager->persist($taxon);
$this->objectManager->flush();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Sylius/Behat/Context/Setup/UserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\Common\Persistence\ObjectManager;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Bundle\CoreBundle\Fixture\Factory\ExampleFactoryInterface;
use Sylius\Component\Core\Model\ShopUserInterface;
use Sylius\Component\User\Model\UserInterface;
use Sylius\Component\User\Repository\UserRepositoryInterface;

Expand Down Expand Up @@ -84,6 +85,7 @@ public function thereIsUserIdentifiedBy($email, $password = 'sylius')
*/
public function accountWasDeleted($email)
{
/** @var ShopUserInterface $user */
$user = $this->userRepository->findOneByEmail($email);

$this->sharedStorage->set('customer', $user->getCustomer());
Expand Down
5 changes: 5 additions & 0 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingChannelsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public function iEnableIt()
*/
public function iDisableIt()
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->disable();
Expand Down Expand Up @@ -374,6 +375,7 @@ public function iShouldBeNotifiedThatItCannotBeDeleted()
*/
public function iMakeItAvailableIn($locale)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->chooseLocale($locale);
Expand All @@ -394,6 +396,7 @@ public function theChannelShouldBeAvailableIn(ChannelInterface $channel, $locale
*/
public function iAllowToPayingForThisChannel($currencyCode)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->chooseCurrency($currencyCode);
Expand All @@ -414,6 +417,7 @@ public function payingInEuroShouldBePossibleForTheChannel($currencyCode, Channel
*/
public function iSelectDefaultTaxZone($taxZone)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->chooseDefaultTaxZone($taxZone);
Expand All @@ -432,6 +436,7 @@ public function iRemoveItsDefaultTaxZone()
*/
public function iSelectTaxCalculationStrategy($taxCalculationStrategy)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->chooseTaxCalculationStrategy($taxCalculationStrategy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public function iChoose($countryName)
*/
public function iAddProvinceWithCode($provinceName, $provinceCode, $provinceAbbreviation = null)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->addProvince($provinceName, $provinceCode, $provinceAbbreviation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
use Sylius\Behat\Page\Admin\Customer\CreatePageInterface;
use Sylius\Behat\Page\Admin\Customer\IndexPageInterface as CustomerIndexPageInterface;
use Sylius\Behat\Page\Admin\Customer\ShowPageInterface;
use Sylius\Behat\Page\Admin\Customer\UpdatePageInterface;
use Sylius\Behat\Service\Resolver\CurrentPageResolverInterface;
Expand All @@ -28,7 +29,7 @@
final class ManagingCustomersContext implements Context
{
/**
* @var IndexPageInterface
* @var CustomerIndexPageInterface
*/
private $indexPage;

Expand Down Expand Up @@ -59,7 +60,7 @@ final class ManagingCustomersContext implements Context

/**
* @param CreatePageInterface $createPage
* @param IndexPageInterface $indexPage
* @param CustomerIndexPageInterface $indexPage
* @param UpdatePageInterface $updatePage
* @param ShowPageInterface $showPage
* @param IndexPageInterface $ordersIndexPage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function iWantToModifyAPaymentMethod(PaymentMethodInterface $paymentMetho
*/
public function iNameItIn($name = null, $language)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->nameIt($name, $language);
Expand Down Expand Up @@ -159,6 +160,7 @@ public function iShouldBeNotifiedThatItIsInUse()
*/
public function iChooseGateway($gatewayName)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->chooseGateway($gatewayName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ public function thePromotionShouldBeAvailableToUseOnlyTimes(PromotionInterface $
*/
public function iMakeItExclusive()
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->makeExclusive();
Expand All @@ -377,6 +378,7 @@ public function thePromotionShouldBeExclusive(PromotionInterface $promotion)
*/
public function iMakeItCouponBased()
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->checkCouponBased();
Expand All @@ -395,6 +397,7 @@ public function thePromotionShouldBeCouponBased(PromotionInterface $promotion)
*/
public function iMakeItApplicableForTheChannel($channelName)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->checkChannel($channelName);
Expand Down Expand Up @@ -475,6 +478,7 @@ public function iShouldBeNotifiedOfFailure()
*/
public function iMakeItAvailableFromTo(\DateTimeInterface $startsDate, \DateTimeInterface $endsDate)
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */
$currentPage = $this->currentPageResolver->getCurrentPageWithForm([$this->createPage, $this->updatePage]);

$currentPage->setStartsAt($startsDate);
Expand Down
6 changes: 3 additions & 3 deletions src/Sylius/Behat/Page/Admin/Country/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sylius\Behat\Page\Admin\Country;

use Behat\Mink\Element\Element;
use Behat\Mink\Element\NodeElement;
use Sylius\Behat\Behaviour\ChoosesName;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -55,9 +55,9 @@ protected function getDefinedElements()
}

/**
* @return Element
* @return NodeElement
*/
private function getLastProvinceElement()
private function getLastProvinceElement(): NodeElement
{
$provinces = $this->getElement('provinces');
$items = $provinces->findAll('css', 'div[data-form-collection="item"]');
Expand Down
6 changes: 3 additions & 3 deletions src/Sylius/Behat/Page/Admin/Country/UpdatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sylius\Behat\Page\Admin\Country;

use Behat\Mink\Element\Element;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\Behaviour\Toggles;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
Expand Down Expand Up @@ -171,9 +171,9 @@ protected function getDefinedElements()
}

/**
* @return Element
* @return NodeElement
*/
private function getLastProvinceElement()
private function getLastProvinceElement(): NodeElement
{
$provinces = $this->getElement('provinces');
$items = $provinces->findAll('css', 'div[data-form-collection="item"]');
Expand Down
6 changes: 3 additions & 3 deletions src/Sylius/Behat/Page/Admin/ProductOption/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sylius\Behat\Page\Admin\ProductOption;

use Behat\Mink\Element\Element;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\Behaviour\SpecifiesItsCode;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
Expand Down Expand Up @@ -76,9 +76,9 @@ protected function getDefinedElements()
}

/**
* @return Element
* @return NodeElement
*/
private function getLastOptionValueElement()
private function getLastOptionValueElement(): NodeElement
{
$optionValues = $this->getElement('values');
$items = $optionValues->findAll('css', 'div[data-form-collection="item"]');
Expand Down
6 changes: 3 additions & 3 deletions src/Sylius/Behat/Page/Admin/ProductOption/UpdatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Sylius\Behat\Page\Admin\ProductOption;

use Behat\Mink\Element\Element;
use Behat\Mink\Element\NodeElement;
use Sylius\Behat\Behaviour\ChecksCodeImmutability;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -98,9 +98,9 @@ protected function getDefinedElements()
}

/**
* @return Element
* @return NodeElement
*/
private function getLastOptionValueElement()
private function getLastOptionValueElement(): NodeElement
{
$optionValues = $this->getElement('values');
$items = $optionValues->findAll('css', 'div[data-form-collection="item"]');
Expand Down

0 comments on commit 0d43251

Please sign in to comment.