Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/Fake/FromDir/TodoClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Ray\MediaQuery\FromDir;

final class TodoClass
{
}
3 changes: 3 additions & 0 deletions tests/Fake/FromDirInvalidCase/NoClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

declare(strict_types=1);
46 changes: 46 additions & 0 deletions tests/InsertedRowTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Ray\MediaQuery;

use Aura\Sql\ExtendedPdoInterface;
use PDOStatement;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Ray\MediaQuery\Result\InsertedRow;
use Ray\MediaQuery\Result\PostQueryContext;

final class InsertedRowTest extends TestCase
{
/**

Check failure on line 16 in tests/InsertedRowTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Found multi-line doc comment with single line content, use one-line doc comment instead.

Check failure on line 16 in tests/InsertedRowTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Found multi-line doc comment with single line content, use one-line doc comment instead.
* @param string|false $lastInsertId
*/
#[DataProvider('emptyLastInsertIds')]
public function testFromContextNormalizesEmptyLastInsertId(string|false $lastInsertId): void

Check failure on line 20 in tests/InsertedRowTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Method \Ray\MediaQuery\InsertedRowTest::testFromContextNormalizesEmptyLastInsertId() does not need documentation comment.

Check failure on line 20 in tests/InsertedRowTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Method \Ray\MediaQuery\InsertedRowTest::testFromContextNormalizesEmptyLastInsertId() does not need documentation comment.
{
$pdo = $this->createStub(ExtendedPdoInterface::class);
$pdo->method('lastInsertId')->willReturn($lastInsertId);

$result = InsertedRow::fromContext(new PostQueryContext(
$this->createStub(PDOStatement::class),
$pdo,
['label' => 'empty'],
));

$this->assertSame(['label' => 'empty'], $result->values);
$this->assertNull($result->id);
}

/**

Check failure on line 35 in tests/InsertedRowTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Found multi-line doc comment with single line content, use one-line doc comment instead.

Check failure on line 35 in tests/InsertedRowTest.php

View workflow job for this annotation

GitHub Actions / cs / Coding Standards

Found multi-line doc comment with single line content, use one-line doc comment instead.
* @return array<string, array{string|false}>
*/
public static function emptyLastInsertIds(): array
{
return [
'false' => [false],
'empty string' => [''],
'zero string' => ['0'],
];
}
}
28 changes: 28 additions & 0 deletions tests/PagesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Ray\MediaQuery;

use Aura\Sql\ExtendedPdoInterface;
use PHPUnit\Framework\TestCase;
use Ray\AuraSqlModule\Pagerfanta\AuraSqlPagerInterface;

final class PagesTest extends TestCase
{
public function testOffsetGetReturnsNullWhenDelegateHasNoPage(): void
{
$delegate = $this->createStub(AuraSqlPagerInterface::class);
$delegate->method('offsetGet')->willReturn(null);

$pages = new Pages(
$delegate,
$this->createStub(ExtendedPdoInterface::class),
'SELECT 1',
[],
);

$this->assertFalse(isset($pages[3]));
$this->assertNull($pages[3]);
}
}
14 changes: 13 additions & 1 deletion tests/QueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

use PHPUnit\Framework\TestCase;
use Ray\MediaQuery\FromDir\TodoAddInterface;
use Ray\MediaQuery\FromDir\TodoClass;
use Ray\MediaQuery\FromDir\TodoItemInterface;
use ReflectionMethod;

use function sort;

class QueriesTest extends TestCase
{
public function testFromClasses(): void
{
$classes = [TodoAddInterface::class, TodoItemInterface::class];
$classes = [TodoAddInterface::class, TodoClass::class, TodoItemInterface::class];
$mediaQueries = Queries::fromClasses($classes);
$this->assertSame($classes, $mediaQueries->classes);
}
Expand All @@ -26,6 +28,7 @@ public function testFromDir(): void
sort($classes);
$this->assertSame([
TodoAddInterface::class,
TodoClass::class,
TodoItemInterface::class,
], $classes);
}
Expand All @@ -37,6 +40,7 @@ public function testFromDirCache(): void
sort($classes);
$this->assertSame([
TodoAddInterface::class,
TodoClass::class,
TodoItemInterface::class,
], $classes);
}
Expand All @@ -46,4 +50,12 @@ public function testFromDirInvalidClass(): void
$mediaQueries = Queries::fromDir(__DIR__ . '/Fake/FromDirInvalidCase');
$this->assertEmpty($mediaQueries->classes);
}

public function testTokenListsWithoutClassHaveNoClass(): void
{
$method = new ReflectionMethod(ClassesInDirectories::class, 'extractClassName');

$this->assertNull($method->invoke(null, []));
$this->assertNull($method->invoke(null, ['']));
}
}
8 changes: 8 additions & 0 deletions tests/ReturnTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Ray\MediaQuery;

use phpDocumentor\Reflection\DocBlockFactory;
use phpDocumentor\Reflection\PseudoTypes\Generic;
use PHPUnit\Framework\TestCase;
use Ray\MediaQuery\Entity\FakeEntity;
use ReflectionMethod;
Expand Down Expand Up @@ -97,4 +98,11 @@ public function testReturnArray(): void

$this->assertSame(null, $entity);
}

public function testEmptyGenericTypeHasNoValueType(): void
{
$method = new ReflectionMethod($this->returnEntity, 'extractValueType');

$this->assertNull($method->invoke($this->returnEntity, new Generic(null, [])));
}
}
Loading