Completed
Push — master ( dbb439...8abb49 )
by Jakub
01:34
created

TestCaseTest::getOne()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace MyTester;
5
6
use MyTester\Annotations\Attributes\DataProvider;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, MyTester\DataProvider. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use MyTester\Annotations\Attributes\Skip;
8
use MyTester\Annotations\Attributes\Test;
9
use MyTester\Annotations\Attributes\TestSuite;
10
11
/**
12
 * Test suite for class TestCase
13
 * 
14
 * @testSuite TestCase
15
 * @author Jakub Konečný
16
 * @property-read bool|int $one
17
 */
18
#[TestSuite("TestCase")]
0 ignored issues
show
introduced by
This comment is 84% valid code; is this commented out code?
Loading history...
19
final class TestCaseTest extends TestCase {
20
  /** @var bool|int */
21
  private $one = false;
22
23
  /**
24
   * @return bool|int
25
   */
26
  public function getOne() {
27
    return $this->one;
28
  }
29
  
30
  public function setUp(): void {
31
    $this->one = 1;
1 ignored issue
show
Bug introduced by
The property one is declared read-only in MyTester\TestCaseTest.
Loading history...
32
  }
33
  
34
  public function tearDown(): void {
35
    $this->one = false;
1 ignored issue
show
Bug introduced by
The property one is declared read-only in MyTester\TestCaseTest.
Loading history...
36
  }
37
  
38
  public function shutDown(): void {
39
    $this->assertFalsey($this->one);
40
  }
41
42
  public function testState(): void {
43
    $this->assertFalse($this->shouldFail);
44
    $this->assertSame(1, $this->getCounter());
45
    $this->incCounter();
46
    $this->assertSame(3, $this->getCounter());
47
    $this->resetCounter();
48
    $this->assertSame(0, $this->getCounter());
49
  }
50
  
51
  /**
52
   * Test parameters
53
   *
54
   * @dataProvider(dataProvider)
55
   */
56
  #[DataProvider("dataProvider")]
0 ignored issues
show
introduced by
This comment is 84% valid code; is this commented out code?
Loading history...
57
  public function testParams(string $text): void {
58
    $this->assertType("string", $text);
59
    $this->assertContains("a", $text);
60
  }
61
62
  public function dataProvider(): array {
63
    return ["abc", "adef", ];
64
  }
65
  
66
  /**
67
   * Test custom test's name
68
   * 
69
   * @test Custom name
70
   */
71
  #[Test("Custom name")]
0 ignored issues
show
introduced by
This comment is 84% valid code; is this commented out code?
Loading history...
72
  public function testTestName(): void {
73
    $this->assertSame(1, $this->one);
74
  }
75
  
76
  /**
77
   * Test unconditional skipping
78
   * 
79
   * @test Skip
80
   * @skip
81
   */
82
  #[Test("Skip")]
0 ignored issues
show
introduced by
This comment is 75% valid code; is this commented out code?
Loading history...
83
  #[Skip()]
84
  public function testSkip(): void {
85
    $this->assertTrue(false);
86
  }
87
  
88
  /**
89
   * Test skipping based on boolean
90
   * 
91
   * @test Boolean
92
   * @skip(true)
93
   */
94
  #[Test("Boolean")]
0 ignored issues
show
introduced by
This comment is 77% valid code; is this commented out code?
Loading history...
95
  #[Skip(true)]
96
  public function testSkipBoolean(): void {
97
    $this->assertTrue(false);
98
  }
99
  
100
  /**
101
   * Test skipping based on integer
102
   * 
103
   * @test Integer
104
   * @skip(1)
105
   */
106
  #[Test("Integer")]
0 ignored issues
show
introduced by
This comment is 75% valid code; is this commented out code?
Loading history...
107
  #[Skip(1)]
108
  public function testSkipInteger(): void {
109
    $this->assertTrue(false);
110
  }
111
  
112
  /**
113
   * Test skipping based on float
114
   * 
115
   * @test Float
116
   * @skip(1.5)
117
   */
118
  #[Test("Integer")]
0 ignored issues
show
introduced by
This comment is 70% valid code; is this commented out code?
Loading history...
119
  #[Skip(1.5)]
120
  public function testSkipFloat(): void {
121
    $this->assertTrue(false);
122
  }
123
  
124
  /**
125
   * Test skipping based on string
126
   * 
127
   * @test String
128
   * @skip(abc)
129
   */
130
  #[Test("String")]
0 ignored issues
show
introduced by
This comment is 77% valid code; is this commented out code?
Loading history...
131
  #[Skip("abc")]
132
  public function testSkipString(): void {
133
    $this->assertTrue(false);
134
  }
135
  
136
  /**
137
   * Test skipping based on PHP version
138
   * 
139
   * @test PHP version
140
   * @skip(php=666)
141
   */
142
  #[Test("PHP version")]
0 ignored issues
show
introduced by
This comment is 73% valid code; is this commented out code?
Loading history...
143
  #[Skip(["php" => 666])]
144
  public function testSkipPhpVersion(): void {
145
    $this->assertTrue(false);
146
  }
147
148
  /**
149
   * Test skipping based on sapi
150
   *
151
   * @test CGI sapi
152
   * @skip(sapi=abc)
153
   */
154
  #[Test("CGI sapi")]
0 ignored issues
show
introduced by
This comment is 74% valid code; is this commented out code?
Loading history...
155
  #[Skip(["sapi" => "abc"])]
156
  public function testCgiSapi(): void {
157
    $this->assertNotSame(PHP_SAPI, "abc");
158
  }
159
  
160
  /**
161
   * Test skipping based on loaded extension
162
   * 
163
   * @test Extension
164
   * @skip(extension=abc)
165
   */
166
  #[Test("Extension")]
0 ignored issues
show
introduced by
This comment is 74% valid code; is this commented out code?
Loading history...
167
  #[Skip(["extension" => "abc"])]
168
  public function testSkipExtension(): void {
169
    $this->assertTrue(false);
170
  }
171
}
172
?>