Completed
Push — master ( f7b33a...213343 )
by Andy
03:36
created

AbstractTest::configProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace Palmtree\CanonicalUrlBundle\Tests;
4
5
use PHPUnit\Framework\TestCase;
6
use Symfony\Component\Config\Loader\LoaderInterface;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\Routing\RequestContext;
9
use Symfony\Component\Routing\Route;
10
use Symfony\Component\Routing\RouteCollection;
11
use Symfony\Component\Routing\Router;
12
13
abstract class AbstractTest extends TestCase
14
{
15
    public function getRouter($routeCollection = null)
16
    {
17
        if (! $routeCollection) {
18
            $routeCollection = $this->getFooRouteCollection();
19
        }
20
21
        $loader = $this->createMock(LoaderInterface::class);
22
        $loader->method('load')->willReturn($routeCollection);
23
24
        /** @var LoaderInterface $loader */
25
        $context = new RequestContext();
26
        $context->setScheme('https')->setHost('example.org');
27
28
        $router = new Router($loader, '');
29
        $router->setContext($context);
30
31
        return $router;
32
    }
33
34
    public function getFooRouteCollection()
35
    {
36
        $routeCollection = new RouteCollection();
37
        $routeCollection->add('foo', new Route('/foo'));
38
        $routeCollection->setHost('example.org');
39
40
        return $routeCollection;
41
    }
42
43
    /**
44
     * @param bool $secure
45
     * @return Request
46
     */
47
    protected function getFooRequest($secure = true)
48
    {
49
        $scheme = ($secure) ? 'https' : 'http';
50
51
        $request = Request::create("$scheme://example.org/foo/");
52
        $request->attributes->set('_route', 'foo');
53
54
        return $request;
55
    }
56
57 View Code Duplication
    public function configProvider()
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...
58
    {
59
        return array(
60
            'config' => array(
61
                array(
62
                    'site_url'       => 'https://example.org',
63
                    'redirect'       => true,
64
                    'redirect_code'  => 302,
65
                    'trailing_slash' => false,
66
                )
67
            )
68
        );
69
    }
70
}
71