rspec/rules/S5785/php/rule.adoc
Rudy Regazzoni 53ed3f06b4
Modify rule S5785: add examples with boolean literals (#2926)
## Review

A dedicated reviewer checked the rule description successfully for:

- [ ] logical errors and incorrect information
- [ ] information gaps and missing content
- [ ] text style and tone
- [ ] PR summary and labels follow [the
guidelines](https://github.com/SonarSource/rspec/#to-modify-an-existing-rule)
2023-08-25 13:55:18 +02:00

47 lines
921 B
Plaintext

== Why is this an issue?
Testing equality or nullness with PHPUnit's ``++assertTrue()++`` or ``++assertFalse()++`` should be simplified to the corresponding dedicated assertion.
=== Noncompliant code example
[source,php]
----
assertTrue($a === $b);
assertTrue($a == $b);
assertTrue($a === null);
assertTrue($a !== null);
assertTrue($a !== $b);
assertTrue($a != $b);
assertFalse($a === $b);
assertFalse($a == $b);
assertTrue($a == true);
assertTrue($a == false);
----
=== Compliant solution
[source,php]
----
assertEquals($a, $b);
assertSame($a, $b);
assertNull($a);
assertNotNull($a);
assertNotEquals($a, $b);
assertNotSame($a, $b);
assertNotEquals($a, $b);
assertNotSame($a, $b);
assertTrue($a);
assertFalse($a);
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
include::../highlighting.adoc[]
endif::env-github,rspecator-view[]