Skip to content

Commit

Permalink
use Schema\TestCase for DB setup in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippGrashoff committed Sep 8, 2023
1 parent 236871e commit 03e3925
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 42 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"prefer-stable": true,
"require": {
"php": "8.*",
"philippgrashoff/atkextendedtestcase": "4.*",
"atk4/data": "4.*",
"ext-json": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion tests/BaseCronJobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PhilippR\Atk4\Cron\Tests;

use atkextendedtestcase\TestCase;
use Atk4\Core\Phpunit\TestCase;
use PhilippR\Atk4\Cron\BaseCronJob;
use PhilippR\Atk4\Cron\Tests\Testclasses\SomeCronJob;
use PhilippR\Atk4\Cron\Tests\Testclasses\SomeCronJobWithExceptionInExecute;
Expand Down
2 changes: 1 addition & 1 deletion tests/CronJobLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace PhilippR\Atk4\Cron\Tests;


use atkextendedtestcase\TestCase;
use Atk4\Core\Phpunit\TestCase;
use PhilippR\Atk4\Cron\CronJobLoader;

class CronJobLoaderTest extends TestCase
Expand Down
27 changes: 15 additions & 12 deletions tests/ExecutionLogTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace PhilippR\Atk4\Cron\Tests;

use atkextendedtestcase\TestCase;
use Atk4\Data\Persistence\Sql;
use Atk4\Data\Schema\TestCase;
use PhilippR\Atk4\Cron\ExecutionLog;
use PhilippR\Atk4\Cron\Executor;
use PhilippR\Atk4\Cron\Scheduler;
Expand All @@ -14,14 +15,16 @@
class ExecutionLogTest extends TestCase
{

protected array $sqlitePersistenceModels = [
Scheduler::class,
ExecutionLog::class
];

protected function setUp(): void
{
parent::setUp();
$this->db = new Sql('sqlite::memory:');
$this->createMigrator(new Scheduler($this->db))->create();
$this->createMigrator(new ExecutionLog($this->db))->create();
}
public function testDurationIsLogged()
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-05-05');
$testTime->setTime(3, 3);

Expand Down Expand Up @@ -50,7 +53,7 @@ public function testDurationIsLogged()

public function testExecutionSuccessIsLogged(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-09-07');
$testTime->setTime(3, 3);

Expand Down Expand Up @@ -88,7 +91,7 @@ public function testExecutionSuccessIsLogged(): void

public function testLoggingOptionNoLogging(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-09-07');
$testTime->setTime(3, 3);

Expand All @@ -113,7 +116,7 @@ public function testLoggingOptionNoLogging(): void

public function testLoggingOptionOnlyIfLogOutput(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-09-07');
$testTime->setTime(3, 3);

Expand Down Expand Up @@ -155,7 +158,7 @@ public function testLoggingOptionOnlyIfLogOutput(): void

public function testLoggingOptionAlwaysLog(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-09-07');
$testTime->setTime(3, 3);

Expand Down Expand Up @@ -198,7 +201,7 @@ public function testLoggingOptionAlwaysLog(): void

public function testLastExecutedSaved(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$dateTime = new \DateTime();
//this one should be executed
$entity = ExecutorTest::getScheduler(
Expand Down
41 changes: 22 additions & 19 deletions tests/ExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
namespace PhilippR\Atk4\Cron\Tests;

use Atk4\Data\Persistence;
use atkextendedtestcase\TestCase;
use Atk4\Data\Persistence\Sql;
use Atk4\Data\Schema\TestCase;
use PhilippR\Atk4\Cron\Executor;
use PhilippR\Atk4\Cron\Scheduler;
use PhilippR\Atk4\Cron\Tests\Testclasses\SomeCronJob;
Expand All @@ -14,16 +15,18 @@

class ExecutorTest extends TestCase
{

protected array $sqlitePersistenceModels = [
Scheduler::class,
ExecutionLog::class
];



protected function setUp(): void
{
parent::setUp();
$this->db = new Sql('sqlite::memory:');
$this->createMigrator(new Scheduler($this->db))->create();
$this->createMigrator(new ExecutionLog($this->db))->create();
}

public function testRunYearly(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-11-05');
$testTime->setTime(3, 11);
//this one should be executed
Expand Down Expand Up @@ -78,7 +81,7 @@ public function testRunYearly(): void

public function testSkipYearlyIfNoDateYearlySet(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-05-05');
$testTime->setTime(3, 3);
//this one should be executed
Expand All @@ -99,7 +102,7 @@ public function testSkipYearlyIfNoDateYearlySet(): void

public function testRunMonthly(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-08-05');
$testTime->setTime(3, 14);
//this one should be executed
Expand Down Expand Up @@ -163,7 +166,7 @@ public function testRunMonthly(): void

public function testSkipMonthlyIfNoTimeSet(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-05-05');
$testTime->setTime(3, 3);
//this one should be executed
Expand All @@ -184,7 +187,7 @@ public function testSkipMonthlyIfNoTimeSet(): void

public function testRunWeekly(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-06-03');
$testTime->setTime(4, 34);
//this one should be executed
Expand Down Expand Up @@ -248,7 +251,7 @@ public function testRunWeekly(): void

public function testRunDaily(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime();
$testTime->setTime(15, 3);

Expand Down Expand Up @@ -290,7 +293,7 @@ public function testRunDaily(): void

public function testRunHourly(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime();
$testTime->setTime(14, 35);
//this one should be executed
Expand Down Expand Up @@ -330,7 +333,7 @@ public function testRunHourly(): void

public function testRunMinutely(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime();
$testTime->setTime(3, 16);
//this one should be executed
Expand Down Expand Up @@ -370,7 +373,7 @@ public function testRunMinutely(): void

public function testRunMinutelyOffset(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime();
$testTime->setTime(3, 18);

Expand Down Expand Up @@ -423,7 +426,7 @@ public function testRunMinutelyOffset(): void

public function testNonActiveCronInRun(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-05-05');
$testTime->setTime(3, 3);
//this one should be executed
Expand Down Expand Up @@ -455,7 +458,7 @@ public function testNonActiveCronInRun(): void

public function testExceptionInExecuteDoesNotStopExecutionOfOthers(): void
{
$persistence = $this->getSqliteTestPersistence();
$persistence = $this->db;
$testTime = new \DateTime('2020-05-05');
$testTime->setTime(3, 3);

Expand Down
20 changes: 12 additions & 8 deletions tests/SchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@

namespace PhilippR\Atk4\Cron\Tests;

use atkextendedtestcase\TestCase;
use Atk4\Data\Persistence\Sql;
use Atk4\Data\Schema\TestCase;
use PhilippR\Atk4\Cron\ExecutionLog;
use PhilippR\Atk4\Cron\Scheduler;
use PhilippR\Atk4\Cron\Tests\Testclasses\SomeCronJob;

class SchedulerTest extends TestCase
{

protected array $sqlitePersistenceModels = [
Scheduler::class,
ExecutionLog::class
];
protected function setUp(): void
{
parent::setUp();
$this->db = new Sql('sqlite::memory:');
$this->createMigrator(new Scheduler($this->db))->create();
$this->createMigrator(new ExecutionLog($this->db))->create();
}

public function testNameAndDescriptionLoadedFromBaseCronJob()
{
$scheduler = (new Scheduler($this->getSqliteTestPersistence()))->createEntity();
$scheduler = (new Scheduler($this->db))->createEntity();
$scheduler->set('cronjob_class', SomeCronJob::class);
$scheduler->save();
self::assertSame(
Expand All @@ -34,7 +38,7 @@ public function testNameAndDescriptionLoadedFromBaseCronJob()

public function testNameAndDescriptionNotChangedIfAlreadySet()
{
$scheduler = (new Scheduler($this->getSqliteTestPersistence()))->createEntity();
$scheduler = (new Scheduler($this->db))->createEntity();
$scheduler->set('cronjob_class', SomeCronJob::class);
$scheduler->set('name', 'someName');
$scheduler->set('description', 'someDescription');
Expand All @@ -51,7 +55,7 @@ public function testNameAndDescriptionNotChangedIfAlreadySet()

public function testNameAndDescriptionNotLoadedIfNoCronJobModelSet()
{
$scheduler = (new Scheduler($this->getSqliteTestPersistence()))->createEntity();
$scheduler = (new Scheduler($this->db))->createEntity();
$scheduler->save();
self::assertNull($scheduler->get('name'));
self::assertNull($scheduler->get('description'));
Expand Down

0 comments on commit 03e3925

Please sign in to comment.