Use Doctrine entities and truncate only what is used in SubscriberTest

This commit replaces old Paris code with Doctrine entities in
SubscriberTest::_after() and it also truncate only the entities that are
actually used inside the test class. Before this change, the class was
unnecessarily truncating entities that were not used. I'm doing this
commit as part of task to remove all usages of the old NewsletterOption
model and that is why I'm not touching the remaining models in other
methods of this class.

[MAILPOET-4150]
This commit is contained in:
Rodrigo Primo
2022-05-10 10:02:55 -03:00
parent acd8fbb773
commit bcd33de9ed

View File

@ -3,20 +3,17 @@
namespace MailPoet\Test\Models; namespace MailPoet\Test\Models;
use Codeception\Util\Fixtures; use Codeception\Util\Fixtures;
use MailPoet\Entities\SegmentEntity;
use MailPoet\Entities\SubscriberCustomFieldEntity;
use MailPoet\Entities\SubscriberEntity;
use MailPoet\Entities\SubscriberSegmentEntity;
use MailPoet\Models\CustomField; use MailPoet\Models\CustomField;
use MailPoet\Models\Newsletter;
use MailPoet\Models\NewsletterOption;
use MailPoet\Models\NewsletterOptionField;
use MailPoet\Models\ScheduledTask;
use MailPoet\Models\Segment; use MailPoet\Models\Segment;
use MailPoet\Models\SendingQueue;
use MailPoet\Models\Subscriber; use MailPoet\Models\Subscriber;
use MailPoet\Models\SubscriberCustomField; use MailPoet\Models\SubscriberCustomField;
use MailPoet\Models\SubscriberSegment; use MailPoet\Models\SubscriberSegment;
use MailPoet\Settings\SettingsController; use MailPoet\Settings\SettingsController;
use MailPoet\Settings\SettingsRepository;
use MailPoetVendor\Carbon\Carbon; use MailPoetVendor\Carbon\Carbon;
use MailPoetVendor\Idiorm\ORM;
class SubscriberTest extends \MailPoetTest { class SubscriberTest extends \MailPoetTest {
public $saved; public $saved;
@ -880,16 +877,9 @@ class SubscriberTest extends \MailPoetTest {
} }
public function _after() { public function _after() {
ORM::raw_execute('TRUNCATE ' . Subscriber::$_table); $this->truncateEntity(SubscriberEntity::class);
ORM::raw_execute('TRUNCATE ' . Segment::$_table); $this->truncateEntity(SegmentEntity::class);
ORM::raw_execute('TRUNCATE ' . SubscriberSegment::$_table); $this->truncateEntity(SubscriberSegmentEntity::class);
ORM::raw_execute('TRUNCATE ' . CustomField::$_table); $this->truncateEntity(SubscriberCustomFieldEntity::class);
ORM::raw_execute('TRUNCATE ' . SubscriberCustomField::$_table);
ORM::raw_execute('TRUNCATE ' . Newsletter::$_table);
ORM::raw_execute('TRUNCATE ' . NewsletterOptionField::$_table);
ORM::raw_execute('TRUNCATE ' . NewsletterOption::$_table);
ORM::raw_execute('TRUNCATE ' . ScheduledTask::$_table);
ORM::raw_execute('TRUNCATE ' . SendingQueue::$_table);
$this->diContainer->get(SettingsRepository::class)->truncate();
} }
} }