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); |
|
|
|
|
24
|
|
|
|
25
|
|
|
$this->assertEquals('mailto:[email protected]', $urlHelper->replaceUrl('[email protected]')); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
public function testReplaceUrlWithInternalLink() |
|
|
|
|
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); |
|
|
|
|
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() |
|
|
|
|
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); |
|
|
|
|
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
|
|
|
|
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: