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

TranslationPanelTest::testGetPanel()   B

Complexity

Conditions 10
Paths 16

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 27
rs 7.6666
c 0
b 0
f 0
cc 10
nc 16
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Translation\Bridges\Tracy;
5
6
use Tester\Assert;
7
use Nexendrie\Translation\Translator;
8
9
require __DIR__ . "/../../../../bootstrap.php";
10
11
/**
12
 * @author Jakub Konečný
13
 * @testCase
14
 */
15
final class TranslationPanelTest extends \Tester\TestCase {
16
  use \Testbench\TCompiledContainer;
17
18
  protected TranslationPanel $panel;
19
  
20
  protected function setUp(): void {
21
    $this->panel = $this->getService(TranslationPanel::class); // @phpstan-ignore assign.propertyType
22
  }
23
  
24
  public function testGetTab(): void {
25
    $result = $this->panel->getTab();
26
    Assert::type("string", $result);
27
    $r = new \SimpleXMLElement($result);
28
    Assert::same("Translation", (string) $r["title"]);
29
    Assert::contains("en", (string) $r);
30
  }
31
  
32
  public function testGetPanel(): void {
33
    $result = $this->panel->getPanel();
34
    Assert::type("string", $result);
35
    $r = new \SimpleXMLElement("<root>$result</root>");
36
    Assert::same(2, $r->count());
37
    $text = (string) $r->p;
38
    Assert::same("Untranslated messages: 0, loaded resources 0", $text);
39
    Assert::same("Resolved language", (string) $r->div->div->h1);
40
    foreach($r->div->div->table->tr->children() as $i => $td) {
41
      if($i === 0) {
42
        Assert::same("ManualLocaleResolver", (string) $td);
43
      } elseif($i === 1) {
44
        Assert::same("en", (string) $td);
45
      }
46
    }
47
    foreach($r->children() as $i1 => $div) {
48
      if($i1 === 1) {
49
        Assert::same("Loaded resources", (string) $div->h1);
50
        foreach($div->table->th as $i2 => $td) {
51
          if($i2 === 0) {
52
            Assert::same("Domain", (string) $td);
53
          } elseif($i2 === 1) {
54
            Assert::same("Filename", (string) $td);
55
          }
56
        }
57
      } elseif($i1 === 2) {
58
        Assert::count(0, $div->children());
59
      }
60
    }
61
  }
62
  
63
  public function testGetPanelResources(): void {
64
    /** @var Translator $translator */
65
    $translator = $this->getService(Translator::class);
66
    $translator->translate("xyz");
67
    $result = $this->panel->getPanel();
68
    Assert::type("string", $result);
69
    $r = new \SimpleXMLElement("<root>$result</root>");
70
    $text = (string) $r->p;
71
    Assert::same("Untranslated messages: 0, loaded resources 2", $text);
72
  }
73
  
74
  public function testGetPanelWithMessages(): void {
75
    /** @var Translator $translator */
76
    $translator = $this->getService(Translator::class);
77
    $translator->translate("abcd");
78
    $result = $this->panel->getPanel();
79
    Assert::type("string", $result);
80
    $r = new \SimpleXMLElement("<root>$result</root>");
81
    $text = (string) $r->p;
82
    Assert::same("Untranslated messages: 1, loaded resources 2", $text);
83
  }
84
}
85
86
$test = new TranslationPanelTest();
87
$test->run();
88
?>