Apply new limit to new users

I refactored the SubscribersFeature class so that it's easily
unit tested. Computing the subscribers count in the constructor
is better then computing it on every call to check().

[MAILPOET-2394]
This commit is contained in:
Amine Ben hammou
2019-11-26 00:30:48 +01:00
committed by Jack Kitterhing
parent 53e0934a87
commit 042557aafa
4 changed files with 75 additions and 47 deletions

View File

@@ -0,0 +1,54 @@
<?php
namespace MailPoet\Test\Util\License\Features;
use Codeception\Util\Stub;
use MailPoet\Util\License\Features\Subscribers as SubscribersFeature;
class SubscribersTest extends \MailPoetUnitTest {
function testCheckReturnsTrueIfOldUserReachedLimit() {
$subscribers_feature = Stub::make(SubscribersFeature::class, [
'license' => false,
'installation_time' => strtotime('2018-11-11'),
'subscribers_count' => 2500,
]);
expect($subscribers_feature->check())->true();
}
function testCheckReturnsFalseIfOldUserDidntReachLimit() {
$subscribers_feature = Stub::make(SubscribersFeature::class, [
'license' => false,
'installation_time' => strtotime('2018-11-11'),
'subscribers_count' => 1500,
]);
expect($subscribers_feature->check())->false();
}
function testCheckReturnsTrueIfNewUserReachedLimit() {
$subscribers_feature = Stub::make(SubscribersFeature::class, [
'license' => false,
'installation_time' => strtotime('2019-11-11'),
'subscribers_count' => 1500,
]);
expect($subscribers_feature->check())->true();
}
function testCheckReturnsFalseIfNewUserDidntReachLimit() {
$subscribers_feature = Stub::make(SubscribersFeature::class, [
'license' => false,
'installation_time' => strtotime('2019-11-11'),
'subscribers_count' => 900,
]);
expect($subscribers_feature->check())->false();
}
function testCheckReturnsFalseIfLicenseExists() {
$subscribers_feature = Stub::make(SubscribersFeature::class, [
'license' => true,
'installation_time' => strtotime('2019-11-11'),
'subscribers_count' => 1500,
]);
expect($subscribers_feature->check())->false();
}
}