Skip to content

Commit

Permalink
Tests n minor fixes (#50)
Browse files Browse the repository at this point in the history
* WIP: refactoring & tests

* WIP: ShoppingListBundle tests & refactorings

* WIP: SetupBundle repo test

* WIP: more tests

* WIP: CustomerBundle tests

* WIP: CatalogBundle Tests

* feat(Symfony): add missing interface function to data collector to support symfony 4

Closes #48

* WIP: ExampleBundle tests

* WIP: StateBundle tests & refactoring

* wIP: StateBundle tests

* WIP: CtpBundle tests

* WIP: ExampleBundle form tests

* WIP: ExampleBundle refactor Form Types

* WIP: ExampleBundle refactor ProductEntity

* WIP: additional tests

* WIP: ExampleBundle, Controllers tests

* WIP: minor improvements

* WIP: add tests for Search

* fix dependencies version

* chore(travis): add travis build

* update to symfony 4.2, fix deprecated
  • Loading branch information
nikossvnk authored and Jens Schulze committed Dec 4, 2018
1 parent a327a18 commit 7fb9ee4
Show file tree
Hide file tree
Showing 195 changed files with 10,593 additions and 832 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,3 +3,4 @@ vendor
composer.lock
.phan
analysis.txt
/var/
14 changes: 14 additions & 0 deletions .travis.yml
@@ -0,0 +1,14 @@
dist: xenial
sudo: false
language: php
php:
- 7.1
- 7.2
- nightly
matrix:
allow_failures:
- php: nightly
before_script:
- composer install
script:
- vendor/bin/phpunit
11 changes: 7 additions & 4 deletions composer.json
Expand Up @@ -9,27 +9,30 @@
}
},
"require": {
"php": ">=5.6",
"php": ">=7.0",
"symfony/framework-bundle": "^3.4 | ^4.0",
"symfony/form": "^3.4 | ^4.0",
"symfony/templating": "^3.4 | ^4.0",
"symfony/security-bundle": "^3.4 | ^4.0",
"symfony/validator": "^3.4 | ^4.0",
"symfony/serializer": "^3.4 | ^4.0",
"symfony/cache": "^3.4 | ^4.0",
"commercetools/php-sdk": "^2.5",
"commercetools/php-sdk": "dev-develop",
"symfony/var-dumper": "^3.4 | ^4.0",
"symfony/dotenv": "^3.4 | ^4.0",
"symfony/stopwatch": "^3.4 | ^4.0",
"symfony/workflow": "^3.4 | ^4.0",
"twig/extensions": "^1.5"
"twig/extensions": "^1.5",
"symfony/console": "^3.4 | ^4.0",
"symfony/twig-bundle": "^3.4 | ^4.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0 | ^6.0 | ^5.0",
"symfony/phpunit-bridge": "^3.4 | ^4.0",
"commercetools/commercetools-api-reference": "dev-master",
"matthiasnoback/symfony-dependency-injection-test": "^3.0",
"symfony/test-pack": "^1.0"
"symfony/test-pack": "^1.0",
"cache/filesystem-adapter": "^1.0"
},
"extra": {
"branch-alias": {
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Expand Up @@ -8,6 +8,7 @@
>
<php>
<ini name="error_reporting" value="-1" />
<server name="KERNEL_CLASS" value="Commercetools\Symfony\CtpBundle\Tests\TestKernel" />
</php>

<testsuites>
Expand Down
8 changes: 0 additions & 8 deletions src/CartBundle/Event/OrderPostUpdateEvent.php
Expand Up @@ -41,12 +41,4 @@ public function getOrder()
{
return $this->order;
}

/**
* @param Order $order
*/
public function setOrder(Order $order)
{
$this->order = $order;
}
}
8 changes: 0 additions & 8 deletions src/CartBundle/Event/PaymentPostUpdateEvent.php
Expand Up @@ -41,12 +41,4 @@ public function getPayment()
{
return $this->payment;
}

/**
* @param Payment $payment
*/
public function setPayment(Payment $payment)
{
$this->payment = $payment;
}
}
10 changes: 5 additions & 5 deletions src/CartBundle/Manager/PaymentManager.php
Expand Up @@ -55,23 +55,23 @@ public function getPaymentById($locale, $paymentId)
/**
* @param $locale
* @param $paymentId
* @param UserInterface $user
* @param CustomerReference|null $customer
* @param string|null $anonymousId
* @return PaymentCollection
*/
public function getPaymentForUser($locale, $paymentId, UserInterface $user = null, $anonymousId = null)
public function getPaymentForUser($locale, $paymentId, CustomerReference $customer = null, $anonymousId = null)
{
return $this->repository->getPaymentForUser($locale, $paymentId, $user, $anonymousId);
return $this->repository->getPaymentForUser($locale, $paymentId, $customer, $anonymousId);
}

