Skip to content

Commit

Permalink
Added the ability to specify a custom directory for specific declarat…
Browse files Browse the repository at this point in the history
…ion types in the [spiral/scaffolder] componentt (#925)
  • Loading branch information
spiralbot committed Apr 25, 2023
1 parent 753d260 commit e2fbe4c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
8 changes: 5 additions & 3 deletions src/Paginator.php
Expand Up @@ -11,12 +11,14 @@ final class Paginator implements PaginatorInterface, \Countable
{
private int $pageNumber = 1;
private int $countPages = 1;
private int $count;

public function __construct(
private int $limit = 25,
private int $count = 0,
private readonly ?string $parameter = null
int $count = 0,
private readonly ?string $parameter = null,
) {
$this->setCount($count);
}

/**
Expand Down Expand Up @@ -129,7 +131,7 @@ public function previousPage(): ?int
private function setCount(int $count): self
{
$this->count = \max($count, 0);
$this->countPages = $this->count > 0 ? (int) \ceil($this->count / $this->limit) : 1;
$this->countPages = $this->count > 0 ? (int)\ceil($this->count / $this->limit) : 1;

return $this;
}
Expand Down
53 changes: 30 additions & 23 deletions tests/PaginatorTest.php
Expand Up @@ -10,32 +10,40 @@

class PaginatorTest extends TestCase
{
public function testInterfaces()
public function testInterfaces(): void
{
$paginator = new Paginator(25);
$paginator = new Paginator(limit: 25);

$this->assertInstanceOf(PaginatorInterface::class, $paginator);
}

public function testParameterTracking()
public function testParameterTracking(): void
{
$paginator = new Paginator(25, 0, 'request:page');
$paginator = new Paginator(limit: 25, count: 0, parameter: 'request:page');
$this->assertSame('request:page', $paginator->getParameter());
}

public function testLimit()
public function testLimit(): void
{
$paginator = new Paginator(25);
$paginator = new Paginator(limit: 25);

$this->assertSame(25, $paginator->getLimit());
$newPaginator = $paginator->withLimit(50);
$this->assertSame(25, $paginator->getLimit());
$this->assertSame(50, $newPaginator->getLimit());
}

public function testCountsAndPages()
public function testLimitWithCounts(): void
{
$paginator = new Paginator(25);
$paginator = new Paginator(limit: 25, count: 100);

$this->assertSame(100, $paginator->count());
$this->assertSame(4, $paginator->countPages());
}

public function testCountsAndPages(): void
{
$paginator = new Paginator(limit: 25);

$this->assertSame(0, $paginator->count());
$this->assertSame($paginator->count(), $paginator->count());
Expand All @@ -47,9 +55,9 @@ public function testCountsAndPages()
$this->assertSame(0, $paginator->countDisplayed());
}

public function testFirstPage()
public function testFirstPage(): void
{
$paginator = new Paginator(25);
$paginator = new Paginator(limit: 25);
$paginator = $paginator->withCount(100);

$this->assertSame(1, $paginator->getPage());
Expand All @@ -66,10 +74,9 @@ public function testFirstPage()
$this->assertSame(25, $paginator->countDisplayed());
}


public function testSecondPage()
public function testSecondPage(): void
{
$paginator = new Paginator(25);
$paginator = new Paginator(limit: 25);
$paginator = $paginator->withCount(110);

$this->assertSame(110, $paginator->count());
Expand All @@ -89,9 +96,9 @@ public function testSecondPage()
$this->assertSame(25, $paginator->countDisplayed());
}

public function testLastPage()
public function testLastPage(): void
{
$paginator = new Paginator(25);
$paginator = new Paginator(limit: 25);
$paginator = $paginator->withCount(100);

$this->assertSame(1, $paginator->getPage());
Expand All @@ -114,9 +121,9 @@ public function testLastPage()
$this->assertSame(25, $paginator->countDisplayed());
}

public function testNegativePage()
public function testNegativePage(): void
{
$paginator = new Paginator(25);
$paginator = new Paginator(limit: 25);
$paginator = $paginator->withCount(100);
$paginator = $paginator->withPage(-1);

Expand All @@ -127,9 +134,9 @@ public function testNegativePage()
$this->assertSame($paginator->count(), count($paginator));
}

public function testNegativeCount()
public function testNegativeCount(): void
{
$paginator = new Paginator(25);
$paginator = new Paginator(limit: 25);
$paginator = $paginator->withCount(-100);

$paginator = $paginator->withPage(-10);
Expand All @@ -144,9 +151,9 @@ public function testNegativeCount()
$this->assertSame(0, $paginator->countDisplayed());
}

public function testLastPageNumber()
public function testLastPageNumber(): void
{
$paginator = new Paginator(25);
$paginator = new Paginator(limit: 25);
$paginator = $paginator->withCount(110);

$this->assertSame(110, $paginator->count());
Expand All @@ -164,9 +171,9 @@ public function testLastPageNumber()
$this->assertSame(10, $paginator->countDisplayed());
}

public function testIsRequired()
public function testIsRequired(): void
{
$paginator = new Paginator(25);
$paginator = new Paginator(limit: 25);

$paginator = $paginator->withCount(24);
$this->assertFalse($paginator->isRequired());
Expand Down

0 comments on commit e2fbe4c

Please sign in to comment.