Passed
Push — develop ( 0d7fb1...8577d6 )
by Alejandro
09:01 queued 01:01
created

alwaysReturnsNullForApiKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 1
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ShlinkioTest\Shlink\Core\ShortUrl\Resolver;
6
7
use PHPUnit\Framework\TestCase;
8
use Shlinkio\Shlink\Core\Entity\Domain;
9
use Shlinkio\Shlink\Core\ShortUrl\Resolver\SimpleShortUrlRelationResolver;
10
11
class SimpleShortUrlRelationResolverTest extends TestCase
12
{
13
    private SimpleShortUrlRelationResolver $resolver;
14
15
    public function setUp(): void
16
    {
17
        $this->resolver = new SimpleShortUrlRelationResolver();
18
    }
19
20
    /**
21
     * @test
22
     * @dataProvider provideDomains
23
     */
24
    public function resolvesExpectedDomain(?string $domain): void
25
    {
26
        $result = $this->resolver->resolveDomain($domain);
27
28
        if ($domain === null) {
29
            self::assertNull($result);
30
        } else {
31
            self::assertInstanceOf(Domain::class, $result);
32
            self::assertEquals($domain, $result->getAuthority());
33
        }
34
    }
35
36
    public function provideDomains(): iterable
37
    {
38
        yield 'empty domain' => [null];
39
        yield 'non-empty domain' => ['domain.com'];
40
    }
41
42
    /**
43
     * @test
44
     * @dataProvider provideKeys
45
     */
46
    public function alwaysReturnsNullForApiKeys(?string $key): void
47
    {
48
        self::assertNull($this->resolver->resolveApiKey($key));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->resolver->resolveApiKey($key) targeting Shlinkio\Shlink\Core\Sho...solver::resolveApiKey() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
49
    }
50
51
    public function provideKeys(): iterable
52
    {
53
        yield 'empty api key' => [null];
54
        yield 'non-empty api key' => ['abc123'];
55
    }
56
}
57