Completed
Push — master ( 6dc195...257818 )
by Jeroen
04:37 queued 04:31
created

UrlHelperTest::testReplaceUrlWithMediaLink()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\NodeBundle\Tests\Helper;
4
5
use Doctrine\DBAL\Connection;
6
use Doctrine\DBAL\Driver\Statement;
7
use Doctrine\ORM\EntityManager;
8
use Kunstmaan\AdminBundle\Helper\DomainConfigurationInterface;
9
use Kunstmaan\NodeBundle\Helper\URLHelper;
10
use PHPUnit\Framework\TestCase;
11
use Psr\Log\LoggerInterface;
12
use Symfony\Component\Routing\RouterInterface;
13
14
class UrlHelperTest extends TestCase
15
{
16
    public function testReplaceUrlWithEmail()
17
    {
18
        $em = $this->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock();
19
        $router = $this->getMockBuilder(RouterInterface::class)->getMock();
20
        $logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
21
        $domainConfig = $this->getMockBuilder(DomainConfigurationInterface::class)->getMock();
22
23
        $urlHelper = new URLHelper($em, $router, $logger, $domainConfig);
0 ignored issues
show
Documentation introduced by
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManager>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$router is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component\Routing\RouterInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$logger is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Log\LoggerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$domainConfig is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminBu...ConfigurationInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
24
25
        $this->assertEquals('mailto:[email protected]', $urlHelper->replaceUrl('[email protected]'));
26
    }
27
28 View Code Duplication
    public function testReplaceUrlWithInternalLink()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        $stmt = $this->getMockBuilder(Statement::class)->getMock();
31
        $stmt->expects($this->once())->method('fetch')->willReturn(['id' => 18, 'url' => 'abc']);
32
        $conn = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
33
        $conn->expects($this->once())->method('executeQuery')->willReturn($stmt);
34
        $em = $this->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock();
35
        $em->expects($this->once())->method('getConnection')->willReturn($conn);
36
        $router = $this->getMockBuilder(RouterInterface::class)->getMock();
37
        $router->method('generate')->with('_slug', ['url' => 'abc'])->willReturn('/abc');
38
        $logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
39
        $domainConfig = $this->getMockBuilder(DomainConfigurationInterface::class)->getMock();
40
41
        $urlHelper = new URLHelper($em, $router, $logger, $domainConfig);
0 ignored issues
show
Documentation introduced by
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManager>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$router is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component\Routing\RouterInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$logger is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Log\LoggerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$domainConfig is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminBu...ConfigurationInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
42
        $this->assertEquals('/abc', $urlHelper->replaceUrl('[NT18]'));
43
44
        //Second call to replaceUrl should not execute query again
45
        $this->assertEquals('/abc', $urlHelper->replaceUrl('[NT18]'));
46
    }
47
48 View Code Duplication
    public function testReplaceUrlWithMediaLink()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
49
    {
50
        $stmt = $this->getMockBuilder(Statement::class)->getMock();
51
        $stmt->expects($this->once())->method('fetch')->willReturn(['id' => 18, 'url' => '/uploads/media/5e24be27412e6/test.svg']);
52
        $conn = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
53
        $conn->expects($this->once())->method('executeQuery')->willReturn($stmt);
54
        $em = $this->getMockBuilder(EntityManager::class)->disableOriginalConstructor()->getMock();
55
        $em->expects($this->once())->method('getConnection')->willReturn($conn);
56
        $router = $this->getMockBuilder(RouterInterface::class)->getMock();
57
        $router->method('generate')->with('_slug', ['url' => 'abc'])->willReturn('/abc');
58
        $logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
59
        $domainConfig = $this->getMockBuilder(DomainConfigurationInterface::class)->getMock();
60
61
        $urlHelper = new URLHelper($em, $router, $logger, $domainConfig);
0 ignored issues
show
Documentation introduced by
$em is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\ORM\EntityManager>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$router is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component\Routing\RouterInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$logger is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Log\LoggerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$domainConfig is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Kunstmaan\AdminBu...ConfigurationInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
        $this->assertEquals('/uploads/media/5e24be27412e6/test.svg', $urlHelper->replaceUrl('[M18]'));
63
64
        //Second call to replaceUrl should not execute query again
65
        $this->assertEquals('/uploads/media/5e24be27412e6/test.svg', $urlHelper->replaceUrl('[M18]'));
66
    }
67
}
68