/**
* @param $locale
* @param array $payments
* @return array|mixed
*/
public function getPaymentsForOrder($locale, array $payments)
public function getMultiplePayments($locale, array $payments)
{
return $this->repository->getPaymentsForOrder($locale, $payments);
return $this->repository->getMultiplePayments($locale, $payments);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/CartBundle/Model/Repository/CartRepository.php
Expand Up @@ -102,4 +102,15 @@ public function update(Cart $cart, array $actions, QueryParams $params = null)

return $this->executeRequest($request);
}

/**
* @param Cart $cart
* @return Cart
*/
public function delete(Cart $cart)
{
$request = RequestBuilder::of()->carts()->delete($cart);

return $this->executeRequest($request);
}
}
20 changes: 17 additions & 3 deletions src/CartBundle/Model/Repository/OrderRepository.php
Expand Up @@ -96,12 +96,15 @@ public function getOrderFromPayment($locale, $paymentId, UserInterface $user = n
* @param StateReference $stateReference
* @return Order
*/
public function createOrderFromCart($locale, Cart $cart, StateReference $stateReference)
public function createOrderFromCart($locale, Cart $cart, StateReference $stateReference = null)
{
$request = RequestBuilder::of()->orders()
->createFromCart($cart)
->setOrderNumber($this->createOrderNumber())
->setState($stateReference);
->setOrderNumber($this->createOrderNumber());

if (!is_null($stateReference)) {
$request->setState($stateReference);
}

return $this->executeRequest($request, $locale);
}
Expand Down Expand Up @@ -132,4 +135,15 @@ public function update(Order $order, array $actions, QueryParams $params = null)

return $this->executeRequest($request);
}

