Skip to content

Commit

Permalink
Merge pull request shlinkio#9 from acelaya-forks/feature/missing-unit…
Browse files Browse the repository at this point in the history
…-tests

Feature/missing unit tests
  • Loading branch information
acelaya authored Dec 4, 2021
2 parents 4353b06 + eeaeae8 commit adabe2e
Show file tree
Hide file tree
Showing 11 changed files with 756 additions and 19 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"test": "phpdbg -qrr vendor/bin/phpunit --order-by=random --testdox --colors=always",
"test:ci": "@test --coverage-clover=build/clover.xml --coverage-xml=build/coverage-xml --log-junit=build/junit.xml",
"test:pretty": "@test --coverage-html build/coverage-html",
"infect": "infection --threads=4 --min-msi=85 --log-verbosity=default --only-covered --only-covering-test-cases",
"infect": "infection --threads=4 --min-msi=80 --log-verbosity=default --only-covered --only-covering-test-cases",
"infect:ci": "@infect --coverage=build --skip-initial-tests",
"infect:show": "@infect --show-mutations",
"infect:show:ci": "@infect --show-mutations --coverage=build",
Expand Down
6 changes: 3 additions & 3 deletions src/Visits/Model/OrphanVisit.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public function referer(): string
return $this->visit->referer();
}

public function dateTime(): DateTimeInterface
public function date(): DateTimeInterface
{
return $this->visit->dateTime();
return $this->visit->date();
}

public function userAgent(): string
Expand All @@ -45,7 +45,7 @@ public function potentialBot(): bool
return $this->visit->potentialBot();
}

public function location(): VisitLocation
public function location(): ?VisitLocation
{
return $this->visit->location();
}
Expand Down
12 changes: 6 additions & 6 deletions src/Visits/Model/Visit.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ final class Visit implements VisitInterface
{
private function __construct(
private string $referer,
private DateTimeInterface $dateTime,
private DateTimeInterface $date,
private string $userAgent,
private bool $potentialBot,
private VisitLocation $location,
private ?VisitLocation $location,
) {
}

Expand All @@ -25,7 +25,7 @@ public static function fromArray(array $payload): self
DateTimeImmutable::createFromFormat(DateTimeInterface::ATOM, $payload['date']), // @phpstan-ignore-line
$payload['userAgent'] ?? '',
$payload['potentialBot'] ?? false,
VisitLocation::fromArray($payload['visitLocation'] ?? []),
isset($payload['visitLocation']) ? VisitLocation::fromArray($payload['visitLocation']) : null,
);
}

Expand All @@ -34,9 +34,9 @@ public function referer(): string
return $this->referer;
}

public function dateTime(): DateTimeInterface
public function date(): DateTimeInterface
{
return $this->dateTime;
return $this->date;
}

public function userAgent(): string
Expand All @@ -49,7 +49,7 @@ public function potentialBot(): bool
return $this->potentialBot;
}

public function location(): VisitLocation
public function location(): ?VisitLocation
{
return $this->location;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Visits/Model/VisitInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
interface VisitInterface
{
public function referer(): string;
public function dateTime(): DateTimeInterface;
public function date(): DateTimeInterface;
public function userAgent(): string;
public function potentialBot(): bool;
public function location(): VisitLocation;
public function location(): ?VisitLocation;
}
16 changes: 9 additions & 7 deletions test/Domains/Model/DomainRedirectsConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,26 @@ class DomainRedirectsConfigTest extends TestCase
* @test
* @dataProvider provideConfigs
*/
public function payloadIsBuiltAsExpected(DomainRedirectsConfig $config, array $expectedPayload): void
public function payloadIsBuiltAsExpected(callable $createConfig, array $expectedPayload): void
{
/** @var DomainRedirectsConfig $config */
$config = $createConfig();
self::assertEquals($expectedPayload, $config->jsonSerialize());
}

public function provideConfigs(): iterable
{
yield [DomainRedirectsConfig::forDomain('foo.com'), ['domain' => 'foo.com']];
yield [fn () => DomainRedirectsConfig::forDomain('foo.com'), ['domain' => 'foo.com']];
yield [
DomainRedirectsConfig::forDomain('foo.com')
fn () => DomainRedirectsConfig::forDomain('foo.com')
->withRegularNotFoundRedirect('somewhere.com'),
[
'domain' => 'foo.com',
DomainRedirectProps::REGULAR_NOT_FOUND => 'somewhere.com',
],
];
yield [
DomainRedirectsConfig::forDomain('bar.com')
fn () => DomainRedirectsConfig::forDomain('bar.com')
->withRegularNotFoundRedirect('foo.com')
->removingBaseUrlRedirect(),
[
Expand All @@ -41,7 +43,7 @@ public function provideConfigs(): iterable
],
];
yield [
DomainRedirectsConfig::forDomain('bar.com')
fn () => DomainRedirectsConfig::forDomain('bar.com')
->withRegularNotFoundRedirect('foo.net')
->withInvalidShortUrlRedirect('something.com')
->removingBaseUrlRedirect(),
Expand All @@ -53,7 +55,7 @@ public function provideConfigs(): iterable
],
];
yield [
DomainRedirectsConfig::forDomain('baz.com')
fn () => DomainRedirectsConfig::forDomain('baz.com')
->removingBaseUrlRedirect()
->removingRegularNotFoundRedirect()
->removingInvalidShortUrlRedirect(),
Expand All @@ -65,7 +67,7 @@ public function provideConfigs(): iterable
],
];
yield [
DomainRedirectsConfig::forDomain('foobarbaz.com')
fn () => DomainRedirectsConfig::forDomain('foobarbaz.com')
->withRegularNotFoundRedirect('foo.net')
->withInvalidShortUrlRedirect('something.com')
->withBaseUrlRedirect('base-redirect.com'),
Expand Down
Loading

0 comments on commit adabe2e

Please sign in to comment.