Refactor test to doctrine

[MAILPOET-3624]
This commit is contained in:
Pavel Dohnal
2021-06-04 09:42:51 +02:00
committed by Veljko V
parent e5e7be6437
commit ab29ab170a

View File

@@ -3,7 +3,6 @@
namespace MailPoet\Logging; namespace MailPoet\Logging;
use MailPoet\Entities\LogEntity; use MailPoet\Entities\LogEntity;
use MailPoet\Models\Log;
use MailPoetVendor\Carbon\Carbon; use MailPoetVendor\Carbon\Carbon;
class LogHandlerTest extends \MailPoetTest { class LogHandlerTest extends \MailPoetTest {
@@ -26,21 +25,21 @@ class LogHandlerTest extends \MailPoetTest {
'datetime' => $time, 'datetime' => $time,
]); ]);
$log = Log::where('name', 'name')->orderByDesc('id')->findOne(); $log = $this->repository->findOneBy(['name' => 'name'], ['id' => 'desc']);
assert($log instanceof Log); assert($log instanceof LogEntity);
expect($log->createdAt)->equals($time->format('Y-m-d H:i:s')); expect($log->getCreatedAt()->format('Y-m-d H:i:s'))->equals($time->format('Y-m-d H:i:s'));
} }
public function testItPurgesOldLogs() { public function testItPurgesOldLogs() {
$model = Log::create(); $entity = new LogEntity();
$model->hydrate([ $entity->setName( 'old name');
'name' => 'old name', $entity->setLevel(5);
'level' => '5', $entity->setMessage('xyz');
'message' => 'xyz', $entity->setCreatedAt(Carbon::now()->subDays(100));
'created_at' => Carbon::now()->subDays(100)->toDateTimeString(),
]); $this->repository->persist($entity);
$model->save(); $this->repository->flush();
$random = function() { $random = function() {
return 0; return 0;
}; };
@@ -54,20 +53,20 @@ class LogHandlerTest extends \MailPoetTest {
'datetime' => new \DateTime(), 'datetime' => new \DateTime(),
]); ]);
$log = Log::whereEqual('name', 'old name')->findMany(); $log = $this->repository->findBy(['name' => 'old name']);
expect($log)->isEmpty(); expect($log)->isEmpty();
} }
public function testItNotPurgesOldLogs() { public function testItNotPurgesOldLogs() {
$model = Log::create(); $entity = new LogEntity();
$date = Carbon::now(); $entity->setName( 'old name keep');
$model->hydrate([ $entity->setLevel(5);
'name' => 'old name keep', $entity->setMessage('xyz');
'level' => '5', $entity->setCreatedAt(Carbon::now()->subDays(100));
'message' => 'xyz',
'created_at' => $date->subDays(100)->toDateTimeString(), $this->repository->persist($entity);
]); $this->repository->flush();
$model->save();
$random = function() { $random = function() {
return 100; return 100;
}; };
@@ -81,7 +80,7 @@ class LogHandlerTest extends \MailPoetTest {
'datetime' => new \DateTime(), 'datetime' => new \DateTime(),
]); ]);
$log = Log::whereEqual('name', 'old name keep')->findMany(); $log = $this->repository->findBy(['name' => 'old name keep']);
expect($log)->notEmpty(); expect($log)->notEmpty();
} }
} }