/**
* @param Order $order
* @return mixed
*/
public function delete(Order $order)
{
$request = RequestBuilder::of()->orders()->delete($order);

return $this->executeRequest($request);
}
}
4 changes: 2 additions & 2 deletions src/CartBundle/Model/Repository/PaymentRepository.php
Expand Up @@ -57,9 +57,9 @@ public function getPaymentForUser($locale, $paymentId, CustomerReference $custom
/**
* @param $locale
* @param array $payments
* @return array|mixed
* @return PaymentCollection
*/
public function getPaymentsForOrder($locale, array $payments)
public function getMultiplePayments($locale, array $payments)
{
$request = RequestBuilder::of()->payments()->query();

Expand Down
40 changes: 40 additions & 0 deletions src/CartBundle/Tests/DependencyInjection/CartExtensionTest.php
@@ -0,0 +1,40 @@
<?php
/**
*
*/

namespace Commercetools\Symfony\CartBundle\Tests\DependencyInjection;


use Commercetools\Symfony\CartBundle\DependencyInjection\CartExtension;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;

class CartExtensionTest extends AbstractExtensionTestCase
{
protected function getContainerExtensions()
{
return [
new CartExtension()
];
}

public function testExtensionLoads()
{
$this->load();

$this->assertContainerBuilderHasParameter('commercetools.cache.cart', 'false');
$this->assertContainerBuilderHasParameter('commercetools.cache.shipping_method', 'false');
$this->assertContainerBuilderHasParameter('commercetools.cache.order', 'false');
$this->assertContainerBuilderHasParameter('commercetools.cache.payment', 'false');

$this->assertContainerBuilderHasService('Commercetools\Symfony\CartBundle\Model\Repository\CartRepository');
$this->assertContainerBuilderHasService('Commercetools\Symfony\CartBundle\Model\Repository\PaymentRepository');
$this->assertContainerBuilderHasService('Commercetools\Symfony\CartBundle\Model\Repository\OrderRepository');
$this->assertContainerBuilderHasService('Commercetools\Symfony\CartBundle\Model\Repository\ShippingMethodRepository');

$this->assertContainerBuilderHasService('Commercetools\Symfony\CartBundle\Manager\CartManager');
$this->assertContainerBuilderHasService('Commercetools\Symfony\CartBundle\Manager\PaymentManager');
$this->assertContainerBuilderHasService('Commercetools\Symfony\CartBundle\Manager\OrderManager');
$this->assertContainerBuilderHasService('Commercetools\Symfony\CartBundle\Manager\ShippingMethodManager');
}
}
20 changes: 20 additions & 0 deletions src/CartBundle/Tests/Event/CartGetEventTest.php
@@ -0,0 +1,20 @@
<?php
/**
*
*/

namespace Commercetools\Symfony\CartBundle\Tests\Event;


use Commercetools\Core\Model\Cart\Cart;
use Commercetools\Symfony\CartBundle\Event\CartGetEvent;
use PHPUnit\Framework\TestCase;

class CartGetEventTest extends TestCase
{
public function testCartGetEvent()
{
$getEvent = new CartGetEvent(Cart::of());
$this->assertInstanceOf(Cart::class, $getEvent->getCart());
}
}
20 changes: 20 additions & 0 deletions src/CartBundle/Tests/Event/CartPostCreateEventTest.php
@@ -0,0 +1,20 @@
<?php
/**
*
*/

namespace Commercetools\Symfony\CartBundle\Tests\Event;


use Commercetools\Core\Model\Cart\Cart;
use Commercetools\Symfony\CartBundle\Event\CartPostCreateEvent;
use PHPUnit\Framework\TestCase;

class CartPostCreateEventTest extends TestCase
{
public function testCartPostCreateEvent()
{
$postCreateEvent = new CartPostCreateEvent(Cart::of());
$this->assertInstanceOf(Cart::class, $postCreateEvent->getCart());
}
}
2 changes: 0 additions & 2 deletions src/CartBundle/Tests/Event/CartUpdateEventTest.php
Expand Up @@ -26,11 +26,9 @@ public function testCartUpdateEvent()
$this->assertEquals([$action->reveal()], $updateEvent->getActions());

$updateEvent->addAction($secondAction->reveal());

$this->assertEquals([$action->reveal(), $secondAction->reveal()], $updateEvent->getActions());

$updateEvent->setActions([$secondAction->reveal()]);

$this->assertEquals([$secondAction->reveal()], $updateEvent->getActions());
}
}
15 changes: 3 additions & 12 deletions src/CartBundle/Tests/Event/OrderPostUpdateEventTest.php
Expand Up @@ -15,17 +15,8 @@ class OrderPostUpdateEventTest extends TestCase
{
public function testOrderPostUpdateEvent()
{
$order = $this->prophesize(Order::class);
$action = $this->prophesize(OrderSetCustomerEmail::class);
$secondOrder = $this->prophesize(Order::class);

$postUpdateEvent = new OrderPostUpdateEvent($order->reveal(), [$action->reveal()]);
$postUpdateEvent->setOrder($secondOrder->reveal());

$this->assertNotSame($order->reveal(),$secondOrder->reveal());
$this->assertSame($secondOrder->reveal(), $postUpdateEvent->getOrder());
$this->assertNotSame($order->reveal(), $postUpdateEvent->getOrder());

$this->assertEquals([$action->reveal()], $postUpdateEvent->getActions());
$event = new OrderPostUpdateEvent(Order::of(), [OrderSetCustomerEmail::of()]);
$this->assertInstanceOf(Order::class, $event->getOrder());
$this->assertInstanceOf(OrderSetCustomerEmail::class, current($event->getActions()));
}
}
23 changes: 9 additions & 14 deletions src/CartBundle/Tests/Event/OrderUpdateEventTest.php
Expand Up @@ -16,21 +16,16 @@ class OrderUpdateEventTest extends TestCase
{
public function testOrderUpdateEvent()
{
$order = $this->prophesize(Order::class);
$action = $this->prophesize(OrderSetCustomerEmail::class);
$secondAction = $this->prophesize(OrderSetBillingAddress::class);
$event = new OrderUpdateEvent(Order::of(), OrderSetCustomerEmail::of());
$this->assertInstanceOf(Order::class, $event->getOrder());
$this->assertSame(1, count($event->getActions()));
$this->assertInstanceOf(OrderSetCustomerEmail::class, current($event->getActions()));

$updateEvent = new OrderUpdateEvent($order->reveal(), $action->reveal());
$event->addAction(OrderSetBillingAddress::of());
$this->assertSame(2, count($event->getActions()));

$this->assertInstanceOf(Order::class, $updateEvent->getOrder());
$this->assertEquals([$action->reveal()], $updateEvent->getActions());

$updateEvent->addAction($secondAction->reveal());

$this->assertEquals([$action->reveal(), $secondAction->reveal()], $updateEvent->getActions());

$updateEvent->setActions([$secondAction->reveal()]);

$this->assertEquals([$secondAction->reveal()], $updateEvent->getActions());
$event->setActions([OrderSetBillingAddress::of()]);
$this->assertSame(1, count($event->getActions()));
$this->assertInstanceOf(OrderSetBillingAddress::class, current($event->getActions()));
}
}
20 changes: 20 additions & 0 deletions src/CartBundle/Tests/Event/PaymentPostCreateEventTest.php
@@ -0,0 +1,20 @@
<?php
/**
*
*/

