Skip to content

Commit

Permalink
Merge pull request #199 from alma/feat/MPP-517/fix-autoload-test-unit
Browse files Browse the repository at this point in the history
Feat/mpp 517/fix autoload test unit
  • Loading branch information
Benjamin-Freoua-Alma authored Aug 18, 2023
2 parents 4d141e7 + 95d6add commit b59ab7b
Show file tree
Hide file tree
Showing 18 changed files with 67 additions and 410 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public function canRun()
* @param array $params
*
* @return void
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function run($params)
{
Expand Down
12 changes: 12 additions & 0 deletions alma/lib/Helpers/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,16 @@ protected static function getFrenchDateFormat($timestamp)

return $date->format('d/m/Y');
}

/**
* @param string|int $timestamp
*
* @return bool
*/
public static function isValidTimeStamp($timestamp)
{
return ((string) (int) $timestamp === $timestamp)
&& ($timestamp <= PHP_INT_MAX)
&& ($timestamp >= ~PHP_INT_MAX);
}
}
3 changes: 3 additions & 0 deletions alma/lib/Helpers/OrderHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public function __construct()
* @param string $endDate
*
* @return \Order[]
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function getOrdersByDate($startDate, $endDate)
{
Expand All @@ -87,6 +89,7 @@ public function getOrdersByDate($startDate, $endDate)
* @param string $endDate
*
* @return array
* @throws \PrestaShopDatabaseException
*/
public function getOrdersIdByDate($startDate, $endDate)
{
Expand Down
15 changes: 12 additions & 3 deletions alma/lib/Helpers/ShareOfCheckoutHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ public function __construct($orderHelper)

/**
* @return bool
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function shareDays()
{
$shareOfCheckoutEnabledDate = $this->getEnabledDate();
if (
ShareOfCheckoutAdminFormBuilder::ALMA_SHARE_OF_CHECKOUT_CONSENT_NO === SettingsHelper::getShareOfCheckoutStatus()
|| empty($shareOfCheckoutEnabledDate)
|| !DateHelper::isValidTimeStamp($shareOfCheckoutEnabledDate)
) {
Logger::instance()->info('Share Of Checkout is disabled or invalide date');

Expand All @@ -102,6 +105,8 @@ public function shareDays()
* Put Payload to Share of Checkout.
*
* @return void
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function putDay()
{
Expand Down Expand Up @@ -152,6 +157,8 @@ public function getStartShareOfCheckout()
* Total Orders to send.
*
* @return array
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function getTotalOrders()
{
Expand Down Expand Up @@ -437,7 +444,7 @@ private function getEndDateTime()
*
* @param string $id
*
* @return string
* @return array|bool|object|null|string
*/
private function getIsoCodeById($id)
{
Expand All @@ -453,6 +460,8 @@ private function getIsoCodeById($id)
* Payload Share of Checkout.
*
* @return array
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function getPayload()
{
Expand All @@ -467,15 +476,15 @@ public function getPayload()
/**
* @return string|false
*/
protected function getEnabledDate()
public function getEnabledDate()
{
return \Configuration::get(ShareOfCheckoutAdminFormBuilder::ALMA_SHARE_OF_CHECKOUT_DATE);
}

/**
* @return array
*/
protected function getDatesInInterval($lastShareOfCheckout, $shareOfCheckoutEnabledDate)
public function getDatesInInterval($lastShareOfCheckout, $shareOfCheckoutEnabledDate)
{
return DateHelper::getDatesInInterval($lastShareOfCheckout, $shareOfCheckoutEnabledDate);
}
Expand Down
9 changes: 2 additions & 7 deletions alma/phpunit.ci.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@
stopOnFailure = "true">

<testsuites>
<testsuite name="Alma Installment Prestashop Unit Test Suite">
<directory>tests/unit</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="Alma Installment Prestashop Integration Test Suite">
<directory>tests/integration</directory>
<testsuite name="Alma Installment Prestashop Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

Expand Down
9 changes: 2 additions & 7 deletions alma/phpunit.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,8 @@
stopOnFailure = "false">

<testsuites>
<testsuite name="Alma Installment Prestashop Unit Test Suite">
<directory>tests/unit</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="Alma Installment Prestashop Integration Test Suite">
<directory>tests/integration</directory>
<testsuite name="Alma Installment Prestashop Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<php>
Expand Down
12 changes: 1 addition & 11 deletions alma/tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,5 @@ cd modules/alma/

to launch test :
```
./vendor/bin/phpunit
```

to launch integration test :
```
./vendor/bin/phpunit --testsuite 'Alma Installment Prestashop Integration Test Suite'
```

to launch unit test :
```
./vendor/bin/phpunit --testsuite 'Alma Installment Prestashop Unit Test Suite'
./vendor/bin/phpunit -c phpunit.ci.xml
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @license https://opensource.org/licenses/MIT The MIT License
*/

namespace Alma\PrestaShop\Tests\Unit\Lib\ShareOfCheckout;
namespace Alma\PrestaShop\Tests\Unit\Helper;

use Alma\PrestaShop\Helpers\OrderHelper;
use Alma\PrestaShop\Helpers\ShareOfCheckoutHelper;
Expand All @@ -43,7 +43,10 @@ protected function setUp()
/**
* @dataProvider dateErrorDataProvider
*
* @param $dateErrorData
* @return void
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function testShareDaysNoDate($dateErrorData)
{
Expand All @@ -52,6 +55,11 @@ public function testShareDaysNoDate($dateErrorData)
$this->assertFalse($shareOfCheckoutHelperMock->shareDays());
}

/**
* @return void
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function testShareDaysReturnTrueWithValidTimestamp()
{
$this->orderHelperMock->shouldReceive('resetOrderList');
Expand All @@ -67,7 +75,11 @@ public function testShareDaysReturnTrueWithValidTimestamp()
*
* @dataProvider ordersGetPayload
*
* @param $ordersMock
* @param $expectedPayload
* @return void
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function testGetPayload($ordersMock, $expectedPayload)
{
Expand Down Expand Up @@ -103,7 +115,11 @@ public function testGetTotalPaymentMethods($ordersMock, $expectedTotalPaymentMet
*
* @dataProvider ordersTotalOrders
*
* @param $ordersMock
* @param $expectedTotalOrders
* @return void
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function testGetTotalOrders($ordersMock, $expectedTotalOrders)
{
Expand All @@ -115,6 +131,9 @@ public function testGetTotalOrders($ordersMock, $expectedTotalOrders)
$this->assertEquals($expectedTotalOrders, $getTotalOrders);
}

/**
* @return array[]
*/
public function ordersTotalOrders()
{
$expectedTotalOrders = [
Expand All @@ -138,6 +157,9 @@ public function ordersTotalOrders()
];
}

/**
* @return array[]
*/
public function ordersTotalPaymentMethods()
{
$expectedTotalPaymentMethods = [
Expand Down Expand Up @@ -176,6 +198,9 @@ public function ordersTotalPaymentMethods()
];
}

/**
* @return array[]
*/
public function ordersGetPayload()
{
$expectedPayload = [
Expand Down Expand Up @@ -230,6 +255,9 @@ public function ordersGetPayload()
];
}

/**
* @return array
*/
public function orders()
{
$ordersMock = [];
Expand Down Expand Up @@ -267,6 +295,9 @@ public function orders()
return $ordersMock;
}

/**
* @return array
*/
public function dateErrorDataProvider()
{
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @license https://opensource.org/licenses/MIT The MIT License
*/

namespace Alma\PrestaShop\Tests\Unit\Lib\Model;
namespace Alma\PrestaShop\Tests\Unit\Model;

use Alma\PrestaShop\Helpers\ProductHelper;
use Alma\PrestaShop\Model\CartData;
Expand Down
30 changes: 0 additions & 30 deletions alma/tests/integration/index.php

This file was deleted.

Loading

0 comments on commit b59ab7b

Please sign in to comment.