AbstractTestCase   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 2
A getTestUrl() 0 7 3
1
<?php
2
declare(strict_types=1);
3
4
namespace DiscordWebhook\Test;
5
6
use DiscordWebhook\Webhook;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * Class AbstractTestCase
11
 *
12
 * @package DiscordWebhook\Test
13
 * @author Scrummer <[email protected]>
14
 */
15
class AbstractTestCase extends TestCase
16
{
17
    /**
18
     * @var Webhook
19
     */
20
    protected $webhook;
21
22
    /**
23
     * @var string
24
     */
25
    private $testUrl;
26
27
    protected function setUp(): void
28
    {
29
        $this->webhook = new Webhook($this->getTestUrl());
0 ignored issues
show
Bug introduced by
$this->getTestUrl() of type string is incompatible with the type array expected by parameter $url of DiscordWebhook\Webhook::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
        $this->webhook = new Webhook(/** @scrutinizer ignore-type */ $this->getTestUrl());
Loading history...
30
31
        if ($this->getTestUrl() === '') {
32
            throw new \LogicException('Cannot test webhook without test URL. Please provide it as environment variable in the docker-compose.yml file.');
33
        }
34
    }
35
36
    protected function getTestUrl(): ?string
37
    {
38
        if (null === $this->webhook) {
39
            $this->testUrl = getenv('DISCORD_TEST_URL') ?: '';
40
        }
41
42
        return $this->testUrl;
43
    }
44
}
45