namespace Commercetools\Symfony\CartBundle\Tests\Event;


use Commercetools\Core\Model\Payment\Payment;
use Commercetools\Symfony\CartBundle\Event\PaymentPostCreateEvent;
use PHPUnit\Framework\TestCase;

class PaymentPostCreateEventTest extends TestCase
{
public function testPaymentPostCreateEvent()
{
$event = new PaymentPostCreateEvent(Payment::of());
$this->assertInstanceOf(Payment::class, $event->getPayment());
}
}
22 changes: 22 additions & 0 deletions src/CartBundle/Tests/Event/PaymentPostUpdateEventTest.php
@@ -0,0 +1,22 @@
<?php
/**
*
*/

namespace Commercetools\Symfony\CartBundle\Tests\Event;


use Commercetools\Core\Model\Payment\Payment;
use Commercetools\Core\Request\Payments\Command\PaymentSetCustomerAction;
use Commercetools\Symfony\CartBundle\Event\PaymentPostUpdateEvent;
use PHPUnit\Framework\TestCase;

class PaymentPostUpdateEventTest extends TestCase
{
public function testPaymentPostUpdateEvent()
{
$event = new PaymentPostUpdateEvent(Payment::of(), [PaymentSetCustomerAction::of()]);
$this->assertInstanceOf(Payment::class, $event->getPayment());
$this->assertInstanceOf(PaymentSetCustomerAction::class, current($event->getActions()));
}
}

0 comments on commit 7fb9ee4

Please sign in to comment.