Refactor Tests
This commit is contained in:
@@ -2,12 +2,12 @@
|
||||
|
||||
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Repositories;
|
||||
|
||||
use Codeception\Attribute\DataProvider;
|
||||
use Codeception\Test\Unit;
|
||||
use DateTime;
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use PDO;
|
||||
use TorstenHettstedt\TimekeepingApi\Models\WorkingHoursView;
|
||||
use PDO;use TorstenHettstedt\TimekeepingApi\Models\WorkingHoursView;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\RepositoryRecordNotFoundException;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursWeeklyViewRepository;
|
||||
use TorstenHettstedt\TimekeepingApi\Repositories\WorkingHoursMonthlyViewRepository;
|
||||
@@ -25,7 +25,7 @@ class WorkingHoursViewRepositoryTest extends Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @return array<array{string, int}>
|
||||
*/
|
||||
public function listObjectProvider(): array
|
||||
{
|
||||
@@ -37,7 +37,7 @@ class WorkingHoursViewRepositoryTest extends Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @return array<array{string, string, int, DateTime}>
|
||||
* @throws Exception
|
||||
*/
|
||||
public function existingObjectProvider(): array
|
||||
@@ -50,7 +50,7 @@ class WorkingHoursViewRepositoryTest extends Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
* @return array<array{string, string}>
|
||||
*/
|
||||
public function notExistingObjectProvider(): array
|
||||
{
|
||||
@@ -61,49 +61,30 @@ class WorkingHoursViewRepositoryTest extends Unit
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $period_class
|
||||
* @param int $count_records
|
||||
*
|
||||
* @dataProvider listObjectProvider
|
||||
*/
|
||||
public function testFindAll(string $period_class, int $count_records): void
|
||||
#[DataProvider(('listObjectProvider'))]
|
||||
public function testFindAll(string $periodClass, int $countRecords): void
|
||||
{
|
||||
$repository = new $period_class($this->pdoObject);
|
||||
$repository = new $periodClass($this->pdoObject);
|
||||
$models = $repository->findAll();
|
||||
$this->assertIsArray($models);
|
||||
$this->assertContainsOnly(WorkingHoursView::class, $models);
|
||||
$this->assertCount($count_records, $models);
|
||||
$this->assertContainsOnlyInstancesOf(WorkingHoursView::class, $models);
|
||||
$this->assertCount($countRecords, $models);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @dataProvider existingObjectProvider
|
||||
*
|
||||
* @param string $period_class
|
||||
* @param string $search
|
||||
* @param int $workingDays
|
||||
* @param DateTime $period
|
||||
*/
|
||||
public function testExistingFindByKey(string $period_class, string $search, int $workingDays, DateTime $period): void
|
||||
#[DataProvider(('existingObjectProvider'))]
|
||||
public function testExistingFindByKey(string $periodClass, string $search, int $workingDays, DateTime $period): void
|
||||
{
|
||||
$repository = new $period_class($this->pdoObject);
|
||||
$repository = new $periodClass($this->pdoObject);
|
||||
$model = $repository->findByKey($search);
|
||||
$this->assertInstanceOf(WorkingHoursView::class, $model);
|
||||
$this->assertEquals($workingDays, $model->getWorkingDays());
|
||||
$this->assertEquals($period->format('Ymd'), $model->getPeriod()->format('Ymd'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $period_class
|
||||
* @param string $search
|
||||
*
|
||||
* @dataProvider notExistingObjectProvider
|
||||
*
|
||||
*/
|
||||
public function testNotExistingFindByKey(string $period_class, string $search): void
|
||||
#[DataProvider(('notExistingObjectProvider'))]
|
||||
public function testNotExistingFindByKey(string $periodClass, string $search): void
|
||||
{
|
||||
$repository = new $period_class($this->pdoObject);
|
||||
$repository = new $periodClass($this->pdoObject);
|
||||
$this->expectException(RepositoryRecordNotFoundException::class);
|
||||
$repository->findByKey($search);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user