Passed
Push — master ( 9fb777...c455df )
by Gerrit
01:50
created

ArgumentCompilerTest::shouldBuildArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.7
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
/**
3
 * Copyright (C) 2017  Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\SymfonyGenerics\Tests\Integration\Arguments;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\SymfonyGenerics\Services\ArgumentCompiler;
15
use Addiks\SymfonyGenerics\Services\NewArgumentCompiler;
16
use Psr\Container\ContainerInterface;
17
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
18
use Symfony\Component\Config\FileLocator;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Doctrine\ORM\EntityManager;
22
use Symfony\Component\HttpFoundation\RequestStack;
23
24
final class ArgumentCompilerTest extends TestCase
25
{
26
27
    /**
28
     * @var ArgumentCompiler
29
     */
30
    private $oldCompiler;
31
32
    /**
33
     * @var NewArgumentCompiler
34
     */
35
    private $newCompiler;
36
37
    /**
38
     * @var ContainerInterface
39
     */
40
    private $container;
41
42
    /**
43
     * @var XmlFileLoader
44
     */
45
    private $loader;
46
47
    public function setUp()
48
    {
49
        $this->container = new ContainerBuilder();
50
51
        $this->loader = new XmlFileLoader(
52
            $this->container,
53
            new FileLocator(__DIR__ . '/../../..')
54
        );
55
56
        $this->loader->load('services.xml');
57
58
        $this->container->set('doctrine.orm.entity_manager', $this->createMock(EntityManager::class));
59
        $this->container->set('request_stack', new RequestStack());
60
61
        $this->oldCompiler = $this->container->get('symfony_generics.argument_compiler');
62
        $this->newCompiler = $this->container->get('symfony_generics.argument_compiler.new');
63
    }
64
65
    /**
66
     * @test
67
     * @dataProvider dataProviderForShouldBuildArguments
68
     */
69
    public function shouldBuildArguments($expectedResult, string $argumentsConfiguration, array $additionalData)
70
    {
71
        /** @var Request $request */
72
        $request = $this->createMock(Request::class);
73
        $request->method("getContent")->willReturn("request-content");
0 ignored issues
show
Bug introduced by
The method method() does not exist on Symfony\Component\HttpFoundation\Request. Did you maybe mean enableHttpMethodParameterOverride()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
74
75
        $this->container->get('request_stack')->push($request);
76
77
        /** @var mixed $actualOldResult */
78
        $actualOldResult = $this->oldCompiler->buildArguments([$argumentsConfiguration], $request, $additionalData);
79
80
        /** @var mixed $actualOldResult */
81
        $actualNewResult = $this->newCompiler->buildArguments([$argumentsConfiguration], $request, $additionalData);
82
83
        $this->assertEquals($expectedResult, $actualNewResult[0]);
84
        $this->assertEquals($expectedResult, $actualOldResult[0]);
85
    }
86
87
    public function dataProviderForShouldBuildArguments()
88
    {
89
        return array(
90
            [null, "", []],
91
            ["request-content", "$", []],
92
        );
93
    }
94
95
}
96