Skip to content

Commit 0461f96

Browse files
localheinzsebastianbergmann
authored andcommitted
Fix: Use class keyword
1 parent 68b9ace commit 0461f96

15 files changed

+262
-106
lines changed

tests/unit/Framework/AssertTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,20 +214,20 @@ public function testAssertArrayNotContainsOnlyIntegers(): void
214214

215215
public function testAssertArrayContainsOnlyStdClass(): void
216216
{
217-
$this->assertContainsOnly('StdClass', [new stdClass]);
217+
$this->assertContainsOnly(stdClass::class, [new stdClass]);
218218

219219
$this->expectException(AssertionFailedError::class);
220220

221-
$this->assertContainsOnly('StdClass', ['StdClass']);
221+
$this->assertContainsOnly(stdClass::class, [stdClass::class]);
222222
}
223223

224224
public function testAssertArrayNotContainsOnlyStdClass(): void
225225
{
226-
$this->assertNotContainsOnly('StdClass', ['StdClass']);
226+
$this->assertNotContainsOnly(stdClass::class, [stdClass::class]);
227227

228228
$this->expectException(AssertionFailedError::class);
229229

230-
$this->assertNotContainsOnly('StdClass', [new stdClass]);
230+
$this->assertNotContainsOnly(stdClass::class, [new stdClass]);
231231
}
232232

233233
public function equalProvider(): array
@@ -930,7 +930,7 @@ public function testAssertThatIdenticalTo(): void
930930

931931
public function testAssertThatIsInstanceOf(): void
932932
{
933-
$this->assertThat(new stdClass, $this->isInstanceOf('StdClass'));
933+
$this->assertThat(new stdClass, $this->isInstanceOf(stdClass::class));
934934
}
935935

936936
public function testAssertThatIsType(): void
@@ -1412,7 +1412,7 @@ public function testAssertInstanceOfThrowsExceptionIfTypeDoesNotExist(): void
14121412
{
14131413
$this->expectException(Exception::class);
14141414

1415-
$this->assertInstanceOf('ClassThatDoesNotExist', new stdClass);
1415+
$this->assertInstanceOf(ClassThatDoesNotExist::class, new stdClass);
14161416
}
14171417

14181418
public function testAssertInstanceOf(): void
@@ -1428,7 +1428,7 @@ public function testAssertNotInstanceOfThrowsExceptionIfTypeDoesNotExist(): void
14281428
{
14291429
$this->expectException(Exception::class);
14301430

1431-
$this->assertNotInstanceOf('ClassThatDoesNotExist', new stdClass);
1431+
$this->assertNotInstanceOf(ClassThatDoesNotExist::class, new stdClass);
14321432
}
14331433

14341434
public function testAssertNotInstanceOf(): void

