Skip to content

Commit

Permalink
Fix: Use class keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz authored and sebastianbergmann committed Mar 8, 2022
1 parent 68b9ace commit 0461f96
Show file tree
Hide file tree
Showing 15 changed files with 262 additions and 106 deletions.
14 changes: 7 additions & 7 deletions tests/unit/Framework/AssertTest.php
Expand Up @@ -214,20 +214,20 @@ public function testAssertArrayNotContainsOnlyIntegers(): void

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

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

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

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

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

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

public function equalProvider(): array
Expand Down Expand Up @@ -930,7 +930,7 @@ public function testAssertThatIdenticalTo(): void

public function testAssertThatIsInstanceOf(): void
{
$this->assertThat(new stdClass, $this->isInstanceOf('StdClass'));
$this->assertThat(new stdClass, $this->isInstanceOf(stdClass::class));
}

public function testAssertThatIsType(): void
Expand Down Expand Up @@ -1412,7 +1412,7 @@ public function testAssertInstanceOfThrowsExceptionIfTypeDoesNotExist(): void
{
$this->expectException(Exception::class);

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

public function testAssertInstanceOf(): void
Expand All @@ -1428,7 +1428,7 @@ public function testAssertNotInstanceOfThrowsExceptionIfTypeDoesNotExist(): void
{
$this->expectException(Exception::class);

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

public function testAssertNotInstanceOf(): void
Expand Down
18 changes: 12 additions & 6 deletions tests/unit/Framework/Constraint/ClassHasAttributeTest.php
Expand Up @@ -33,11 +33,14 @@ public function testConstraintClassHasAttribute(): void
$constraint->evaluate(stdClass::class);
} catch (ExpectationFailedException $e) {
$this->assertEquals(
<<<'EOF'
Failed asserting that class "stdClass" has attribute "privateAttribute".
sprintf(
<<<'EOF'
Failed asserting that class "%s" has attribute "privateAttribute".
EOF
,
,
stdClass::class
),
TestFailure::exceptionToString($e)
);

Expand All @@ -57,12 +60,15 @@ public function testConstraintClassHasAttribute2(): void
$constraint->evaluate(stdClass::class, 'custom message');
} catch (ExpectationFailedException $e) {
$this->assertEquals(
<<<'EOF'
sprintf(
<<<'EOF'
custom message
Failed asserting that class "stdClass" has attribute "privateAttribute".
Failed asserting that class "%s" has attribute "privateAttribute".
EOF
,
,
stdClass::class
),
TestFailure::exceptionToString($e)
);

Expand Down
18 changes: 12 additions & 6 deletions tests/unit/Framework/Constraint/ClassHasStaticAttributeTest.php
Expand Up @@ -31,11 +31,14 @@ public function testConstraintClassHasStaticAttribute(): void
$constraint->evaluate(stdClass::class);
} catch (ExpectationFailedException $e) {
$this->assertEquals(
<<<'EOF'
Failed asserting that class "stdClass" has static attribute "privateStaticAttribute".
sprintf(
<<<'EOF'
Failed asserting that class "%s" has static attribute "privateStaticAttribute".
EOF
,
,
stdClass::class
),
TestFailure::exceptionToString($e)
);

Expand All @@ -53,12 +56,15 @@ public function testConstraintClassHasStaticAttribute2(): void
$constraint->evaluate(stdClass::class, 'custom message');
} catch (ExpectationFailedException $e) {
$this->assertEquals(
<<<'EOF'
sprintf(
<<<'EOF'
custom message
Failed asserting that class "stdClass" has static attribute "foo".
Failed asserting that class "%s" has static attribute "foo".
EOF
,
,
stdClass::class
),
TestFailure::exceptionToString($e)
);

Expand Down
8 changes: 7 additions & 1 deletion tests/unit/Framework/Constraint/IsIdenticalTest.php
Expand Up @@ -26,7 +26,13 @@ public function testConstraintIsIdentical(): void

$this->assertFalse($constraint->evaluate($b, '', true));
$this->assertTrue($constraint->evaluate($a, '', true));
$this->assertEquals('is identical to an object of class "stdClass"', $constraint->toString());
$this->assertEquals(
sprintf(
'is identical to an object of class "%s"',
stdClass::class
),
$constraint->toString()
);
$this->assertCount(1, $constraint);

try {
Expand Down
17 changes: 12 additions & 5 deletions tests/unit/Framework/Constraint/IsInstanceOfTest.php
Expand Up @@ -30,14 +30,18 @@ public function testConstraintFailsOnString(): void
$constraint = new IsInstanceOf(stdClass::class);

try {
$constraint->evaluate('stdClass');
$constraint->evaluate(stdClass::class);
} catch (ExpectationFailedException $e) {
$this->assertSame(
<<<'EOT'
Failed asserting that 'stdClass' is an instance of class "stdClass".
sprintf(
<<<'EOT'
Failed asserting that '%s' is an instance of class "%s".
EOT
,
,
stdClass::class,
stdClass::class
),
TestFailure::exceptionToString($e)
);
}
Expand All @@ -50,7 +54,10 @@ public function testCronstraintsThrowsReflectionException(): void
$constraint = new IsInstanceOf(NotExistingClass::class);

$this->assertSame(
'is instance of class "PHPUnit\Framework\Constraint\NotExistingClass"',
sprintf(
'is instance of class "%s"',
NotExistingClass::class
),
$constraint->toString()
);
}
Expand Down
16 changes: 11 additions & 5 deletions tests/unit/Framework/Constraint/IsTypeTest.php
Expand Up @@ -36,11 +36,14 @@ public function testConstraintIsType(): void
$constraint->evaluate(new stdClass);
} catch (ExpectationFailedException $e) {
$this->assertStringMatchesFormat(
<<<'EOF'
Failed asserting that stdClass Object #%d () is of type "string".
sprintf(
<<<'EOF'
Failed asserting that %s Object #%%d () is of type "string".
EOF
,
,
stdClass::class
),
$this->trimnl(TestFailure::exceptionToString($e))
);

Expand All @@ -58,12 +61,15 @@ public function testConstraintIsType2(): void
$constraint->evaluate(new stdClass, 'custom message');
} catch (ExpectationFailedException $e) {
$this->assertStringMatchesFormat(
<<<'EOF'
sprintf(
<<<'EOF'
custom message
Failed asserting that stdClass Object #%d () is of type "string".
Failed asserting that %s Object #%%d () is of type "string".
EOF
,
stdClass::class
),
$this->trimnl(TestFailure::exceptionToString($e))
);

Expand Down
18 changes: 12 additions & 6 deletions tests/unit/Framework/Constraint/ObjectHasAttributeTest.php
Expand Up @@ -31,11 +31,14 @@ public function testConstraintObjectHasAttribute(): void
$constraint->evaluate(new stdClass);
} catch (ExpectationFailedException $e) {
$this->assertEquals(
<<<'EOF'
Failed asserting that object of class "stdClass" has attribute "privateAttribute".
sprintf(
<<<'EOF'
Failed asserting that object of class "%s" has attribute "privateAttribute".
EOF
,
,
stdClass::class
),
TestFailure::exceptionToString($e)
);

Expand All @@ -53,12 +56,15 @@ public function testConstraintObjectHasAttribute2(): void
$constraint->evaluate(new stdClass, 'custom message');
} catch (ExpectationFailedException $e) {
$this->assertEquals(
<<<'EOF'
sprintf(
<<<'EOF'
custom message
Failed asserting that object of class "stdClass" has attribute "privateAttribute".
Failed asserting that object of class "%s" has attribute "privateAttribute".
EOF
,
,
stdClass::class
),
TestFailure::exceptionToString($e)
);

Expand Down

0 comments on commit 0461f96

Please sign in to comment.