Move test to unit

[MAILPOET-2219]
This commit is contained in:
Pavel Dohnal
2019-08-21 10:02:54 +02:00
committed by M. Shull
parent 8e65d4b6b2
commit 01fb9c7083

View File

@ -1,23 +1,29 @@
<?php
namespace MailPoet\Test\API\JSON\v1;
use MailPoet\Entities\FeatureFlagEntity;
use MailPoet\Features\FeatureFlagsRepository;
use MailPoet\Features\FeaturesController;
use MailPoet\Models\FeatureFlag;
class FeaturesControllerTest extends \MailPoetTest {
function _before() {
parent::_before();
FeatureFlag::deleteMany();
}
class FeaturesControllerTest extends \MailPoetUnitTest {
function testItWorksWithDefaults() {
$controller = $this->make(FeaturesController::class, [
'defaults' => [
'feature-a' => true,
'feature-b' => false,
],
]);
$repository = $this->makeEmpty(
FeatureFlagsRepository::class,
[
'findAll' => [],
]
);
$controller = $this->construct(
FeaturesController::class,
[$repository],
[
'defaults' => [
'feature-a' => true,
'feature-b' => false,
],
]
);
expect($controller->isSupported('feature-a'))->equals(true);
expect($controller->isSupported('feature-b'))->equals(false);
@ -28,12 +34,14 @@ class FeaturesControllerTest extends \MailPoetTest {
}
function testItWorksWithDatabaseValues() {
FeatureFlag::createOrUpdate([
'name' => 'feature-a',
'value' => false,
]);
$repository = $this->makeEmpty(
FeatureFlagsRepository::class,
[
'findAll' => [new FeatureFlagEntity('feature-a', false)],
]
);
$controller = $this->make(FeaturesController::class, [
$controller = $this->construct(FeaturesController::class, [$repository], [
'defaults' => [
'feature-a' => true,
],
@ -46,12 +54,14 @@ class FeaturesControllerTest extends \MailPoetTest {
}
function testItDoesNotReturnUnknownFlag() {
FeatureFlag::createOrUpdate([
'name' => 'feature-unknown',
'value' => true,
]);
$repository = $this->makeEmpty(
FeatureFlagsRepository::class,
[
'findAll' => [new FeatureFlagEntity('feature-unknown', true)],
]
);
$controller = $this->make(FeaturesController::class, [
$controller = $this->construct(FeaturesController::class, [$repository], [
'defaults' => [],
]);
@ -63,8 +73,4 @@ class FeaturesControllerTest extends \MailPoetTest {
expect($controller->getAllFlags())->isEmpty();
}
function _after() {
parent::_before();
FeatureFlag::deleteMany();
}
}