Test Failed
Push — master ( 8413e5...65cae7 )
by Jakub
02:11
created

ParamLocaleResolverTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 30
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testResolve() 0 17 1
A setUp() 0 8 1
A testCustomParamName() 0 12 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Translation\Bridges\NetteApplication;
5
6
use Tester\Assert;
7
use Nette\Application\Request;
8
use Nette\Application\Application;
9
10
require __DIR__ . "/../../../../bootstrap.php";
11
12
/**
13
 * @author Jakub Konečný
14
 * @testCase
15
 */
16
final class ParamLocaleResolverTest extends \Tester\TestCase {
17
  use \Testbench\TCompiledContainer;
18
19
  protected ParamLocaleResolver $resolver;
20
  
21
  protected function setUp(): void {
22
    $config = [
23
      "translation" => [
24
        "localeResolver" => "param"
25
      ]
26
    ];
27
    $this->refreshContainer($config);
28
    $this->resolver = $this->getService(ParamLocaleResolver::class); // @phpstan-ignore assign.propertyType
29
  }
30
  
31
  public function testResolve(): void {
32
    $parameters = [
33
      "callback" => function() {
34
        return "";
35
      }
36
    ];
37
    Assert::null($this->resolver->resolve());
38
    /** @var Application $application */
39
    $application = $this->getService(Application::class);
40
    $request = new Request("Micro", Request::FORWARD, $parameters);
41
    Assert::null($this->resolver->resolve());
42
    $request->method = "GET";
43
    $application->processRequest($request);
44
    $parameters["locale"] = "en";
45
    $request->parameters = $parameters;
46
    $application->processRequest($request);
47
    Assert::same("en", $this->resolver->resolve());
48
  }
49
50
  public function testCustomParamName(): void {
51
    $this->resolver->param = "language";
52
    $parameters = [
53
      "callback" => function() {
54
        return "";
55
      }, "language" => "en",
56
    ];
57
    /** @var Application $application */
58
    $application = $this->getService(Application::class);
59
    $request = new Request("Micro", "GET", $parameters);
60
    $application->processRequest($request);
61
    Assert::same("en", $this->resolver->resolve());
62
  }
63
}
64
65
$test = new ParamLocaleResolverTest();
66
$test->run();
67
?>