tests/unit/Framework/Constraint/ClassHasAttributeTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ public function testConstraintClassHasAttribute(): void
3333
$constraint->evaluate(stdClass::class);
3434
} catch (ExpectationFailedException $e) {
3535
$this->assertEquals(
36-
<<<'EOF'
37-
Failed asserting that class "stdClass" has attribute "privateAttribute".
36+
sprintf(
37+
<<<'EOF'
38+
Failed asserting that class "%s" has attribute "privateAttribute".
3839

3940
EOF
40-
,
41+
,
42+
stdClass::class
43+
),
4144
TestFailure::exceptionToString($e)
4245
);
4346

@@ -57,12 +60,15 @@ public function testConstraintClassHasAttribute2(): void
5760
$constraint->evaluate(stdClass::class, 'custom message');
5861
} catch (ExpectationFailedException $e) {
5962
$this->assertEquals(
60-
<<<'EOF'
63+
sprintf(
64+
<<<'EOF'
6165
custom message
62-
Failed asserting that class "stdClass" has attribute "privateAttribute".
66+
Failed asserting that class "%s" has attribute "privateAttribute".
6367

6468
EOF
65-
,
69+
,
70+
stdClass::class
71+
),
6672
TestFailure::exceptionToString($e)
6773
);
6874

tests/unit/Framework/Constraint/ClassHasStaticAttributeTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ public function testConstraintClassHasStaticAttribute(): void
3131
$constraint->evaluate(stdClass::class);
3232
} catch (ExpectationFailedException $e) {
3333
$this->assertEquals(
34-
<<<'EOF'
35-
Failed asserting that class "stdClass" has static attribute "privateStaticAttribute".
34+
sprintf(
35+
<<<'EOF'
36+
Failed asserting that class "%s" has static attribute "privateStaticAttribute".
3637

3738
EOF
38-
,
39+
,
40+
stdClass::class
41+
),
3942
TestFailure::exceptionToString($e)
4043
);
4144

@@ -53,12 +56,15 @@ public function testConstraintClassHasStaticAttribute2(): void
5356
$constraint->evaluate(stdClass::class, 'custom message');
5457
} catch (ExpectationFailedException $e) {
5558
$this->assertEquals(
56-
<<<'EOF'
59+
sprintf(
60+
<<<'EOF'
5761
custom message
58-
Failed asserting that class "stdClass" has static attribute "foo".
62+
Failed asserting that class "%s" has static attribute "foo".
5963

6064
EOF
61-
,
65+
,
66+
stdClass::class
67+
),
6268
TestFailure::exceptionToString($e)
6369
);
6470

tests/unit/Framework/Constraint/IsIdenticalTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ public function testConstraintIsIdentical(): void
2626

2727
$this->assertFalse($constraint->evaluate($b, '', true));
2828
$this->assertTrue($constraint->evaluate($a, '', true));
29-
$this->assertEquals('is identical to an object of class "stdClass"', $constraint->toString());
29+
$this->assertEquals(
30+
sprintf(
31+
'is identical to an object of class "%s"',
32+
stdClass::class
33+
),
34+
$constraint->toString()
35+
);
3036
$this->assertCount(1, $constraint);
3137

3238
try {

tests/unit/Framework/Constraint/IsInstanceOfTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@ public function testConstraintFailsOnString(): void
3030
$constraint = new IsInstanceOf(stdClass::class);
3131

3232
try {
33-
$constraint->evaluate('stdClass');
33+
$constraint->evaluate(stdClass::class);
3434
} catch (ExpectationFailedException $e) {
3535
$this->assertSame(
36-
<<<'EOT'
37-
Failed asserting that 'stdClass' is an instance of class "stdClass".
36+
sprintf(
37+
<<<'EOT'
38+
Failed asserting that '%s' is an instance of class "%s".
3839

3940
EOT
40-
,
41+
,
42+
stdClass::class,
43+
stdClass::class
44+
),
4145
TestFailure::exceptionToString($e)
4246
);
4347
}
@@ -50,7 +54,10 @@ public function testCronstraintsThrowsReflectionException(): void
5054
$constraint = new IsInstanceOf(NotExistingClass::class);
5155

5256
$this->assertSame(
53-
'is instance of class "PHPUnit\Framework\Constraint\NotExistingClass"',
57+
sprintf(
58+
'is instance of class "%s"',
59+
NotExistingClass::class
60+
),
5461
$constraint->toString()
5562
);
5663
}

tests/unit/Framework/Constraint/IsTypeTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ public function testConstraintIsType(): void
3636
$constraint->evaluate(new stdClass);
3737
} catch (ExpectationFailedException $e) {
3838
$this->assertStringMatchesFormat(
39-
<<<'EOF'
40-
Failed asserting that stdClass Object #%d () is of type "string".
39+
sprintf(
40+
<<<'EOF'
41+
Failed asserting that %s Object #%%d () is of type "string".
4142

4243
EOF
43-
,
44+
,
45+
stdClass::class
46+
),
4447
$this->trimnl(TestFailure::exceptionToString($e))
4548
);
4649

@@ -58,12 +61,15 @@ public function testConstraintIsType2(): void
5861
$constraint->evaluate(new stdClass, 'custom message');
5962
} catch (ExpectationFailedException $e) {
6063
$this->assertStringMatchesFormat(
61-
<<<'EOF'
64+
sprintf(
65+
<<<'EOF'
6266
custom message
63-
Failed asserting that stdClass Object #%d () is of type "string".
67+
Failed asserting that %s Object #%%d () is of type "string".
6468

6569
EOF
6670
,
71+
stdClass::class
72+
),
6773
$this->trimnl(TestFailure::exceptionToString($e))
6874
);
6975

tests/unit/Framework/Constraint/ObjectHasAttributeTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ public function testConstraintObjectHasAttribute(): void
3131
$constraint->evaluate(new stdClass);
3232
} catch (ExpectationFailedException $e) {
3333
$this->assertEquals(
34-
<<<'EOF'
35-
Failed asserting that object of class "stdClass" has attribute "privateAttribute".
34+
sprintf(
35+
<<<'EOF'
36+
Failed asserting that object of class "%s" has attribute "privateAttribute".
3637

3738
EOF
38-
,
39+
,
40+
stdClass::class
41+
),
3942
TestFailure::exceptionToString($e)
4043
);
4144

@@ -53,12 +56,15 @@ public function testConstraintObjectHasAttribute2(): void
5356
$constraint->evaluate(new stdClass, 'custom message');
5457
} catch (ExpectationFailedException $e) {
5558
$this->assertEquals(
56-
<<<'EOF'
59+
sprintf(
60+
<<<'EOF'
5761
custom message
58-
Failed asserting that object of class "stdClass" has attribute "privateAttribute".
62+
Failed asserting that object of class "%s" has attribute "privateAttribute".
5963

6064
EOF
61-
,
65+
,
66+
stdClass::class
67+
),
6268
TestFailure::exceptionToString($e)
6369
);
6470

0 commit comments

Comments
 (0)