Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 committed Dec 2, 2023
1 parent 81b88de commit 2c4758f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/Adapter/Doctrine/Event/ORMAdapterQueryEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@
*/
class ORMAdapterQueryEvent extends Event
{
/** @var Query */
protected $query;
protected Query $query;

/**
* ORMAdapterQueryEvent constructor.
*/
public function __construct(Query $query)
{
$this->query = $query;
Expand Down
2 changes: 1 addition & 1 deletion src/Column/DateTimeColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function normalize(mixed $value): mixed
if (false === ($errors = \DateTime::getLastErrors())) {
throw new \LogicException('DateTime conversion failed for unknown reasons');
}
throw new \Exception(implode(', ', $errors['errors'] ?: $errors['warnings']));
throw new \RuntimeException(implode(', ', $errors['errors'] ?: $errors['warnings']));
}
} else {
$value = new \DateTime((string) $value);
Expand Down
38 changes: 38 additions & 0 deletions tests/Unit/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ public function testDateTimeColumn(): void

$this->assertSame('03-04-2015', $column->transform('2015-04-03'));
$this->assertSame('foo', $column->transform(null));

$column->initialize('test', 1, [
'createFromFormat' => 'foo',
], $this->createDataTable()->setName('foo'));

$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('format separator does not match');
$column->transform('2015-04-03');
}

public function testDateTimeColumnWithCreateFromFormat(): void
Expand Down Expand Up @@ -118,6 +126,9 @@ public function testNumberColumn(): void
$this->assertFalse($column->isRaw());
$this->assertTrue($column->isValidForSearch(684));
$this->assertFalse($column->isValidForSearch('foo.bar'));

// Forced conversion failure
$this->assertSame('0', $column->normalize('foo'));
}

public function testColumnWithClosures(): void
Expand All @@ -136,6 +147,33 @@ public function testColumnWithClosures(): void
$this->assertSame('BAR', $column->transform(null));
}

public function testLeftRightExprColumns(): void
{
$column = new TextColumn();
$column->initialize('test', 1, [
'leftExpr' => 'foo',
'rightExpr' => 'bar',
], $this->createDataTable());

$this->assertSame('foo', $column->getLeftExpr());
$this->assertSame('bar', $column->getRightExpr('fud'));

$column->initialize('test', 1, [
'field' => 'foo',
'leftExpr' => fn (string $field) => $field . 'bar',
'rightExpr' => fn (string $field) => $field . 'baz',
], $this->createDataTable());

$this->assertSame('foobar', $column->getLeftExpr());
$this->assertSame('fudbaz', $column->getRightExpr('fud'));

$column->initialize('test', 1, [
'rightExpr' => null,
], $this->createDataTable());

$this->assertSame('foo', $column->getRightExpr('foo'));
}

public function testTwigDependencyDetection(): void
{
$this->expectException(MissingDependencyException::class);
Expand Down
3 changes: 3 additions & 0 deletions tests/Unit/DataTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public function testDataTableState(): void

$this->assertSame(0, $state->getStart());
$this->assertNull($state->getLength());

$column = $datatable->getColumn(0);
$this->assertSame($state, $column->getState());
}

public function testPostMethod(): void
Expand Down

0 comments on commit 2c4758f

Please sign in to comment.